1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-18 09:35:20 +02:00
joplin/ReactNativeClient/lib/HtmlToMd.js

22 lines
672 B
JavaScript
Raw Normal View History

2019-07-29 15:43:53 +02:00
const TurndownService = require('joplin-turndown');
const markdownUtils = require('lib/markdownUtils');
2018-05-16 15:16:14 +02:00
class HtmlToMd {
parse(html, options = {}) {
2019-07-29 15:43:53 +02:00
const turndownPluginGfm = require('joplin-turndown-plugin-gfm').gfm;
const turndown = new TurndownService({
headingStyle: 'atx',
anchorNames: options.anchorNames ? options.anchorNames.map(n => n.trim().toLowerCase()) : [],
codeBlockStyle: 'fenced',
2019-07-29 15:43:53 +02:00
});
turndown.use(turndownPluginGfm);
turndown.remove('script');
turndown.remove('style');
2019-07-29 15:43:53 +02:00
let md = turndown.turndown(html);
if (options.baseUrl) md = markdownUtils.prependBaseUrl(md, options.baseUrl);
return md;
2018-05-16 15:16:14 +02:00
}
}
2019-07-29 15:43:53 +02:00
module.exports = HtmlToMd;