honkit
Version:
HonKit is building beautiful books using Markdown.
31 lines (29 loc) • 1.18 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const location_1 = __importDefault(require("../../utils/location"));
const editHTMLElement_1 = __importDefault(require("./editHTMLElement"));
/**
Resolve all HTML images:
- /test.png in hello -> ../test.html
@param {string} currentFile
@param {HTMLDom} $
*/
function resolveImages(currentFile, $) {
const currentDirectory = path_1.default.dirname(currentFile);
return (0, editHTMLElement_1.default)($, "img", ($img) => {
let src = $img.attr("src");
if (src === null || src === undefined || location_1.default.isExternal(src) || location_1.default.isDataURI(src)) {
return;
}
// Calcul absolute path for this
src = location_1.default.toAbsolute(src, currentDirectory, ".");
// Convert back to relative
src = location_1.default.relative(currentDirectory, src);
$img.attr("src", src);
});
}
exports.default = resolveImages;