UNPKG

yarle-evernote-to-md

Version:

Yet Another Rope Ladder from Evernote

83 lines (82 loc) 3.96 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTurndownService = void 0; const turndown_1 = __importDefault(require("turndown")); const joplin_turndown_plugin_gfm_1 = require("joplin-turndown-plugin-gfm"); const turndown_rules_1 = require("./turndown-rules"); const output_format_1 = require("./../output-format"); const task_list_rule_1 = require("./turndown-rules/task-list-rule"); const remove_newlines_1 = require("./remove-newlines"); const constants_1 = require("./../constants"); const underline_rule_1 = require("./turndown-rules/underline-rule"); const encrypt_rule_1 = require("./turndown-rules/encrypt-rule"); const getTurndownService = (yarleOptions) => { /* istanbul ignore next */ const turndownService = new turndown_1.default(Object.assign(Object.assign({ br: '' }, yarleOptions.turndownOptions), { blankReplacement: (content, node) => { return node.isBlock ? '\n\n' : ''; }, keepReplacement: (content, node) => { return node.isBlock ? `\n${node.outerHTML}\n` : node.outerHTML; }, defaultReplacement: (content, node) => { return node.isBlock ? `\n${content}\n` : content; } })); turndownService.use(joplin_turndown_plugin_gfm_1.gfm); turndownService.addRule('span', turndown_rules_1.spanRule); turndownService.addRule('strikethrough', turndown_rules_1.strikethroughRule); turndownService.addRule('evernote task items', turndown_rules_1.taskItemsRule); turndownService.addRule('wikistyle links', turndown_rules_1.wikiStyleLinksRule); turndownService.addRule('images', turndown_rules_1.imagesRule); turndownService.addRule('list', task_list_rule_1.taskListRule); turndownService.addRule('italic', turndown_rules_1.italicRule); turndownService.addRule('underline', underline_rule_1.underlineRule); turndownService.addRule('encrypt', encrypt_rule_1.encryptRule); if (yarleOptions.outputFormat === output_format_1.OutputFormat.LogSeqMD) { turndownService.addRule('logseq_hr', { filter: ['hr'], // tslint:disable-next-line:typedef replacement(content) { return '\r ---'; // this \r is important, used to diff from \n }, }); } if (yarleOptions.outputFormat === output_format_1.OutputFormat.Tana) { turndownService.addRule('tanaSkipTableRule', { filter: ['table'], replacement(content) { return `${constants_1.tanaTableBlock}${(0, remove_newlines_1.removeNewlines)(content)}`; }, }); turndownService.addRule('tanaSkipTableRowRule', { filter: ['tr'], replacement(content) { return `${constants_1.tanaTableRowBlock}${(0, remove_newlines_1.removeNewlines)(content)}`; }, }); turndownService.addRule('tanaSkipTableColRule', { filter: ['td'], replacement(content) { return `${constants_1.tanaTableColBlock}${(0, remove_newlines_1.removeNewlines)(content)}`; }, }); } if (yarleOptions.keepMDCharactersOfENNotes) { turndownService.escape = ((str) => str); } turndownService.addRule('divBlock', turndown_rules_1.divRule); /* turndownService.addRule('v10Tasks', v10TaskBlockRule); if (yarleOptions.monospaceIsCodeBlock) { turndownService.addRule('codeblocks', monospaceCodeBlockRule); } else { turndownService.addRule('codeblocks', codeBlockRule); } */ if (yarleOptions.keepOriginalAmountOfNewlines) { turndownService.addRule('newline', turndown_rules_1.newLineRule); } return turndownService; }; exports.getTurndownService = getTurndownService; //# sourceMappingURL=turndown-service.js.map