UNPKG

markdawn

Version:

(multi)markdown for paged documents. Outputs to pdf

37 lines 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var cheerio = require("cheerio"); var path = require("path"); /** * Interpolate object values into the input using double curly braces interpolation */ function interpolate(input, object) { for (var key in object) { if (object.hasOwnProperty(key)) { var exp = new RegExp("{{" + key + "}}", 'g'); input = input.replace(exp, object[key]); } } return input; } exports.interpolate = interpolate; /** * rebase all the html attributes to a specified base path */ function rebaseAttribute(html, basePath, attr) { var $ = cheerio.load(html); $("*[" + attr + "]") .filter(function (key, val) { var firstChar = val.attribs[attr][0]; return firstChar === '.' || firstChar === '.'; }) .attr(attr, function (_, val) { // rebase the attribute var absPath = path.resolve(basePath, val); // make sure it's a valid URI. return "file://" + absPath; }); return $.html(); } exports.rebaseAttribute = rebaseAttribute; //# sourceMappingURL=utils.js.map