feat(package): modernize package metadata, typings, and test setup for ESM builds
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user