mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-12 08:54:00 +02:00
a96734f5be
This reverts commit 0b6f5581f0
.
It causes too many conflicts with pull requests.
26 lines
812 B
JavaScript
26 lines
812 B
JavaScript
const TurndownService = require('joplin-turndown');
|
|
const markdownUtils = require('lib/markdownUtils');
|
|
|
|
class HtmlToMd {
|
|
parse(html, options = {}) {
|
|
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',
|
|
preserveImageTagsWithSize: !!options.preserveImageTagsWithSize,
|
|
bulletListMarker: '-',
|
|
emDelimiter: '*',
|
|
strongDelimiter: '**',
|
|
});
|
|
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;
|