2022-05-19 09:36:59 +02:00
|
|
|
import * as plugins from './smartmarkdown.plugins.js';
|
2022-05-20 16:03:35 +02:00
|
|
|
import { MdParsedResult } from './smartmarkdown.classes.mdparsedresult.js';
|
2018-09-22 21:58:33 +02:00
|
|
|
|
2019-06-17 11:56:39 +02:00
|
|
|
export class SmartMarkdown {
|
2022-06-26 20:45:40 +02:00
|
|
|
public static async easyMarkdownToHtml(mdStringArg: string) {
|
|
|
|
const smartmarkdownInstance = new SmartMarkdown();
|
|
|
|
const mdParsedResult = await smartmarkdownInstance.getMdParsedResultFromMarkdown(mdStringArg);
|
|
|
|
return mdParsedResult.html;
|
|
|
|
}
|
|
|
|
|
2019-06-17 11:56:39 +02:00
|
|
|
constructor() {}
|
|
|
|
|
|
|
|
/**
|
2022-05-20 16:03:35 +02:00
|
|
|
* create a MdParsedResult from markdown
|
|
|
|
* @param mdStringArg
|
2019-06-17 11:56:39 +02:00
|
|
|
*/
|
2022-05-20 16:03:35 +02:00
|
|
|
public async getMdParsedResultFromMarkdown(mdStringArg: string): Promise<MdParsedResult> {
|
|
|
|
const result = await MdParsedResult.createFromMarkdownString(mdStringArg);
|
|
|
|
return result;
|
2022-06-26 20:45:40 +02:00
|
|
|
}
|
2019-06-17 11:56:39 +02:00
|
|
|
|
2021-10-04 13:35:20 +02:00
|
|
|
public htmlToMarkdown(htmlString: string): string {
|
2019-06-17 11:56:39 +02:00
|
|
|
const turndownInstance = new plugins.turndown({
|
|
|
|
headingStyle: 'atx',
|
2021-04-12 09:20:28 +00:00
|
|
|
codeBlockStyle: 'fenced',
|
2019-06-17 11:56:39 +02:00
|
|
|
});
|
2019-06-17 14:41:57 +02:00
|
|
|
turndownInstance.use(plugins.turndownPluginGfm.gfm);
|
2019-06-17 11:56:39 +02:00
|
|
|
return turndownInstance.turndown(htmlString);
|
|
|
|
}
|
|
|
|
}
|