fix
This commit is contained in:
8
book/node_modules/honkit/lib/output/modifiers/addHeadingId.d.ts
generated
vendored
Normal file
8
book/node_modules/honkit/lib/output/modifiers/addHeadingId.d.ts
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
Add ID to all headings
|
||||
|
||||
@param {HTMLDom} $
|
||||
*/
|
||||
declare function addHeadingId($: any): any;
|
||||
export default addHeadingId;
|
||||
//# sourceMappingURL=addHeadingId.d.ts.map
|
1
book/node_modules/honkit/lib/output/modifiers/addHeadingId.d.ts.map
generated
vendored
Normal file
1
book/node_modules/honkit/lib/output/modifiers/addHeadingId.d.ts.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"addHeadingId.d.ts","sourceRoot":"","sources":["../../../src/output/modifiers/addHeadingId.ts"],"names":[],"mappings":"AAaA;;;;GAIG;AACH,iBAAS,YAAY,CAAC,CAAC,KAAA,OAEtB;AAED,eAAe,YAAY,CAAC"}
|
26
book/node_modules/honkit/lib/output/modifiers/addHeadingId.js
generated
vendored
Normal file
26
book/node_modules/honkit/lib/output/modifiers/addHeadingId.js
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const github_slugid_1 = __importDefault(require("github-slugid"));
|
||||
const editHTMLElement_1 = __importDefault(require("./editHTMLElement"));
|
||||
/**
|
||||
Add ID to an heading
|
||||
|
||||
@param {HTMLElement} heading
|
||||
*/
|
||||
function addId(heading) {
|
||||
if (heading.attr("id"))
|
||||
return;
|
||||
heading.attr("id", (0, github_slugid_1.default)(heading.text()));
|
||||
}
|
||||
/**
|
||||
Add ID to all headings
|
||||
|
||||
@param {HTMLDom} $
|
||||
*/
|
||||
function addHeadingId($) {
|
||||
return (0, editHTMLElement_1.default)($, "h1,h2,h3,h4,h5,h6", addId);
|
||||
}
|
||||
exports.default = addHeadingId;
|
10
book/node_modules/honkit/lib/output/modifiers/annotateText.d.ts
generated
vendored
Normal file
10
book/node_modules/honkit/lib/output/modifiers/annotateText.d.ts
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Annotate text using a list of GlossaryEntry
|
||||
*
|
||||
* @param {List<GlossaryEntry>}
|
||||
* @param {string} glossaryFilePath
|
||||
* @param {HTMLDom} $
|
||||
*/
|
||||
declare function annotateText(entries: any, glossaryFilePath: any, $: any): void;
|
||||
export default annotateText;
|
||||
//# sourceMappingURL=annotateText.d.ts.map
|
1
book/node_modules/honkit/lib/output/modifiers/annotateText.d.ts.map
generated
vendored
Normal file
1
book/node_modules/honkit/lib/output/modifiers/annotateText.d.ts.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"annotateText.d.ts","sourceRoot":"","sources":["../../../src/output/modifiers/annotateText.ts"],"names":[],"mappings":"AAyDA;;;;;;GAMG;AACH,iBAAS,YAAY,CAAC,OAAO,KAAA,EAAE,gBAAgB,KAAA,EAAE,CAAC,KAAA,QA4BjD;AAED,eAAe,YAAY,CAAC"}
|
87
book/node_modules/honkit/lib/output/modifiers/annotateText.js
generated
vendored
Normal file
87
book/node_modules/honkit/lib/output/modifiers/annotateText.js
generated
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const escape_html_1 = __importDefault(require("escape-html"));
|
||||
// Selector to ignore
|
||||
const ANNOTATION_IGNORE = ".no-glossary,code,pre,a,script,h1,h2,h3,h4,h5,h6";
|
||||
function pregQuote(str) {
|
||||
return `${str}`.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, "\\$1");
|
||||
}
|
||||
function replaceText($, el, search, replace, text_only) {
|
||||
return $(el).each(function () {
|
||||
let node = this.firstChild;
|
||||
let val;
|
||||
let new_val;
|
||||
// Only continue if firstChild exists.
|
||||
const replaceMap = new Map();
|
||||
if (node) {
|
||||
// Loop over all childNodes.
|
||||
while (node) {
|
||||
// Only process text nodes.
|
||||
if (node.nodeType === 3 && node.nodeValue) {
|
||||
// The original node value.
|
||||
val = node.nodeValue;
|
||||
new_val = val.replace(search, replace);
|
||||
// Only replace text if the new value is actually different!
|
||||
if (new_val !== val) {
|
||||
if (!text_only && /</.test(new_val)) {
|
||||
// The new value contains HTML, set it in a slower but far more
|
||||
// robust way.
|
||||
// Don't remove the node yet, or the loop will lose its place.
|
||||
const currentTextNode = $(node);
|
||||
const newHTML = val.replace(val, new_val);
|
||||
if (newHTML !== val) {
|
||||
// should not replace in looping, keep it in map
|
||||
replaceMap.set(currentTextNode, newHTML);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// The new value contains no HTML, so it can be set in this
|
||||
// very fast, simple way.
|
||||
node.nodeValue = new_val;
|
||||
}
|
||||
}
|
||||
}
|
||||
node = node.nextSibling;
|
||||
}
|
||||
}
|
||||
// replace nodes after looping
|
||||
for (const [node, newHTML] of replaceMap.entries()) {
|
||||
node.replaceWith(newHTML);
|
||||
}
|
||||
replaceMap.clear(); // clean up
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Annotate text using a list of GlossaryEntry
|
||||
*
|
||||
* @param {List<GlossaryEntry>}
|
||||
* @param {string} glossaryFilePath
|
||||
* @param {HTMLDom} $
|
||||
*/
|
||||
function annotateText(entries, glossaryFilePath, $) {
|
||||
entries.forEach((entry) => {
|
||||
const entryId = entry.getID();
|
||||
const name = entry.getName();
|
||||
const nameLowerCase = `${name}`.toLowerCase();
|
||||
const quotedName = pregQuote(nameLowerCase);
|
||||
const nameCleaned = nameLowerCase.replace(/[^\w\s]/, "");
|
||||
const searchRegex = nameLowerCase === nameCleaned
|
||||
? new RegExp(`\\b(${quotedName})\\b`, "gi")
|
||||
: new RegExp(`(?:\\s*)(${quotedName})(?:\\s*)`, "gi");
|
||||
const description = entry.getDescription();
|
||||
$("*").each(function () {
|
||||
const $this = $(this);
|
||||
if ($this.is(ANNOTATION_IGNORE) || $this.parents(ANNOTATION_IGNORE).length > 0)
|
||||
return;
|
||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 5 arguments, but got 4.
|
||||
replaceText($, this, searchRegex, (match, matchedTerm) => {
|
||||
return (`<a href="/${glossaryFilePath}#${entryId}" ` +
|
||||
`class="glossary-term" title="${(0, escape_html_1.default)(description)}">${matchedTerm}</a>`);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.default = annotateText;
|
6
book/node_modules/honkit/lib/output/modifiers/editHTMLElement.d.ts
generated
vendored
Normal file
6
book/node_modules/honkit/lib/output/modifiers/editHTMLElement.d.ts
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
/**
|
||||
Edit all elements matching a selector
|
||||
*/
|
||||
declare function editHTMLElement($: any, selector: any, fn: any): any;
|
||||
export default editHTMLElement;
|
||||
//# sourceMappingURL=editHTMLElement.d.ts.map
|
1
book/node_modules/honkit/lib/output/modifiers/editHTMLElement.d.ts.map
generated
vendored
Normal file
1
book/node_modules/honkit/lib/output/modifiers/editHTMLElement.d.ts.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"editHTMLElement.d.ts","sourceRoot":"","sources":["../../../src/output/modifiers/editHTMLElement.ts"],"names":[],"mappings":"AAEA;;GAEG;AAEH,iBAAS,eAAe,CAAC,CAAC,KAAA,EAAE,QAAQ,KAAA,EAAE,EAAE,KAAA,OAOvC;AAED,eAAe,eAAe,CAAC"}
|
17
book/node_modules/honkit/lib/output/modifiers/editHTMLElement.js
generated
vendored
Normal file
17
book/node_modules/honkit/lib/output/modifiers/editHTMLElement.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const promise_1 = __importDefault(require("../../utils/promise"));
|
||||
/**
|
||||
Edit all elements matching a selector
|
||||
*/
|
||||
function editHTMLElement($, selector, fn) {
|
||||
const $elements = $(selector);
|
||||
return promise_1.default.forEach($elements, (el) => {
|
||||
const $el = $(el);
|
||||
return fn($el);
|
||||
});
|
||||
}
|
||||
exports.default = editHTMLElement;
|
7
book/node_modules/honkit/lib/output/modifiers/fetchRemoteImages.d.ts
generated
vendored
Normal file
7
book/node_modules/honkit/lib/output/modifiers/fetchRemoteImages.d.ts
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
import type cheerio from "cheerio";
|
||||
/**
|
||||
Fetch all remote images
|
||||
*/
|
||||
declare function fetchRemoteImages(rootFolder: string, currentFile: string, $: cheerio.CheerioAPI): Promise<any>;
|
||||
export default fetchRemoteImages;
|
||||
//# sourceMappingURL=fetchRemoteImages.d.ts.map
|
1
book/node_modules/honkit/lib/output/modifiers/fetchRemoteImages.d.ts.map
generated
vendored
Normal file
1
book/node_modules/honkit/lib/output/modifiers/fetchRemoteImages.d.ts.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"fetchRemoteImages.d.ts","sourceRoot":"","sources":["../../../src/output/modifiers/fetchRemoteImages.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC;;GAEG;AAEH,iBAAS,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,CA2BvG;AAED,eAAe,iBAAiB,CAAC"}
|
37
book/node_modules/honkit/lib/output/modifiers/fetchRemoteImages.js
generated
vendored
Normal file
37
book/node_modules/honkit/lib/output/modifiers/fetchRemoteImages.js
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
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 crc_1 = __importDefault(require("crc"));
|
||||
const editHTMLElement_1 = __importDefault(require("./editHTMLElement"));
|
||||
const fs_1 = __importDefault(require("../../utils/fs"));
|
||||
const location_1 = __importDefault(require("../../utils/location"));
|
||||
/**
|
||||
Fetch all remote images
|
||||
*/
|
||||
function fetchRemoteImages(rootFolder, currentFile, $) {
|
||||
const currentDirectory = path_1.default.dirname(currentFile);
|
||||
return (0, editHTMLElement_1.default)($, "img", ($img) => {
|
||||
let src = $img.attr("src");
|
||||
const extension = path_1.default.extname(src);
|
||||
if (!location_1.default.isExternal(src)) {
|
||||
return;
|
||||
}
|
||||
// We avoid generating twice the same PNG
|
||||
const hash = crc_1.default.crc32(src).toString(16);
|
||||
const fileName = hash + extension;
|
||||
const filePath = path_1.default.join(rootFolder, fileName);
|
||||
return fs_1.default
|
||||
.assertFile(filePath, () => {
|
||||
return fs_1.default.download(src, filePath);
|
||||
})
|
||||
.then(() => {
|
||||
// Convert to relative
|
||||
src = location_1.default.relative(currentDirectory, fileName);
|
||||
$img.replaceWith(`<img src="${src}" />`);
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.default = fetchRemoteImages;
|
10
book/node_modules/honkit/lib/output/modifiers/highlightCode.d.ts
generated
vendored
Normal file
10
book/node_modules/honkit/lib/output/modifiers/highlightCode.d.ts
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
Highlight all code elements
|
||||
|
||||
@param {Function(lang, body) -> String} highlight
|
||||
@param {HTMLDom} $
|
||||
@return {Promise}
|
||||
*/
|
||||
declare function highlightCode(highlight: any, $: any): any;
|
||||
export default highlightCode;
|
||||
//# sourceMappingURL=highlightCode.d.ts.map
|
1
book/node_modules/honkit/lib/output/modifiers/highlightCode.d.ts.map
generated
vendored
Normal file
1
book/node_modules/honkit/lib/output/modifiers/highlightCode.d.ts.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"highlightCode.d.ts","sourceRoot":"","sources":["../../../src/output/modifiers/highlightCode.ts"],"names":[],"mappings":"AAqCA;;;;;;GAMG;AACH,iBAAS,aAAa,CAAC,SAAS,KAAA,EAAE,CAAC,KAAA,OAclC;AAED,eAAe,aAAa,CAAC"}
|
59
book/node_modules/honkit/lib/output/modifiers/highlightCode.js
generated
vendored
Normal file
59
book/node_modules/honkit/lib/output/modifiers/highlightCode.js
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const is_1 = __importDefault(require("is"));
|
||||
const immutable_1 = __importDefault(require("immutable"));
|
||||
const promise_1 = __importDefault(require("../../utils/promise"));
|
||||
const editHTMLElement_1 = __importDefault(require("./editHTMLElement"));
|
||||
/**
|
||||
Return language for a code blocks from a list of class names
|
||||
|
||||
@param {Array<String>}
|
||||
@return {string}
|
||||
*/
|
||||
function getLanguageForClass(classNames) {
|
||||
return immutable_1.default.List(classNames)
|
||||
.map((cl) => {
|
||||
// Markdown
|
||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'search' does not exist on type 'unknown'... Remove this comment to see the full error message
|
||||
if (cl.search("lang-") === 0) {
|
||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'slice' does not exist on type 'unknown'.
|
||||
return cl.slice("lang-".length);
|
||||
}
|
||||
// Asciidoc
|
||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'search' does not exist on type 'unknown'... Remove this comment to see the full error message
|
||||
if (cl.search("language-") === 0) {
|
||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'slice' does not exist on type 'unknown'.
|
||||
return cl.slice("language-".length);
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.find((cl) => {
|
||||
return Boolean(cl);
|
||||
});
|
||||
}
|
||||
/**
|
||||
Highlight all code elements
|
||||
|
||||
@param {Function(lang, body) -> String} highlight
|
||||
@param {HTMLDom} $
|
||||
@return {Promise}
|
||||
*/
|
||||
function highlightCode(highlight, $) {
|
||||
return (0, editHTMLElement_1.default)($, "code", ($code) => {
|
||||
const classNames = ($code.attr("class") || "").split(" ");
|
||||
const lang = getLanguageForClass(classNames);
|
||||
const source = $code.text();
|
||||
return (0, promise_1.default)(highlight(lang, source)).then((r) => {
|
||||
if (is_1.default.string(r.html)) {
|
||||
$code.html(r.html);
|
||||
}
|
||||
else {
|
||||
$code.text(r.text);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.default = highlightCode;
|
22
book/node_modules/honkit/lib/output/modifiers/index.d.ts
generated
vendored
Normal file
22
book/node_modules/honkit/lib/output/modifiers/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
import modifyHTML0 from "./modifyHTML";
|
||||
import inlineAssets0 from "./inlineAssets";
|
||||
import addHeadingId0 from "./addHeadingId";
|
||||
import svgToImg0 from "./svgToImg";
|
||||
import fetchRemoteImages0 from "./fetchRemoteImages";
|
||||
import resolveLinks0 from "./resolveLinks";
|
||||
import resolveImages0 from "./resolveImages";
|
||||
import annotateText0 from "./annotateText";
|
||||
import highlightCode0 from "./highlightCode";
|
||||
declare const _default: {
|
||||
modifyHTML: typeof modifyHTML0;
|
||||
inlineAssets: typeof inlineAssets0;
|
||||
addHeadingId: typeof addHeadingId0;
|
||||
svgToImg: typeof svgToImg0;
|
||||
fetchRemoteImages: typeof fetchRemoteImages0;
|
||||
resolveLinks: typeof resolveLinks0;
|
||||
resolveImages: typeof resolveImages0;
|
||||
annotateText: typeof annotateText0;
|
||||
highlightCode: typeof highlightCode0;
|
||||
};
|
||||
export default _default;
|
||||
//# sourceMappingURL=index.d.ts.map
|
1
book/node_modules/honkit/lib/output/modifiers/index.d.ts.map
generated
vendored
Normal file
1
book/node_modules/honkit/lib/output/modifiers/index.d.ts.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/output/modifiers/index.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,aAAa,MAAM,gBAAgB,CAAC;AAC3C,OAAO,aAAa,MAAM,gBAAgB,CAAC;AAC3C,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,kBAAkB,MAAM,qBAAqB,CAAC;AACrD,OAAO,aAAa,MAAM,gBAAgB,CAAC;AAC3C,OAAO,cAAc,MAAM,iBAAiB,CAAC;AAC7C,OAAO,aAAa,MAAM,gBAAgB,CAAC;AAC3C,OAAO,cAAc,MAAM,iBAAiB,CAAC;;;;;;;;;;;;AAC7C,wBAYE"}
|
26
book/node_modules/honkit/lib/output/modifiers/index.js
generated
vendored
Normal file
26
book/node_modules/honkit/lib/output/modifiers/index.js
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const modifyHTML_1 = __importDefault(require("./modifyHTML"));
|
||||
const inlineAssets_1 = __importDefault(require("./inlineAssets"));
|
||||
const addHeadingId_1 = __importDefault(require("./addHeadingId"));
|
||||
const svgToImg_1 = __importDefault(require("./svgToImg"));
|
||||
const fetchRemoteImages_1 = __importDefault(require("./fetchRemoteImages"));
|
||||
const resolveLinks_1 = __importDefault(require("./resolveLinks"));
|
||||
const resolveImages_1 = __importDefault(require("./resolveImages"));
|
||||
const annotateText_1 = __importDefault(require("./annotateText"));
|
||||
const highlightCode_1 = __importDefault(require("./highlightCode"));
|
||||
exports.default = {
|
||||
modifyHTML: modifyHTML_1.default,
|
||||
inlineAssets: inlineAssets_1.default,
|
||||
// HTML transformations
|
||||
addHeadingId: addHeadingId_1.default,
|
||||
svgToImg: svgToImg_1.default,
|
||||
fetchRemoteImages: fetchRemoteImages_1.default,
|
||||
resolveLinks: resolveLinks_1.default,
|
||||
resolveImages: resolveImages_1.default,
|
||||
annotateText: annotateText_1.default,
|
||||
highlightCode: highlightCode_1.default
|
||||
};
|
8
book/node_modules/honkit/lib/output/modifiers/inlineAssets.d.ts
generated
vendored
Normal file
8
book/node_modules/honkit/lib/output/modifiers/inlineAssets.d.ts
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
Inline all assets in a page
|
||||
|
||||
@param {string} rootFolder
|
||||
*/
|
||||
declare function inlineAssets(rootFolder: any, currentFile: any): ($: any) => any;
|
||||
export default inlineAssets;
|
||||
//# sourceMappingURL=inlineAssets.d.ts.map
|
1
book/node_modules/honkit/lib/output/modifiers/inlineAssets.d.ts.map
generated
vendored
Normal file
1
book/node_modules/honkit/lib/output/modifiers/inlineAssets.d.ts.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"inlineAssets.d.ts","sourceRoot":"","sources":["../../../src/output/modifiers/inlineAssets.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,iBAAS,YAAY,CAAC,UAAU,KAAA,EAAE,WAAW,KAAA,mBAc5C;AAED,eAAe,YAAY,CAAC"}
|
29
book/node_modules/honkit/lib/output/modifiers/inlineAssets.js
generated
vendored
Normal file
29
book/node_modules/honkit/lib/output/modifiers/inlineAssets.js
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const resolveImages_1 = __importDefault(require("./resolveImages"));
|
||||
const fetchRemoteImages_1 = __importDefault(require("./fetchRemoteImages"));
|
||||
const svgToImg_1 = __importDefault(require("./svgToImg"));
|
||||
const inlineSvg_1 = __importDefault(require("./inlineSvg"));
|
||||
const inlinePng_1 = __importDefault(require("./inlinePng"));
|
||||
const promise_1 = __importDefault(require("../../utils/promise"));
|
||||
/**
|
||||
Inline all assets in a page
|
||||
|
||||
@param {string} rootFolder
|
||||
*/
|
||||
function inlineAssets(rootFolder, currentFile) {
|
||||
return function ($) {
|
||||
return ((0, promise_1.default)()
|
||||
// Resolving images and fetching external images should be
|
||||
// done before svg conversion
|
||||
.then(resolveImages_1.default.bind(null, currentFile, $))
|
||||
.then(fetchRemoteImages_1.default.bind(null, rootFolder, currentFile, $))
|
||||
.then(svgToImg_1.default.bind(null, rootFolder, currentFile, $))
|
||||
.then(inlineSvg_1.default.bind(null, rootFolder, currentFile, $))
|
||||
.then(inlinePng_1.default.bind(null, rootFolder, currentFile, $)));
|
||||
};
|
||||
}
|
||||
exports.default = inlineAssets;
|
10
book/node_modules/honkit/lib/output/modifiers/inlinePng.d.ts
generated
vendored
Normal file
10
book/node_modules/honkit/lib/output/modifiers/inlinePng.d.ts
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
Convert all inline PNG images to PNG file
|
||||
|
||||
@param {string} rootFolder
|
||||
@param {HTMLDom} $
|
||||
@return {Promise}
|
||||
*/
|
||||
declare function inlinePng(rootFolder: any, currentFile: any, $: any): any;
|
||||
export default inlinePng;
|
||||
//# sourceMappingURL=inlinePng.d.ts.map
|
1
book/node_modules/honkit/lib/output/modifiers/inlinePng.d.ts.map
generated
vendored
Normal file
1
book/node_modules/honkit/lib/output/modifiers/inlinePng.d.ts.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"inlinePng.d.ts","sourceRoot":"","sources":["../../../src/output/modifiers/inlinePng.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AAEH,iBAAS,SAAS,CAAC,UAAU,KAAA,EAAE,WAAW,KAAA,EAAE,CAAC,KAAA,OA4B5C;AAED,eAAe,SAAS,CAAC"}
|
43
book/node_modules/honkit/lib/output/modifiers/inlinePng.js
generated
vendored
Normal file
43
book/node_modules/honkit/lib/output/modifiers/inlinePng.js
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const crc_1 = __importDefault(require("crc"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const images_1 = __importDefault(require("../../utils/images"));
|
||||
const fs_1 = __importDefault(require("../../utils/fs"));
|
||||
const location_1 = __importDefault(require("../../utils/location"));
|
||||
const editHTMLElement_1 = __importDefault(require("./editHTMLElement"));
|
||||
/**
|
||||
Convert all inline PNG images to PNG file
|
||||
|
||||
@param {string} rootFolder
|
||||
@param {HTMLDom} $
|
||||
@return {Promise}
|
||||
*/
|
||||
function inlinePng(rootFolder, currentFile, $) {
|
||||
const currentDirectory = path_1.default.dirname(currentFile);
|
||||
return (0, editHTMLElement_1.default)($, "img", ($img) => {
|
||||
const src = $img.attr("src");
|
||||
if (!location_1.default.isDataURI(src)) {
|
||||
return;
|
||||
}
|
||||
// We avoid generating twice the same PNG
|
||||
const hash = crc_1.default.crc32(src).toString(16);
|
||||
let fileName = `${hash}.png`;
|
||||
// Result file path
|
||||
const filePath = path_1.default.join(rootFolder, fileName);
|
||||
return fs_1.default
|
||||
.assertFile(filePath, () => {
|
||||
return images_1.default.convertInlinePNG(src, filePath);
|
||||
})
|
||||
.then(() => {
|
||||
// Convert filename to a relative filename
|
||||
fileName = location_1.default.relative(currentDirectory, fileName);
|
||||
// Replace src
|
||||
$img.attr("src", fileName);
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.default = inlinePng;
|
10
book/node_modules/honkit/lib/output/modifiers/inlineSvg.d.ts
generated
vendored
Normal file
10
book/node_modules/honkit/lib/output/modifiers/inlineSvg.d.ts
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
Inline SVG images as needed
|
||||
|
||||
@param {string} rootFolder
|
||||
@param {HTMLDom} $
|
||||
@return {Promise}
|
||||
*/
|
||||
declare function inlineSvg(rootFolder: any, currentFile: any, $: any): any;
|
||||
export default inlineSvg;
|
||||
//# sourceMappingURL=inlineSvg.d.ts.map
|
1
book/node_modules/honkit/lib/output/modifiers/inlineSvg.d.ts.map
generated
vendored
Normal file
1
book/node_modules/honkit/lib/output/modifiers/inlineSvg.d.ts.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"inlineSvg.d.ts","sourceRoot":"","sources":["../../../src/output/modifiers/inlineSvg.ts"],"names":[],"mappings":"AAMA;;;;;;GAMG;AAEH,iBAAS,SAAS,CAAC,UAAU,KAAA,EAAE,WAAW,KAAA,EAAE,CAAC,KAAA,OAwB5C;AAED,eAAe,SAAS,CAAC"}
|
63
book/node_modules/honkit/lib/output/modifiers/inlineSvg.js
generated
vendored
Normal file
63
book/node_modules/honkit/lib/output/modifiers/inlineSvg.js
generated
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
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 fs_1 = __importDefault(require("../../utils/fs"));
|
||||
const location_1 = __importDefault(require("../../utils/location"));
|
||||
const editHTMLElement_1 = __importDefault(require("./editHTMLElement"));
|
||||
const cheerio = __importStar(require("cheerio"));
|
||||
/**
|
||||
Inline SVG images as needed
|
||||
|
||||
@param {string} rootFolder
|
||||
@param {HTMLDom} $
|
||||
@return {Promise}
|
||||
*/
|
||||
function inlineSvg(rootFolder, currentFile, $) {
|
||||
const currentDirectory = path_1.default.dirname(currentFile);
|
||||
return (0, editHTMLElement_1.default)($, "img", ($img) => {
|
||||
let src = $img.attr("src");
|
||||
if (path_1.default.extname(src) !== ".svg") {
|
||||
return;
|
||||
}
|
||||
// Calcul absolute path for this
|
||||
src = location_1.default.toAbsolute(src, currentDirectory, ".");
|
||||
const inputPath = path_1.default.join(rootFolder, src);
|
||||
return fs_1.default.readFile(inputPath).then((svgContext) => {
|
||||
// @ts-expect-error
|
||||
const $ = cheerio.load(svgContext, { _useHtmlParser2: true, xmlMode: true });
|
||||
const $svg = $("svg");
|
||||
if ($svg.attr("style")) {
|
||||
return;
|
||||
}
|
||||
$svg.attr("fill", "currentColor");
|
||||
$img.replaceWith($svg);
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.default = inlineSvg;
|
11
book/node_modules/honkit/lib/output/modifiers/modifyHTML.d.ts
generated
vendored
Normal file
11
book/node_modules/honkit/lib/output/modifiers/modifyHTML.d.ts
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
Apply a list of operations to a page and
|
||||
output the new page.
|
||||
|
||||
@param {Page}
|
||||
@param {List|Array<Transformation>}
|
||||
@return {Promise<Page>}
|
||||
*/
|
||||
declare function modifyHTML(page: any, operations: any): any;
|
||||
export default modifyHTML;
|
||||
//# sourceMappingURL=modifyHTML.d.ts.map
|
1
book/node_modules/honkit/lib/output/modifiers/modifyHTML.d.ts.map
generated
vendored
Normal file
1
book/node_modules/honkit/lib/output/modifiers/modifyHTML.d.ts.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"modifyHTML.d.ts","sourceRoot":"","sources":["../../../src/output/modifiers/modifyHTML.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,iBAAS,UAAU,CAAC,IAAI,KAAA,EAAE,UAAU,KAAA,OAcnC;AAED,eAAe,UAAU,CAAC"}
|
51
book/node_modules/honkit/lib/output/modifiers/modifyHTML.js
generated
vendored
Normal file
51
book/node_modules/honkit/lib/output/modifiers/modifyHTML.js
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const cheerio = __importStar(require("cheerio"));
|
||||
const promise_1 = __importDefault(require("../../utils/promise"));
|
||||
/**
|
||||
Apply a list of operations to a page and
|
||||
output the new page.
|
||||
|
||||
@param {Page}
|
||||
@param {List|Array<Transformation>}
|
||||
@return {Promise<Page>}
|
||||
*/
|
||||
function modifyHTML(page, operations) {
|
||||
const html = page.getContent();
|
||||
// @ts-expect-error
|
||||
const $ = cheerio.load(html, { _useHtmlParser2: true });
|
||||
return promise_1.default.forEach(operations, (op) => {
|
||||
return op($);
|
||||
}).then(() => {
|
||||
const resultHTML = $.html();
|
||||
const unescapedHtml = resultHTML.replace(/&#x([0-9a-f]{2,});/gi, (_, code) => String.fromCodePoint(parseInt(code, 16)));
|
||||
return page.set("content", unescapedHtml);
|
||||
});
|
||||
}
|
||||
exports.default = modifyHTML;
|
10
book/node_modules/honkit/lib/output/modifiers/resolveImages.d.ts
generated
vendored
Normal file
10
book/node_modules/honkit/lib/output/modifiers/resolveImages.d.ts
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
Resolve all HTML images:
|
||||
- /test.png in hello -> ../test.html
|
||||
|
||||
@param {string} currentFile
|
||||
@param {HTMLDom} $
|
||||
*/
|
||||
declare function resolveImages(currentFile: any, $: any): any;
|
||||
export default resolveImages;
|
||||
//# sourceMappingURL=resolveImages.d.ts.map
|
1
book/node_modules/honkit/lib/output/modifiers/resolveImages.d.ts.map
generated
vendored
Normal file
1
book/node_modules/honkit/lib/output/modifiers/resolveImages.d.ts.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"resolveImages.d.ts","sourceRoot":"","sources":["../../../src/output/modifiers/resolveImages.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AAEH,iBAAS,aAAa,CAAC,WAAW,KAAA,EAAE,CAAC,KAAA,OAkBpC;AAED,eAAe,aAAa,CAAC"}
|
30
book/node_modules/honkit/lib/output/modifiers/resolveImages.js
generated
vendored
Normal file
30
book/node_modules/honkit/lib/output/modifiers/resolveImages.js
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
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;
|
11
book/node_modules/honkit/lib/output/modifiers/resolveLinks.d.ts
generated
vendored
Normal file
11
book/node_modules/honkit/lib/output/modifiers/resolveLinks.d.ts
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
Resolve all HTML links:
|
||||
- /test.md in hello -> ../test.html
|
||||
|
||||
@param {string} currentFile
|
||||
@param {Function(String) -> String} resolveFile
|
||||
@param {HTMLDom} $
|
||||
*/
|
||||
declare function resolveLinks(currentFile: any, resolveFile: any, $: any): any;
|
||||
export default resolveLinks;
|
||||
//# sourceMappingURL=resolveLinks.d.ts.map
|
1
book/node_modules/honkit/lib/output/modifiers/resolveLinks.d.ts.map
generated
vendored
Normal file
1
book/node_modules/honkit/lib/output/modifiers/resolveLinks.d.ts.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"resolveLinks.d.ts","sourceRoot":"","sources":["../../../src/output/modifiers/resolveLinks.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,iBAAS,YAAY,CAAC,WAAW,KAAA,EAAE,WAAW,KAAA,EAAE,CAAC,KAAA,OAoChD;AAED,eAAe,YAAY,CAAC"}
|
46
book/node_modules/honkit/lib/output/modifiers/resolveLinks.js
generated
vendored
Normal file
46
book/node_modules/honkit/lib/output/modifiers/resolveLinks.js
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
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 url_1 = __importDefault(require("url"));
|
||||
const location_1 = __importDefault(require("../../utils/location"));
|
||||
const editHTMLElement_1 = __importDefault(require("./editHTMLElement"));
|
||||
/**
|
||||
Resolve all HTML links:
|
||||
- /test.md in hello -> ../test.html
|
||||
|
||||
@param {string} currentFile
|
||||
@param {Function(String) -> String} resolveFile
|
||||
@param {HTMLDom} $
|
||||
*/
|
||||
function resolveLinks(currentFile, resolveFile, $) {
|
||||
const currentDirectory = path_1.default.dirname(currentFile);
|
||||
return (0, editHTMLElement_1.default)($, "a", ($a) => {
|
||||
let href = $a.attr("href");
|
||||
// Don't change a tag without href
|
||||
if (!href) {
|
||||
return;
|
||||
}
|
||||
if (location_1.default.isExternal(href)) {
|
||||
$a.attr("target", "_blank");
|
||||
return;
|
||||
}
|
||||
// Split anchor
|
||||
const parsed = url_1.default.parse(href);
|
||||
href = parsed.pathname || "";
|
||||
if (href) {
|
||||
// Calcul absolute path for this
|
||||
href = location_1.default.toAbsolute(href, currentDirectory, ".");
|
||||
// Resolve file
|
||||
href = resolveFile(href);
|
||||
// Convert back to relative
|
||||
href = location_1.default.relative(currentDirectory, href);
|
||||
}
|
||||
// Add back anchor
|
||||
href = href + (parsed.hash || "");
|
||||
$a.attr("href", href);
|
||||
});
|
||||
}
|
||||
exports.default = resolveLinks;
|
9
book/node_modules/honkit/lib/output/modifiers/svgToImg.d.ts
generated
vendored
Normal file
9
book/node_modules/honkit/lib/output/modifiers/svgToImg.d.ts
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/**
|
||||
Replace SVG tag by IMG
|
||||
|
||||
@param {string} baseFolder
|
||||
@param {HTMLDom} $
|
||||
*/
|
||||
declare function svgToImg(baseFolder: any, currentFile: any, $: any): any;
|
||||
export default svgToImg;
|
||||
//# sourceMappingURL=svgToImg.d.ts.map
|
1
book/node_modules/honkit/lib/output/modifiers/svgToImg.d.ts.map
generated
vendored
Normal file
1
book/node_modules/honkit/lib/output/modifiers/svgToImg.d.ts.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"svgToImg.d.ts","sourceRoot":"","sources":["../../../src/output/modifiers/svgToImg.ts"],"names":[],"mappings":"AAuBA;;;;;GAKG;AAEH,iBAAS,QAAQ,CAAC,UAAU,KAAA,EAAE,WAAW,KAAA,EAAE,CAAC,KAAA,OA+B3C;AAED,eAAe,QAAQ,CAAC"}
|
58
book/node_modules/honkit/lib/output/modifiers/svgToImg.js
generated
vendored
Normal file
58
book/node_modules/honkit/lib/output/modifiers/svgToImg.js
generated
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
"use strict";
|
||||
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 crc_1 = __importDefault(require("crc"));
|
||||
const dom_serializer_1 = __importDefault(require("dom-serializer"));
|
||||
const editHTMLElement_1 = __importDefault(require("./editHTMLElement"));
|
||||
const fs_1 = __importDefault(require("../../utils/fs"));
|
||||
const location_1 = __importDefault(require("../../utils/location"));
|
||||
/**
|
||||
Render a cheerio DOM as html
|
||||
|
||||
@param {HTMLDom} $
|
||||
@param {HTMLElement} dom
|
||||
@param {Object}
|
||||
@return {string}
|
||||
*/
|
||||
function renderDOM($, dom, options) {
|
||||
if (!dom && $._root && $._root.children) {
|
||||
dom = $._root.children;
|
||||
}
|
||||
options = options || dom.options || $._options;
|
||||
return (0, dom_serializer_1.default)(dom, options);
|
||||
}
|
||||
/**
|
||||
Replace SVG tag by IMG
|
||||
|
||||
@param {string} baseFolder
|
||||
@param {HTMLDom} $
|
||||
*/
|
||||
function svgToImg(baseFolder, currentFile, $) {
|
||||
const currentDirectory = path_1.default.dirname(currentFile);
|
||||
return (0, editHTMLElement_1.default)($, "svg", ($svg) => {
|
||||
if ($svg.attr("fill")) {
|
||||
return;
|
||||
}
|
||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 3 arguments, but got 2.
|
||||
const content = `<?xml version="1.0" encoding="UTF-8"?>${renderDOM($, $svg)}`;
|
||||
// We avoid generating twice the same PNG
|
||||
const hash = crc_1.default.crc32(content).toString(16);
|
||||
const fileName = `${hash}.svg`;
|
||||
const filePath = path_1.default.join(baseFolder, fileName);
|
||||
// Write the svg to the file
|
||||
return (fs_1.default
|
||||
.assertFile(filePath, () => {
|
||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 3.
|
||||
return fs_1.default.writeFile(filePath, content, "utf8");
|
||||
})
|
||||
// Return as image
|
||||
.then(() => {
|
||||
const src = location_1.default.relative(currentDirectory, fileName);
|
||||
$svg.replaceWith(`<img src="${src}" />`);
|
||||
}));
|
||||
});
|
||||
}
|
||||
exports.default = svgToImg;
|
Reference in New Issue
Block a user