honkit 3.6.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +10 -0
- package/bin/honkit.js +8 -0
- package/lib/BuildGenerator.js +2 -0
- package/lib/__tests__/__fixtures__/honkit/book.js +9 -0
- package/lib/__tests__/githon.js +11 -0
- package/lib/__tests__/init.js +19 -0
- package/lib/__tests__/snapshot-honkit.js +45 -0
- package/lib/api/decodeConfig.js +17 -0
- package/lib/api/decodeGlobal.js +21 -0
- package/lib/api/decodePage.js +41 -0
- package/lib/api/deprecate.js +113 -0
- package/lib/api/encodeConfig.js +30 -0
- package/lib/api/encodeGlobal.js +226 -0
- package/lib/api/encodeNavigation.js +60 -0
- package/lib/api/encodePage.js +37 -0
- package/lib/api/encodeProgress.js +58 -0
- package/lib/api/encodeSummary.js +52 -0
- package/lib/api/index.js +15 -0
- package/lib/bin.js +46 -0
- package/lib/browser.js +41 -0
- package/lib/cli/build.js +36 -0
- package/lib/cli/buildEbook.js +63 -0
- package/lib/cli/getBook.js +24 -0
- package/lib/cli/getOutputFolder.js +19 -0
- package/lib/cli/index.js +11 -0
- package/lib/cli/init.js +17 -0
- package/lib/cli/options.js +38 -0
- package/lib/cli/parse.js +65 -0
- package/lib/cli/serve.js +184 -0
- package/lib/cli/server.js +116 -0
- package/lib/cli/watch.js +35 -0
- package/lib/constants/__tests__/configSchema.js +41 -0
- package/lib/constants/configDefault.js +9 -0
- package/lib/constants/configFiles.js +3 -0
- package/lib/constants/configSchema.js +235 -0
- package/lib/constants/defaultBlocks.js +48 -0
- package/lib/constants/defaultFilters.js +18 -0
- package/lib/constants/defaultPlugins.js +20 -0
- package/lib/constants/extsAsciidoc.js +3 -0
- package/lib/constants/extsMarkdown.js +3 -0
- package/lib/constants/ignoreFiles.js +3 -0
- package/lib/constants/pluginAssetsFolder.js +3 -0
- package/lib/constants/pluginHooks.js +3 -0
- package/lib/constants/pluginPrefix.js +3 -0
- package/lib/constants/pluginResources.js +7 -0
- package/lib/constants/templatesFolder.js +3 -0
- package/lib/constants/themePrefix.js +3 -0
- package/lib/fs/__tests__/mock.js +68 -0
- package/lib/fs/mock.js +88 -0
- package/lib/fs/node.js +44 -0
- package/lib/honkit.js +34 -0
- package/lib/index.js +17 -0
- package/lib/init.js +79 -0
- package/lib/json/encodeBook.js +41 -0
- package/lib/json/encodeBookWithPage.js +25 -0
- package/lib/json/encodeFile.js +20 -0
- package/lib/json/encodeGlossary.js +22 -0
- package/lib/json/encodeGlossaryEntry.js +16 -0
- package/lib/json/encodeLanguages.js +29 -0
- package/lib/json/encodeOutput.js +26 -0
- package/lib/json/encodeOutputWithPage.js +26 -0
- package/lib/json/encodePage.js +38 -0
- package/lib/json/encodeReadme.js +19 -0
- package/lib/json/encodeSummary.js +22 -0
- package/lib/json/encodeSummaryArticle.js +25 -0
- package/lib/json/encodeSummaryPart.js +19 -0
- package/lib/json/index.js +27 -0
- package/lib/models/__tests__/config.js +164 -0
- package/lib/models/__tests__/glossary.js +38 -0
- package/lib/models/__tests__/glossaryEntry.js +16 -0
- package/lib/models/__tests__/page.js +26 -0
- package/lib/models/__tests__/plugin.js +26 -0
- package/lib/models/__tests__/pluginDependency.js +71 -0
- package/lib/models/__tests__/summary.js +115 -0
- package/lib/models/__tests__/summaryArticle.js +62 -0
- package/lib/models/__tests__/summaryPart.js +24 -0
- package/lib/models/__tests__/templateBlock.js +172 -0
- package/lib/models/__tests__/templateEngine.js +49 -0
- package/lib/models/book.js +312 -0
- package/lib/models/config.js +152 -0
- package/lib/models/file.js +83 -0
- package/lib/models/fs.js +255 -0
- package/lib/models/glossary.js +90 -0
- package/lib/models/glossaryEntry.js +34 -0
- package/lib/models/hash.js +191 -0
- package/lib/models/ignore.js +40 -0
- package/lib/models/language.js +22 -0
- package/lib/models/languages.js +64 -0
- package/lib/models/output.js +109 -0
- package/lib/models/page.js +91 -0
- package/lib/models/parser.js +102 -0
- package/lib/models/plugin.js +139 -0
- package/lib/models/pluginDependency.js +192 -0
- package/lib/models/readme.js +38 -0
- package/lib/models/summary.js +199 -0
- package/lib/models/summaryArticle.js +169 -0
- package/lib/models/summaryPart.js +53 -0
- package/lib/models/templateBlock.js +230 -0
- package/lib/models/templateEngine.js +115 -0
- package/lib/models/templateOutput.js +36 -0
- package/lib/models/templateShortcut.js +65 -0
- package/lib/modifiers/config/__tests__/addPlugin.js +30 -0
- package/lib/modifiers/config/__tests__/removePlugin.js +29 -0
- package/lib/modifiers/config/__tests__/togglePlugin.js +28 -0
- package/lib/modifiers/config/addPlugin.js +27 -0
- package/lib/modifiers/config/editPlugin.js +13 -0
- package/lib/modifiers/config/getPluginConfig.js +22 -0
- package/lib/modifiers/config/hasPlugin.js +15 -0
- package/lib/modifiers/config/index.js +21 -0
- package/lib/modifiers/config/isDefaultPlugin.js +17 -0
- package/lib/modifiers/config/removePlugin.js +27 -0
- package/lib/modifiers/config/togglePlugin.js +32 -0
- package/lib/modifiers/index.js +11 -0
- package/lib/modifiers/summary/__tests__/editPartTitle.js +41 -0
- package/lib/modifiers/summary/__tests__/insertArticle.js +72 -0
- package/lib/modifiers/summary/__tests__/insertPart.js +56 -0
- package/lib/modifiers/summary/__tests__/mergeAtLevel.js +45 -0
- package/lib/modifiers/summary/__tests__/moveArticle.js +66 -0
- package/lib/modifiers/summary/__tests__/moveArticleAfter.js +75 -0
- package/lib/modifiers/summary/__tests__/removeArticle.js +54 -0
- package/lib/modifiers/summary/editArticleRef.js +20 -0
- package/lib/modifiers/summary/editArticleTitle.js +20 -0
- package/lib/modifiers/summary/editPartTitle.js +21 -0
- package/lib/modifiers/summary/index.js +27 -0
- package/lib/modifiers/summary/indexArticleLevels.js +21 -0
- package/lib/modifiers/summary/indexLevels.js +18 -0
- package/lib/modifiers/summary/indexPartLevels.js +25 -0
- package/lib/modifiers/summary/insertArticle.js +47 -0
- package/lib/modifiers/summary/insertPart.js +21 -0
- package/lib/modifiers/summary/mergeAtLevel.js +68 -0
- package/lib/modifiers/summary/moveArticle.js +27 -0
- package/lib/modifiers/summary/moveArticleAfter.js +59 -0
- package/lib/modifiers/summary/removeArticle.js +36 -0
- package/lib/modifiers/summary/removePart.js +18 -0
- package/lib/modifiers/summary/unshiftArticle.js +27 -0
- package/lib/output/__tests__/ebook.js +17 -0
- package/lib/output/__tests__/json.js +43 -0
- package/lib/output/__tests__/plugin-hooks.js +57 -0
- package/lib/output/__tests__/website.js +121 -0
- package/lib/output/callHook.js +51 -0
- package/lib/output/callPageHook.js +23 -0
- package/lib/output/createTemplateEngine.js +42 -0
- package/lib/output/ebook/getConvertOptions.js +69 -0
- package/lib/output/ebook/getCoverPath.js +30 -0
- package/lib/output/ebook/getPDFTemplate.js +40 -0
- package/lib/output/ebook/index.js +16 -0
- package/lib/output/ebook/onFinish.js +84 -0
- package/lib/output/ebook/onPage.js +23 -0
- package/lib/output/ebook/options.js +17 -0
- package/lib/output/generateAssets.js +26 -0
- package/lib/output/generateBook.js +167 -0
- package/lib/output/generatePage.js +90 -0
- package/lib/output/generatePages.js +52 -0
- package/lib/output/getModifiers.js +63 -0
- package/lib/output/helper/fileToOutput.js +30 -0
- package/lib/output/helper/fileToURL.js +30 -0
- package/lib/output/helper/index.js +3 -0
- package/lib/output/helper/resolveFileToURL.js +25 -0
- package/lib/output/helper/writeFile.js +26 -0
- package/lib/output/index.js +27 -0
- package/lib/output/json/index.js +14 -0
- package/lib/output/json/onFinish.js +39 -0
- package/lib/output/json/onPage.js +37 -0
- package/lib/output/json/options.js +11 -0
- package/lib/output/modifiers/__tests__/addHeadingId.js +23 -0
- package/lib/output/modifiers/__tests__/annotateText.js +39 -0
- package/lib/output/modifiers/__tests__/fetchRemoteImages.js +32 -0
- package/lib/output/modifiers/__tests__/highlightCode.js +48 -0
- package/lib/output/modifiers/__tests__/inlinePng.js +22 -0
- package/lib/output/modifiers/__tests__/inlineSvg.js +42 -0
- package/lib/output/modifiers/__tests__/resolveImages.js +39 -0
- package/lib/output/modifiers/__tests__/resolveLinks.js +81 -0
- package/lib/output/modifiers/__tests__/svgToImg.js +29 -0
- package/lib/output/modifiers/addHeadingId.js +26 -0
- package/lib/output/modifiers/annotateText.js +76 -0
- package/lib/output/modifiers/editHTMLElement.js +17 -0
- package/lib/output/modifiers/fetchRemoteImages.js +42 -0
- package/lib/output/modifiers/highlightCode.js +59 -0
- package/lib/output/modifiers/index.js +26 -0
- package/lib/output/modifiers/inlineAssets.js +29 -0
- package/lib/output/modifiers/inlinePng.js +43 -0
- package/lib/output/modifiers/inlineSvg.js +39 -0
- package/lib/output/modifiers/modifyHTML.js +27 -0
- package/lib/output/modifiers/resolveImages.js +30 -0
- package/lib/output/modifiers/resolveLinks.js +46 -0
- package/lib/output/modifiers/svgToImg.js +58 -0
- package/lib/output/page-cache.js +15 -0
- package/lib/output/prepareAssets.js +22 -0
- package/lib/output/preparePages.js +25 -0
- package/lib/output/preparePlugins.js +36 -0
- package/lib/output/testing/createMock.js +39 -0
- package/lib/output/testing/generateMock.js +55 -0
- package/lib/output/website/__tests__/i18n.js +40 -0
- package/lib/output/website/copyPluginAssets.js +92 -0
- package/lib/output/website/createTemplateEngine.js +136 -0
- package/lib/output/website/index.js +22 -0
- package/lib/output/website/listSearchPaths.js +20 -0
- package/lib/output/website/onAsset.js +29 -0
- package/lib/output/website/onFinish.js +35 -0
- package/lib/output/website/onInit.js +19 -0
- package/lib/output/website/onPage.js +73 -0
- package/lib/output/website/options.js +15 -0
- package/lib/output/website/prepareI18n.js +28 -0
- package/lib/output/website/prepareResources.js +49 -0
- package/lib/output/website/state.js +20 -0
- package/lib/parse/__tests__/listAssets.js +63 -0
- package/lib/parse/__tests__/parseBook.js +77 -0
- package/lib/parse/__tests__/parseGlossary.js +32 -0
- package/lib/parse/__tests__/parseIgnore.js +37 -0
- package/lib/parse/__tests__/parsePageFromString.js +34 -0
- package/lib/parse/__tests__/parseReadme.js +33 -0
- package/lib/parse/__tests__/parseSummary.js +30 -0
- package/lib/parse/findParsableFile.js +33 -0
- package/lib/parse/index.js +31 -0
- package/lib/parse/listAssets.js +36 -0
- package/lib/parse/lookupStructureFile.js +21 -0
- package/lib/parse/parseBook.js +68 -0
- package/lib/parse/parseConfig.js +52 -0
- package/lib/parse/parseGlossary.js +25 -0
- package/lib/parse/parseIgnore.js +43 -0
- package/lib/parse/parseLanguages.js +26 -0
- package/lib/parse/parsePage.js +21 -0
- package/lib/parse/parsePageFromString.js +25 -0
- package/lib/parse/parsePagesList.js +80 -0
- package/lib/parse/parseReadme.js +26 -0
- package/lib/parse/parseStructureFile.js +64 -0
- package/lib/parse/parseSummary.js +43 -0
- package/lib/parse/validateConfig.js +31 -0
- package/lib/parse/walkSummary.js +34 -0
- package/lib/parsers.js +60 -0
- package/lib/plugins/PluginResolver.js +84 -0
- package/lib/plugins/__tests__/findInstalled.js +25 -0
- package/lib/plugins/__tests__/listDependencies.js +28 -0
- package/lib/plugins/__tests__/sortDependencies.js +28 -0
- package/lib/plugins/__tests__/validatePlugin.js +99 -0
- package/lib/plugins/findInstalled.js +87 -0
- package/lib/plugins/index.js +17 -0
- package/lib/plugins/listBlocks.js +19 -0
- package/lib/plugins/listDependencies.js +33 -0
- package/lib/plugins/listDepsForBook.js +20 -0
- package/lib/plugins/listFilters.js +18 -0
- package/lib/plugins/listResources.js +44 -0
- package/lib/plugins/loadForBook.js +38 -0
- package/lib/plugins/loadPlugin.js +89 -0
- package/lib/plugins/package-name-util.js +48 -0
- package/lib/plugins/sortDependencies.js +30 -0
- package/lib/plugins/toNames.js +16 -0
- package/lib/plugins/validateConfig.js +60 -0
- package/lib/plugins/validatePlugin.js +36 -0
- package/lib/templating/__tests__/conrefsLoader.js +93 -0
- package/lib/templating/__tests__/postRender.js +52 -0
- package/lib/templating/__tests__/replaceShortcuts.js +27 -0
- package/lib/templating/conrefsLoader.js +88 -0
- package/lib/templating/index.js +19 -0
- package/lib/templating/listShortcuts.js +29 -0
- package/lib/templating/postRender.js +46 -0
- package/lib/templating/render.js +41 -0
- package/lib/templating/renderFile.js +39 -0
- package/lib/templating/replaceShortcuts.js +36 -0
- package/lib/templating/themesLoader.js +98 -0
- package/lib/utils/__tests__/git.js +47 -0
- package/lib/utils/__tests__/location.js +81 -0
- package/lib/utils/__tests__/path.js +19 -0
- package/lib/utils/command.js +104 -0
- package/lib/utils/error.js +88 -0
- package/lib/utils/fs.js +163 -0
- package/lib/utils/genKey.js +13 -0
- package/lib/utils/git.js +116 -0
- package/lib/utils/images.js +22 -0
- package/lib/utils/location.js +129 -0
- package/lib/utils/logger.js +158 -0
- package/lib/utils/mergeDefaults.js +18 -0
- package/lib/utils/path.js +62 -0
- package/lib/utils/promise.js +142 -0
- package/lib/utils/reducedObject.js +31 -0
- package/lib/utils/timing.js +90 -0
- package/package.json +112 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const modifyHTML_1 = __importDefault(require("./modifyHTML"));
|
|
7
|
+
const inlineAssets_1 = __importDefault(require("./inlineAssets"));
|
|
8
|
+
const addHeadingId_1 = __importDefault(require("./addHeadingId"));
|
|
9
|
+
const svgToImg_1 = __importDefault(require("./svgToImg"));
|
|
10
|
+
const fetchRemoteImages_1 = __importDefault(require("./fetchRemoteImages"));
|
|
11
|
+
const resolveLinks_1 = __importDefault(require("./resolveLinks"));
|
|
12
|
+
const resolveImages_1 = __importDefault(require("./resolveImages"));
|
|
13
|
+
const annotateText_1 = __importDefault(require("./annotateText"));
|
|
14
|
+
const highlightCode_1 = __importDefault(require("./highlightCode"));
|
|
15
|
+
exports.default = {
|
|
16
|
+
modifyHTML: modifyHTML_1.default,
|
|
17
|
+
inlineAssets: inlineAssets_1.default,
|
|
18
|
+
// HTML transformations
|
|
19
|
+
addHeadingId: addHeadingId_1.default,
|
|
20
|
+
svgToImg: svgToImg_1.default,
|
|
21
|
+
fetchRemoteImages: fetchRemoteImages_1.default,
|
|
22
|
+
resolveLinks: resolveLinks_1.default,
|
|
23
|
+
resolveImages: resolveImages_1.default,
|
|
24
|
+
annotateText: annotateText_1.default,
|
|
25
|
+
highlightCode: highlightCode_1.default,
|
|
26
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const resolveImages_1 = __importDefault(require("./resolveImages"));
|
|
7
|
+
const fetchRemoteImages_1 = __importDefault(require("./fetchRemoteImages"));
|
|
8
|
+
const svgToImg_1 = __importDefault(require("./svgToImg"));
|
|
9
|
+
const inlineSvg_1 = __importDefault(require("./inlineSvg"));
|
|
10
|
+
const inlinePng_1 = __importDefault(require("./inlinePng"));
|
|
11
|
+
const promise_1 = __importDefault(require("../../utils/promise"));
|
|
12
|
+
/**
|
|
13
|
+
Inline all assets in a page
|
|
14
|
+
|
|
15
|
+
@param {string} rootFolder
|
|
16
|
+
*/
|
|
17
|
+
function inlineAssets(rootFolder, currentFile) {
|
|
18
|
+
return function ($) {
|
|
19
|
+
return (promise_1.default()
|
|
20
|
+
// Resolving images and fetching external images should be
|
|
21
|
+
// done before svg conversion
|
|
22
|
+
.then(resolveImages_1.default.bind(null, currentFile, $))
|
|
23
|
+
.then(fetchRemoteImages_1.default.bind(null, rootFolder, currentFile, $))
|
|
24
|
+
.then(svgToImg_1.default.bind(null, rootFolder, currentFile, $))
|
|
25
|
+
.then(inlineSvg_1.default.bind(null, rootFolder, currentFile, $))
|
|
26
|
+
.then(inlinePng_1.default.bind(null, rootFolder, currentFile, $)));
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
exports.default = inlineAssets;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const crc_1 = __importDefault(require("crc"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const images_1 = __importDefault(require("../../utils/images"));
|
|
9
|
+
const fs_1 = __importDefault(require("../../utils/fs"));
|
|
10
|
+
const location_1 = __importDefault(require("../../utils/location"));
|
|
11
|
+
const editHTMLElement_1 = __importDefault(require("./editHTMLElement"));
|
|
12
|
+
/**
|
|
13
|
+
Convert all inline PNG images to PNG file
|
|
14
|
+
|
|
15
|
+
@param {string} rootFolder
|
|
16
|
+
@param {HTMLDom} $
|
|
17
|
+
@return {Promise}
|
|
18
|
+
*/
|
|
19
|
+
function inlinePng(rootFolder, currentFile, $) {
|
|
20
|
+
const currentDirectory = path_1.default.dirname(currentFile);
|
|
21
|
+
return editHTMLElement_1.default($, "img", ($img) => {
|
|
22
|
+
const src = $img.attr("src");
|
|
23
|
+
if (!location_1.default.isDataURI(src)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// We avoid generating twice the same PNG
|
|
27
|
+
const hash = crc_1.default.crc32(src).toString(16);
|
|
28
|
+
let fileName = `${hash}.png`;
|
|
29
|
+
// Result file path
|
|
30
|
+
const filePath = path_1.default.join(rootFolder, fileName);
|
|
31
|
+
return fs_1.default
|
|
32
|
+
.assertFile(filePath, () => {
|
|
33
|
+
return images_1.default.convertInlinePNG(src, filePath);
|
|
34
|
+
})
|
|
35
|
+
.then(() => {
|
|
36
|
+
// Convert filename to a relative filename
|
|
37
|
+
fileName = location_1.default.relative(currentDirectory, fileName);
|
|
38
|
+
// Replace src
|
|
39
|
+
$img.attr("src", fileName);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
exports.default = inlinePng;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const fs_1 = __importDefault(require("../../utils/fs"));
|
|
8
|
+
const location_1 = __importDefault(require("../../utils/location"));
|
|
9
|
+
const editHTMLElement_1 = __importDefault(require("./editHTMLElement"));
|
|
10
|
+
const cheerio_1 = __importDefault(require("cheerio"));
|
|
11
|
+
/**
|
|
12
|
+
Inline SVG images as needed
|
|
13
|
+
|
|
14
|
+
@param {string} rootFolder
|
|
15
|
+
@param {HTMLDom} $
|
|
16
|
+
@return {Promise}
|
|
17
|
+
*/
|
|
18
|
+
function inlineSvg(rootFolder, currentFile, $) {
|
|
19
|
+
const currentDirectory = path_1.default.dirname(currentFile);
|
|
20
|
+
return editHTMLElement_1.default($, "img", ($img) => {
|
|
21
|
+
let src = $img.attr("src");
|
|
22
|
+
if (path_1.default.extname(src) !== ".svg") {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// Calcul absolute path for this
|
|
26
|
+
src = location_1.default.toAbsolute(src, currentDirectory, ".");
|
|
27
|
+
const inputPath = path_1.default.join(rootFolder, src);
|
|
28
|
+
return fs_1.default.readFile(inputPath).then((svgContext) => {
|
|
29
|
+
const $ = cheerio_1.default.load(svgContext, { xmlMode: true });
|
|
30
|
+
const $svg = $("svg");
|
|
31
|
+
if ($svg.attr("style")) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
$svg.attr("fill", "currentColor");
|
|
35
|
+
$img.replaceWith($svg);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
exports.default = inlineSvg;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const cheerio_1 = __importDefault(require("cheerio"));
|
|
7
|
+
const promise_1 = __importDefault(require("../../utils/promise"));
|
|
8
|
+
/**
|
|
9
|
+
Apply a list of operations to a page and
|
|
10
|
+
output the new page.
|
|
11
|
+
|
|
12
|
+
@param {Page}
|
|
13
|
+
@param {List|Array<Transformation>}
|
|
14
|
+
@return {Promise<Page>}
|
|
15
|
+
*/
|
|
16
|
+
function modifyHTML(page, operations) {
|
|
17
|
+
const html = page.getContent();
|
|
18
|
+
const $ = cheerio_1.default.load(html);
|
|
19
|
+
return promise_1.default.forEach(operations, (op) => {
|
|
20
|
+
return op($);
|
|
21
|
+
}).then(() => {
|
|
22
|
+
const resultHTML = $.html();
|
|
23
|
+
const unescapedHtml = resultHTML.replace(/&#x([0-9a-f]{2,});/gi, (_, code) => String.fromCodePoint(parseInt(code, 16)));
|
|
24
|
+
return page.set("content", unescapedHtml);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
exports.default = modifyHTML;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const location_1 = __importDefault(require("../../utils/location"));
|
|
8
|
+
const editHTMLElement_1 = __importDefault(require("./editHTMLElement"));
|
|
9
|
+
/**
|
|
10
|
+
Resolve all HTML images:
|
|
11
|
+
- /test.png in hello -> ../test.html
|
|
12
|
+
|
|
13
|
+
@param {string} currentFile
|
|
14
|
+
@param {HTMLDom} $
|
|
15
|
+
*/
|
|
16
|
+
function resolveImages(currentFile, $) {
|
|
17
|
+
const currentDirectory = path_1.default.dirname(currentFile);
|
|
18
|
+
return editHTMLElement_1.default($, "img", ($img) => {
|
|
19
|
+
let src = $img.attr("src");
|
|
20
|
+
if (src === null || src === undefined || location_1.default.isExternal(src) || location_1.default.isDataURI(src)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
// Calcul absolute path for this
|
|
24
|
+
src = location_1.default.toAbsolute(src, currentDirectory, ".");
|
|
25
|
+
// Convert back to relative
|
|
26
|
+
src = location_1.default.relative(currentDirectory, src);
|
|
27
|
+
$img.attr("src", src);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
exports.default = resolveImages;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const url_1 = __importDefault(require("url"));
|
|
8
|
+
const location_1 = __importDefault(require("../../utils/location"));
|
|
9
|
+
const editHTMLElement_1 = __importDefault(require("./editHTMLElement"));
|
|
10
|
+
/**
|
|
11
|
+
Resolve all HTML links:
|
|
12
|
+
- /test.md in hello -> ../test.html
|
|
13
|
+
|
|
14
|
+
@param {string} currentFile
|
|
15
|
+
@param {Function(String) -> String} resolveFile
|
|
16
|
+
@param {HTMLDom} $
|
|
17
|
+
*/
|
|
18
|
+
function resolveLinks(currentFile, resolveFile, $) {
|
|
19
|
+
const currentDirectory = path_1.default.dirname(currentFile);
|
|
20
|
+
return editHTMLElement_1.default($, "a", ($a) => {
|
|
21
|
+
let href = $a.attr("href");
|
|
22
|
+
// Don't change a tag without href
|
|
23
|
+
if (!href) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (location_1.default.isExternal(href)) {
|
|
27
|
+
$a.attr("target", "_blank");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// Split anchor
|
|
31
|
+
const parsed = url_1.default.parse(href);
|
|
32
|
+
href = parsed.pathname || "";
|
|
33
|
+
if (href) {
|
|
34
|
+
// Calcul absolute path for this
|
|
35
|
+
href = location_1.default.toAbsolute(href, currentDirectory, ".");
|
|
36
|
+
// Resolve file
|
|
37
|
+
href = resolveFile(href);
|
|
38
|
+
// Convert back to relative
|
|
39
|
+
href = location_1.default.relative(currentDirectory, href);
|
|
40
|
+
}
|
|
41
|
+
// Add back anchor
|
|
42
|
+
href = href + (parsed.hash || "");
|
|
43
|
+
$a.attr("href", href);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
exports.default = resolveLinks;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const crc_1 = __importDefault(require("crc"));
|
|
8
|
+
const dom_serializer_1 = __importDefault(require("dom-serializer"));
|
|
9
|
+
const editHTMLElement_1 = __importDefault(require("./editHTMLElement"));
|
|
10
|
+
const fs_1 = __importDefault(require("../../utils/fs"));
|
|
11
|
+
const location_1 = __importDefault(require("../../utils/location"));
|
|
12
|
+
/**
|
|
13
|
+
Render a cheerio DOM as html
|
|
14
|
+
|
|
15
|
+
@param {HTMLDom} $
|
|
16
|
+
@param {HTMLElement} dom
|
|
17
|
+
@param {Object}
|
|
18
|
+
@return {string}
|
|
19
|
+
*/
|
|
20
|
+
function renderDOM($, dom, options) {
|
|
21
|
+
if (!dom && $._root && $._root.children) {
|
|
22
|
+
dom = $._root.children;
|
|
23
|
+
}
|
|
24
|
+
options = options || dom.options || $._options;
|
|
25
|
+
return dom_serializer_1.default(dom, options);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
Replace SVG tag by IMG
|
|
29
|
+
|
|
30
|
+
@param {string} baseFolder
|
|
31
|
+
@param {HTMLDom} $
|
|
32
|
+
*/
|
|
33
|
+
function svgToImg(baseFolder, currentFile, $) {
|
|
34
|
+
const currentDirectory = path_1.default.dirname(currentFile);
|
|
35
|
+
return editHTMLElement_1.default($, "svg", ($svg) => {
|
|
36
|
+
if ($svg.attr("fill")) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 3 arguments, but got 2.
|
|
40
|
+
const content = `<?xml version="1.0" encoding="UTF-8"?>${renderDOM($, $svg)}`;
|
|
41
|
+
// We avoid generating twice the same PNG
|
|
42
|
+
const hash = crc_1.default.crc32(content).toString(16);
|
|
43
|
+
const fileName = `${hash}.svg`;
|
|
44
|
+
const filePath = path_1.default.join(baseFolder, fileName);
|
|
45
|
+
// Write the svg to the file
|
|
46
|
+
return (fs_1.default
|
|
47
|
+
.assertFile(filePath, () => {
|
|
48
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 3.
|
|
49
|
+
return fs_1.default.writeFile(filePath, content, "utf8");
|
|
50
|
+
})
|
|
51
|
+
// Return as image
|
|
52
|
+
.then(() => {
|
|
53
|
+
const src = location_1.default.relative(currentDirectory, fileName);
|
|
54
|
+
$svg.replaceWith(`<img src="${src}" />`);
|
|
55
|
+
}));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
exports.default = svgToImg;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.clearCache = exports.getCache = void 0;
|
|
7
|
+
const flat_cache_1 = __importDefault(require("flat-cache"));
|
|
8
|
+
const getCache = () => {
|
|
9
|
+
return flat_cache_1.default.create("honkit-3.6.7");
|
|
10
|
+
};
|
|
11
|
+
exports.getCache = getCache;
|
|
12
|
+
const clearCache = () => {
|
|
13
|
+
return flat_cache_1.default.clearCacheById("honkit-3.6.7");
|
|
14
|
+
};
|
|
15
|
+
exports.clearCache = clearCache;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const parse_1 = __importDefault(require("../parse"));
|
|
7
|
+
/**
|
|
8
|
+
List all assets in the book
|
|
9
|
+
|
|
10
|
+
@param {Output}
|
|
11
|
+
@return {Promise<Output>}
|
|
12
|
+
*/
|
|
13
|
+
function prepareAssets(output) {
|
|
14
|
+
const book = output.getBook();
|
|
15
|
+
const pages = output.getPages();
|
|
16
|
+
const logger = output.getLogger();
|
|
17
|
+
return parse_1.default.listAssets(book, pages).then((assets) => {
|
|
18
|
+
logger.info.ln("found", assets.size, "asset files");
|
|
19
|
+
return output.set("assets", assets);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.default = prepareAssets;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const parse_1 = __importDefault(require("../parse"));
|
|
7
|
+
const promise_1 = __importDefault(require("../utils/promise"));
|
|
8
|
+
/**
|
|
9
|
+
List and prepare all pages
|
|
10
|
+
|
|
11
|
+
@param {Output}
|
|
12
|
+
@return {Promise<Output>}
|
|
13
|
+
*/
|
|
14
|
+
function preparePages(output) {
|
|
15
|
+
const book = output.getBook();
|
|
16
|
+
const logger = book.getLogger();
|
|
17
|
+
if (book.isMultilingual()) {
|
|
18
|
+
return promise_1.default(output);
|
|
19
|
+
}
|
|
20
|
+
return parse_1.default.parsePagesList(book).then((pages) => {
|
|
21
|
+
logger.info.ln("found", pages.size, "pages");
|
|
22
|
+
return output.set("pages", pages);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
exports.default = preparePages;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const plugins_1 = __importDefault(require("../plugins"));
|
|
7
|
+
const promise_1 = __importDefault(require("../utils/promise"));
|
|
8
|
+
/**
|
|
9
|
+
* Load and setup plugins
|
|
10
|
+
*
|
|
11
|
+
* @param {Output}
|
|
12
|
+
* @return {Promise<Output>}
|
|
13
|
+
*/
|
|
14
|
+
function preparePlugins(output) {
|
|
15
|
+
const book = output.getBook();
|
|
16
|
+
return (promise_1.default()
|
|
17
|
+
// Only load plugins for main book
|
|
18
|
+
.then(() => {
|
|
19
|
+
if (book.isLanguageBook()) {
|
|
20
|
+
return output.getPlugins();
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return plugins_1.default.loadForBook(book);
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
// Update book's configuration using the plugins
|
|
27
|
+
.then((plugins) => {
|
|
28
|
+
return plugins_1.default.validateConfig(book, plugins).then((newBook) => {
|
|
29
|
+
return output.merge({
|
|
30
|
+
book: newBook,
|
|
31
|
+
plugins: plugins,
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
exports.default = preparePlugins;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const mock_1 = __importDefault(require("../../fs/mock"));
|
|
7
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
8
|
+
const output_1 = __importDefault(require("../../models/output"));
|
|
9
|
+
const book_1 = __importDefault(require("../../models/book"));
|
|
10
|
+
const parseBook_1 = __importDefault(require("../../parse/parseBook"));
|
|
11
|
+
const preparePlugins_1 = __importDefault(require("../preparePlugins"));
|
|
12
|
+
/**
|
|
13
|
+
* Create an output using a generator
|
|
14
|
+
*
|
|
15
|
+
* FOR TESTING PURPOSE ONLY
|
|
16
|
+
*
|
|
17
|
+
* @param {Generator} generator
|
|
18
|
+
* @param {Map<String:String|Map>} files
|
|
19
|
+
* @param {*} [options]
|
|
20
|
+
* @return {Promise<Output>}
|
|
21
|
+
*/
|
|
22
|
+
function createMockOutput(generator, files, options) {
|
|
23
|
+
const fs = mock_1.default(files);
|
|
24
|
+
let book = book_1.default.createForFS(fs);
|
|
25
|
+
const state = generator.State ? new generator.State({}) : immutable_1.default.Map();
|
|
26
|
+
book = book.setLogLevel("disabled");
|
|
27
|
+
options = generator.Options(options);
|
|
28
|
+
return parseBook_1.default(book)
|
|
29
|
+
.then((resultBook) => {
|
|
30
|
+
return new output_1.default({
|
|
31
|
+
book: resultBook,
|
|
32
|
+
options: options,
|
|
33
|
+
state: state,
|
|
34
|
+
generator: generator.name,
|
|
35
|
+
});
|
|
36
|
+
})
|
|
37
|
+
.then(preparePlugins_1.default);
|
|
38
|
+
}
|
|
39
|
+
exports.default = createMockOutput;
|