mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-03 08:35:29 +02:00
27 lines
829 B
JavaScript
27 lines
829 B
JavaScript
const TurndownService = require('@joplin/turndown');
|
|
const turndownPluginGfm = require('@joplin/turndown-plugin-gfm').gfm;
|
|
const markdownUtils = require('./markdownUtils').default;
|
|
|
|
class HtmlToMd {
|
|
parse(html, options = {}) {
|
|
const turndown = new TurndownService({
|
|
headingStyle: 'atx',
|
|
anchorNames: options.anchorNames ? options.anchorNames.map(n => n.trim().toLowerCase()) : [],
|
|
codeBlockStyle: 'fenced',
|
|
preserveImageTagsWithSize: !!options.preserveImageTagsWithSize,
|
|
bulletListMarker: '-',
|
|
emDelimiter: '*',
|
|
strongDelimiter: '**',
|
|
br: '',
|
|
});
|
|
turndown.use(turndownPluginGfm);
|
|
turndown.remove('script');
|
|
turndown.remove('style');
|
|
let md = turndown.turndown(html);
|
|
if (options.baseUrl) md = markdownUtils.prependBaseUrl(md, options.baseUrl);
|
|
return md;
|
|
}
|
|
}
|
|
|
|
module.exports = HtmlToMd;
|