UNPKG

yarle-evernote-to-md

Version:

Yet Another Rope Ladder from Evernote

49 lines 2.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.imagesRule = 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 is_hepta_or_obsidian_output_1 = require("./../is-hepta-or-obsidian-output"); exports.imagesRule = { filter: (0, filter_by_nodename_1.filterByNodeName)('IMG'), replacement: (content, node) => { const nodeProxy = (0, get_attribute_proxy_1.getAttributeProxy)(node); if (!nodeProxy.src) { return ''; } const value = nodeProxy.src.value; const widthParam = node.width || ''; const heightParam = node.height || ''; let realValue = value; if (yarle_1.yarleOptions.sanitizeResourceNameSpaces) { realValue = realValue.replace(/ /g, yarle_1.yarleOptions.replacementChar); } else if (yarle_1.yarleOptions.urlEncodeFileNamesAndLinks) { realValue = encodeURI(realValue); } if (yarle_1.yarleOptions.keepImageSize) { let sizeString = (widthParam || heightParam) ? ` =${widthParam}x${heightParam}` : ''; // while this isn't really a standard, it is common enough if (yarle_1.yarleOptions.imageSizeFormat === "StandardMD" /* ImageSizeFormat.StandardMD */) { return `![](${realValue}${sizeString})`; } else if (yarle_1.yarleOptions.imageSizeFormat === "ObsidianMD" /* ImageSizeFormat.ObsidianMD */) { sizeString = (widthParam || heightParam) ? `${widthParam || 0}x${heightParam || 0}` : ''; if (realValue.startsWith('./') || realValue.startsWith('..')) { return sizeString != '' ? `![[${realValue}\\|${sizeString}]]` : `![[${realValue}${sizeString}]]`; } else { return `![${sizeString}](${realValue})`; } } } const useObsidianMD = (0, is_hepta_or_obsidian_output_1.isHeptaOrObsidianOutput)(); if (useObsidianMD && !value.match(/^[a-z]+:/)) { return `![[${realValue}]]`; } const srcSpl = nodeProxy.src.value.split('/'); return `![${srcSpl[srcSpl.length - 1]}](${realValue})`; }, }; //# sourceMappingURL=images-rule.js.map