feat(package): modernize package metadata, typings, and test setup for ESM builds

This commit is contained in:
2026-05-01 21:57:01 +00:00
parent 2eae324908
commit 84b4f355f8
14 changed files with 7620 additions and 18980 deletions
+21 -10
View File
@@ -1,5 +1,16 @@
import * as plugins from './smartmarkdown.plugins.js';
export type TFrontmatterData = Record<string, unknown>;
type TYamlNode = plugins.RootContent & {
type: 'yaml';
value: string;
};
const isYamlNode = (nodeArg: plugins.RootContent): nodeArg is TYamlNode => {
return nodeArg.type === 'yaml' && 'value' in nodeArg && typeof nodeArg.value === 'string';
};
export class MdParsedResult {
public static async createFromMarkdownString(mdStringArg: string): Promise<MdParsedResult> {
const mdParsedResult = new MdParsedResult();
@@ -7,24 +18,24 @@ export class MdParsedResult {
return mdParsedResult;
}
public originalString: string;
public title: string;
public html: string;
public frontmatterData: {[key: string]: any};
public originalString = '';
public title = '';
public html = '';
public frontmatterData: TFrontmatterData = {};
public async updateFromMarkdownString(mdStringArg: string) {
let yamlString: string;
public async updateFromMarkdownString(mdStringArg: string): Promise<void> {
this.originalString = mdStringArg;
let yamlString: string | undefined;
const result = await plugins.unified()
.use(plugins.remarkParse)
.use(plugins.remarkGfm)
.use(plugins.remarkFrontmatter, ['yaml', 'toml'])
.use(plugins.remarkStringify)
.use(plugins.remarkHtml)
.use(() => (tree) => {
console.dir(tree);
const yamlChild = tree.children.find(objectArg => objectArg.type === 'yaml');
.use((): plugins.Transformer<plugins.Root> => (tree) => {
const yamlChild = tree.children.find(isYamlNode);
if (yamlChild) {
yamlString = (yamlChild as any).value;
yamlString = yamlChild.value;
}
})
.process(mdStringArg);