smartmarkdown/ts/index.ts
2021-10-04 13:35:20 +02:00

24 lines
639 B
TypeScript

import * as plugins from './smartmarkdown.plugins';
export class SmartMarkdown {
constructor() {}
/**
* converts markdown to html
* @param mdString
*/
public async markdownToHtml(mdString: string): Promise<string> {
const result = await plugins.remark().use(plugins.remarkHtml).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);
}
}