2018-05-22 01:54:23 +02:00
|
|
|
const TurndownService = require('joplin-turndown')
|
2018-05-23 13:14:38 +02:00
|
|
|
const markdownUtils = require('lib/markdownUtils');
|
2018-05-16 15:16:14 +02:00
|
|
|
|
|
|
|
class HtmlToMd {
|
|
|
|
|
2018-05-23 13:14:38 +02:00
|
|
|
parse(html, options = {}) {
|
2018-05-22 01:54:23 +02:00
|
|
|
const turndownPluginGfm = require('joplin-turndown-plugin-gfm').gfm
|
|
|
|
const turndown = new TurndownService({
|
|
|
|
headingStyle: 'atx',
|
|
|
|
})
|
2018-05-20 11:19:59 +02:00
|
|
|
turndown.use(turndownPluginGfm)
|
|
|
|
turndown.remove('script');
|
2018-05-24 14:32:43 +02:00
|
|
|
turndown.remove('style');
|
2018-05-23 13:14:38 +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
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = HtmlToMd;
|