2018-05-21 23:54:23 +00:00
|
|
|
const TurndownService = require('joplin-turndown')
|
2018-05-23 11:14:38 +00:00
|
|
|
const markdownUtils = require('lib/markdownUtils');
|
2018-05-16 13:16:14 +00:00
|
|
|
|
|
|
|
class HtmlToMd {
|
|
|
|
|
2018-05-23 11:14:38 +00:00
|
|
|
parse(html, options = {}) {
|
2018-05-21 23:54:23 +00:00
|
|
|
const turndownPluginGfm = require('joplin-turndown-plugin-gfm').gfm
|
|
|
|
const turndown = new TurndownService({
|
|
|
|
headingStyle: 'atx',
|
|
|
|
})
|
2018-05-20 09:19:59 +00:00
|
|
|
turndown.use(turndownPluginGfm)
|
|
|
|
turndown.remove('script');
|
2018-05-23 11:14:38 +00:00
|
|
|
let md = turndown.turndown(html)
|
|
|
|
if (options.baseUrl) md = markdownUtils.prependBaseUrl(md, options.baseUrl);
|
|
|
|
return md;
|
2018-05-16 13:16:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = HtmlToMd;
|