UNPKG

yarle-evernote-to-md

Version:

Yet Another Rope Ladder from Evernote

44 lines 2.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.spanRule = void 0; const yarle_1 = require("../../yarle"); const filter_by_nodename_1 = require("./filter-by-nodename"); const get_attribute_proxy_1 = require("./get-attribute-proxy"); const LanguageFactory_1 = require("./../../outputLanguages/LanguageFactory"); const EVERNOTE_HIGHLIGHT = '-evernote-highlight:true;'; const EVERNOTE_COLORHIGHLIGHT = '--en-highlight'; const BOLD = 'bold'; const ITALIC = 'italic'; exports.spanRule = { filter: (0, filter_by_nodename_1.filterByNodeName)('SPAN'), replacement: (content, node) => { //const HIGHLIGHT_SEPARATOR = yarleOptions.outputFormat === OutputFormat.ObsidianMD ? '==' : '`' ; const nodeProxy = (0, get_attribute_proxy_1.getAttributeProxy)(node); if (nodeProxy.style && content.trim() !== '') { const nodeValue = nodeProxy.style.value; const languageItems = (0, LanguageFactory_1.getLanguageItems)(yarle_1.yarleOptions.outputFormat); // this aims to care for bold text generated as <span style="font-weight: bold;">Bold</span> if (content !== '<YARLE_NEWLINE_PLACEHOLDER>') { const hasBold = nodeValue.includes(BOLD); const hasItalic = nodeValue.includes(ITALIC); if (hasBold && !hasItalic) { return `${languageItems.bold}${content}${languageItems.bold}`; } if (!hasBold && hasItalic) { return `${languageItems.italic}${content}${languageItems.italic}`; } if (hasBold && hasItalic) { return `${languageItems.italic}${languageItems.bold}${content}${languageItems.bold}${languageItems.italic}`; } } const match = nodeValue.match(/color:rgb\(\d{0,3}, \d{0,3}, \d{0,3}\);|background-color: #([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})|--en-fontfamily:[^"]*/); return nodeValue.includes(EVERNOTE_HIGHLIGHT) || nodeValue.includes(EVERNOTE_COLORHIGHLIGHT) || (yarle_1.yarleOptions.convertColorsToMDHighlight && match) ? `${languageItems.highlight}${content}${languageItems.highlight}` : content; } return content; }, }; //# sourceMappingURL=span-rule.js.map