smartmarkdown/ts/index.ts
2022-05-19 09:36:59 +02:00

28 lines
742 B
TypeScript

import * as plugins from './smartmarkdown.plugins.js';
export class SmartMarkdown {
constructor() {}
/**
* converts markdown to html
* @param mdString
*/
public async markdownToHtml(mdString: string): Promise<string> {
const result = await plugins
.remark.remark()
.use(plugins.remarkHtml.default)
.use(plugins.remarkFrontmatter.default, ['yaml', 'toml'])
.process(mdString);
return result.toString();
}
public htmlToMarkdown(htmlString: string): string {
const turndownInstance = new plugins.turndown({
headingStyle: 'atx',
codeBlockStyle: 'fenced',
});
turndownInstance.use(plugins.turndownPluginGfm.gfm);
return turndownInstance.turndown(htmlString);
}
}