UNPKG

mume-with-litvis

Version:

Fork of mume with added http://litvis.org/

62 lines 2.64 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); /** * This function resolves image paths * @param $ cheerio object that we will analyze * @return cheerio object */ function enhance($, options, resolveFilePath, usePandocParser) { return __awaiter(this, void 0, void 0, function* () { // resolve image paths $("img, a").each((i, imgElement) => { let srcTag = "src"; if (imgElement.name === "a") { srcTag = "href"; } const img = $(imgElement); const src = img.attr(srcTag); // insert anchor for scroll sync. if (options.isForPreview && imgElement.name !== "a" && img .parent() .prev() .hasClass("sync-line")) { const lineNo = parseInt(img .parent() .prev() .attr("data-line"), 10); if (lineNo) { img .parent() .after(`<p data-line="${lineNo + 1}" class="sync-line" style="margin:0;"></p>`); } } img.attr(srcTag, resolveFilePath(src, options.useRelativeFilePath, options.fileDirectoryPath)); }); if (!usePandocParser) { // check .mume-header in order to add id and class to headers. $(".mume-header").each((i, e) => { const classes = e.attribs.class; const id = e.attribs.id; const $e = $(e); const $h = $e.prev(); $h.addClass(classes); $h.attr("id", encodeURIComponent(id)); // encodeURIComponent to fix utf-8 header. $e.remove(); }); } }); } exports.default = enhance; //# sourceMappingURL=resolved-image-paths.js.map