2018-09-22 19:58:33 +00:00
|
|
|
import * as plugins from './smartmarkdown.plugins';
|
|
|
|
|
2019-06-17 09:56:39 +00:00
|
|
|
export class SmartMarkdown {
|
|
|
|
constructor() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* converts markdown to html
|
|
|
|
* @param mdString
|
|
|
|
*/
|
|
|
|
public markdownToHtml(mdString: string): string {
|
|
|
|
return plugins.marked(mdString);
|
|
|
|
}
|
|
|
|
|
|
|
|
public htmlToMarkdown(htmlString): string {
|
|
|
|
const turndownInstance = new plugins.turndown({
|
|
|
|
headingStyle: 'atx',
|
2021-04-12 09:20:28 +00:00
|
|
|
codeBlockStyle: 'fenced',
|
2019-06-17 09:56:39 +00:00
|
|
|
});
|
2019-06-17 12:41:57 +00:00
|
|
|
turndownInstance.use(plugins.turndownPluginGfm.gfm);
|
2019-06-17 09:56:39 +00:00
|
|
|
return turndownInstance.turndown(htmlString);
|
|
|
|
}
|
|
|
|
}
|