28 lines
716 B
TypeScript
28 lines
716 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)
|
|
.use(plugins.remarkFrontmatter, ['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);
|
|
}
|
|
}
|