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,48 @@
|
|
|
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
|
+
const highlightCode_1 = __importDefault(require("../highlightCode"));
|
|
9
|
+
describe("highlightCode", () => {
|
|
10
|
+
function doHighlight(lang, code) {
|
|
11
|
+
return {
|
|
12
|
+
text: `${lang || ""}$${code}`
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function doHighlightAsync(lang, code) {
|
|
16
|
+
return promise_1.default().then(() => {
|
|
17
|
+
return doHighlight(lang, code);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
test("should call it for normal code element", () => {
|
|
21
|
+
const $ = cheerio_1.default.load("<p>This is a <code>test</code></p>");
|
|
22
|
+
return highlightCode_1.default(doHighlight, $).then(() => {
|
|
23
|
+
const $code = $("code");
|
|
24
|
+
expect($code.text()).toBe("$test");
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
test("should call it for markdown code block", () => {
|
|
28
|
+
const $ = cheerio_1.default.load("<pre><code class=\"lang-js\">test</code></pre>");
|
|
29
|
+
return highlightCode_1.default(doHighlight, $).then(() => {
|
|
30
|
+
const $code = $("code");
|
|
31
|
+
expect($code.text()).toBe("js$test");
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
test("should call it for asciidoc code block", () => {
|
|
35
|
+
const $ = cheerio_1.default.load("<pre><code class=\"language-python\">test</code></pre>");
|
|
36
|
+
return highlightCode_1.default(doHighlight, $).then(() => {
|
|
37
|
+
const $code = $("code");
|
|
38
|
+
expect($code.text()).toBe("python$test");
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
test("should accept async highlighter", () => {
|
|
42
|
+
const $ = cheerio_1.default.load("<pre><code class=\"language-python\">test</code></pre>");
|
|
43
|
+
return highlightCode_1.default(doHighlightAsync, $).then(() => {
|
|
44
|
+
const $code = $("code");
|
|
45
|
+
expect($code.text()).toBe("python$test");
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -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 cheerio_1 = __importDefault(require("cheerio"));
|
|
7
|
+
const tmp_1 = __importDefault(require("tmp"));
|
|
8
|
+
const inlinePng_1 = __importDefault(require("../inlinePng"));
|
|
9
|
+
describe("inlinePng", () => {
|
|
10
|
+
let dir;
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
dir = tmp_1.default.dirSync();
|
|
13
|
+
});
|
|
14
|
+
test("should write an inline PNG using data URI as a file", () => {
|
|
15
|
+
const $ = cheerio_1.default.load("<img alt=\"HonKit Logo 20x20\" src=\"data:image/png;base64,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\"/>");
|
|
16
|
+
return inlinePng_1.default(dir.name, "index.html", $).then(() => {
|
|
17
|
+
const $img = $("img");
|
|
18
|
+
const src = $img.attr("src");
|
|
19
|
+
expect(dir.name).toHaveFile(src);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
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 tmp_1 = __importDefault(require("tmp"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const inlineSvg_1 = __importDefault(require("../inlineSvg"));
|
|
11
|
+
describe("inlineSvg", () => {
|
|
12
|
+
let dir;
|
|
13
|
+
let svgPath;
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
dir = tmp_1.default.dirSync();
|
|
16
|
+
svgPath = path_1.default.join(dir.name, "test.svg");
|
|
17
|
+
});
|
|
18
|
+
test("should inline svg icons", () => {
|
|
19
|
+
const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1"><rect width="200" height="100" stroke-width="6"/></svg>';
|
|
20
|
+
const $ = cheerio_1.default.load('<img src="test.svg"/>');
|
|
21
|
+
return fs_1.default.promises
|
|
22
|
+
.writeFile(svgPath, svg)
|
|
23
|
+
.then(() => {
|
|
24
|
+
return inlineSvg_1.default(dir.name, "index.html", $);
|
|
25
|
+
})
|
|
26
|
+
.then(() => {
|
|
27
|
+
expect($("svg").attr("fill")).toBe("currentColor");
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
test("should not inline svgs with style tags", () => {
|
|
31
|
+
const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1" style="background-color:red"><rect width="200" height="100" stroke="black" stroke-width="6" fill="green"/></svg>';
|
|
32
|
+
const $ = cheerio_1.default.load('<img src="test.svg"/>');
|
|
33
|
+
return fs_1.default.promises
|
|
34
|
+
.writeFile(svgPath, svg)
|
|
35
|
+
.then(() => {
|
|
36
|
+
return inlineSvg_1.default(dir.name, "index.html", $);
|
|
37
|
+
})
|
|
38
|
+
.then(() => {
|
|
39
|
+
expect($("svg").length).toBe(0);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -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 cheerio_1 = __importDefault(require("cheerio"));
|
|
7
|
+
const resolveImages_1 = __importDefault(require("../resolveImages"));
|
|
8
|
+
describe("resolveImages", () => {
|
|
9
|
+
describe("img tag", () => {
|
|
10
|
+
const TEST = "<img src=\"http://www.github.com\">";
|
|
11
|
+
test("no error occurs and return undefined", () => {
|
|
12
|
+
const $ = cheerio_1.default.load(TEST);
|
|
13
|
+
return resolveImages_1.default("hello.md", $).then(() => {
|
|
14
|
+
const src = $("img").attr("src");
|
|
15
|
+
expect(src).toBe("http://www.github.com");
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
describe("img tag with break line", () => {
|
|
20
|
+
const TEST = "<img \nsrc=\"http://www.github.com\">";
|
|
21
|
+
test("no error occurs and return undefined", () => {
|
|
22
|
+
const $ = cheerio_1.default.load(TEST);
|
|
23
|
+
return resolveImages_1.default("hello.md", $).then(() => {
|
|
24
|
+
const src = $("img").attr("src");
|
|
25
|
+
expect(src).toBe("http://www.github.com");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
describe("img tag with src with plus sign", () => {
|
|
30
|
+
const TEST = "<img +src=\"http://www.github.com\">";
|
|
31
|
+
test("no error occurs and return undefined", () => {
|
|
32
|
+
const $ = cheerio_1.default.load(TEST);
|
|
33
|
+
return resolveImages_1.default("hello.md", $).then(() => {
|
|
34
|
+
const src = $("img").attr("src");
|
|
35
|
+
expect(src).toBe(undefined);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
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 cheerio_1 = __importDefault(require("cheerio"));
|
|
8
|
+
const resolveLinks_1 = __importDefault(require("../resolveLinks"));
|
|
9
|
+
describe("resolveLinks", () => {
|
|
10
|
+
function resolveFileBasic(href) {
|
|
11
|
+
return `fakeDir/${href}`;
|
|
12
|
+
}
|
|
13
|
+
function resolveFileCustom(href) {
|
|
14
|
+
if (path_1.default.extname(href) == ".md") {
|
|
15
|
+
return `${href.slice(0, -3)}.html`;
|
|
16
|
+
}
|
|
17
|
+
return href;
|
|
18
|
+
}
|
|
19
|
+
describe("Absolute path", () => {
|
|
20
|
+
const TEST = "<p>This is a <a href=\"/test/cool.md\"></a></p>";
|
|
21
|
+
test("should resolve path starting by \"/\" in root directory", () => {
|
|
22
|
+
const $ = cheerio_1.default.load(TEST);
|
|
23
|
+
return resolveLinks_1.default("hello.md", resolveFileBasic, $).then(() => {
|
|
24
|
+
const link = $("a");
|
|
25
|
+
expect(link.attr("href")).toBe("fakeDir/test/cool.md");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
test("should resolve path starting by \"/\" in child directory", () => {
|
|
29
|
+
const $ = cheerio_1.default.load(TEST);
|
|
30
|
+
return resolveLinks_1.default("afolder/hello.md", resolveFileBasic, $).then(() => {
|
|
31
|
+
const link = $("a");
|
|
32
|
+
expect(link.attr("href")).toBe("../fakeDir/test/cool.md");
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
describe("Anchor", () => {
|
|
37
|
+
test("should prevent anchors in resolution", () => {
|
|
38
|
+
const TEST = "<p>This is a <a href=\"test/cool.md#an-anchor\"></a></p>";
|
|
39
|
+
const $ = cheerio_1.default.load(TEST);
|
|
40
|
+
return resolveLinks_1.default("hello.md", resolveFileCustom, $).then(() => {
|
|
41
|
+
const link = $("a");
|
|
42
|
+
expect(link.attr("href")).toBe("test/cool.html#an-anchor");
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
test("should ignore pure anchor links", () => {
|
|
46
|
+
const TEST = "<p>This is a <a href=\"#an-anchor\"></a></p>";
|
|
47
|
+
const $ = cheerio_1.default.load(TEST);
|
|
48
|
+
return resolveLinks_1.default("hello.md", resolveFileCustom, $).then(() => {
|
|
49
|
+
const link = $("a");
|
|
50
|
+
expect(link.attr("href")).toBe("#an-anchor");
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe("Custom Resolver", () => {
|
|
55
|
+
const TEST = "<p>This is a <a href=\"/test/cool.md\"></a> <a href=\"afile.png\"></a></p>";
|
|
56
|
+
test("should resolve path correctly for absolute path", () => {
|
|
57
|
+
const $ = cheerio_1.default.load(TEST);
|
|
58
|
+
return resolveLinks_1.default("hello.md", resolveFileCustom, $).then(() => {
|
|
59
|
+
const link = $("a").first();
|
|
60
|
+
expect(link.attr("href")).toBe("test/cool.html");
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
test("should resolve path correctly for absolute path (2)", () => {
|
|
64
|
+
const $ = cheerio_1.default.load(TEST);
|
|
65
|
+
return resolveLinks_1.default("afodler/hello.md", resolveFileCustom, $).then(() => {
|
|
66
|
+
const link = $("a").first();
|
|
67
|
+
expect(link.attr("href")).toBe("../test/cool.html");
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
describe("External link", () => {
|
|
72
|
+
const TEST = "<p>This is a <a href=\"http://www.github.com\">external link</a></p>";
|
|
73
|
+
test("should have target=\"_blank\" attribute", () => {
|
|
74
|
+
const $ = cheerio_1.default.load(TEST);
|
|
75
|
+
return resolveLinks_1.default("hello.md", resolveFileBasic, $).then(() => {
|
|
76
|
+
const link = $("a");
|
|
77
|
+
expect(link.attr("target")).toBe("_blank");
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -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 cheerio_1 = __importDefault(require("cheerio"));
|
|
7
|
+
const tmp_1 = __importDefault(require("tmp"));
|
|
8
|
+
const svgToImg_1 = __importDefault(require("../svgToImg"));
|
|
9
|
+
describe("svgToImg", () => {
|
|
10
|
+
let dir;
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
dir = tmp_1.default.dirSync();
|
|
13
|
+
});
|
|
14
|
+
test("should write svg as a file", () => {
|
|
15
|
+
const $ = cheerio_1.default.load('<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1"><rect width="200" height="100" stroke="black" stroke-width="6" fill="green"/></svg>');
|
|
16
|
+
return svgToImg_1.default(dir.name, "index.html", $).then(() => {
|
|
17
|
+
const $img = $("img");
|
|
18
|
+
const src = $img.attr("src");
|
|
19
|
+
expect(dir.name).toHaveFile(src);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
it("should not write icon svg as a file", () => {
|
|
23
|
+
const $ = cheerio_1.default.load('<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1" fill="currentColor"><rect width="200" height="100" stroke-width="6"/></svg>');
|
|
24
|
+
return svgToImg_1.default(dir.name, "index.html", $).then(() => {
|
|
25
|
+
// @ts-expect-error
|
|
26
|
+
expect($.contains("img")).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -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 github_slugid_1 = __importDefault(require("github-slugid"));
|
|
7
|
+
const editHTMLElement_1 = __importDefault(require("./editHTMLElement"));
|
|
8
|
+
/**
|
|
9
|
+
Add ID to an heading
|
|
10
|
+
|
|
11
|
+
@param {HTMLElement} heading
|
|
12
|
+
*/
|
|
13
|
+
function addId(heading) {
|
|
14
|
+
if (heading.attr("id"))
|
|
15
|
+
return;
|
|
16
|
+
heading.attr("id", github_slugid_1.default(heading.text()));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
Add ID to all headings
|
|
20
|
+
|
|
21
|
+
@param {HTMLDom} $
|
|
22
|
+
*/
|
|
23
|
+
function addHeadingId($) {
|
|
24
|
+
return editHTMLElement_1.default($, "h1,h2,h3,h4,h5,h6", addId);
|
|
25
|
+
}
|
|
26
|
+
exports.default = addHeadingId;
|
|
@@ -0,0 +1,76 @@
|
|
|
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 escape_html_1 = __importDefault(require("escape-html"));
|
|
7
|
+
// Selector to ignore
|
|
8
|
+
const ANNOTATION_IGNORE = ".no-glossary,code,pre,a,script,h1,h2,h3,h4,h5,h6";
|
|
9
|
+
function pregQuote(str) {
|
|
10
|
+
return `${str}`.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, "\\$1");
|
|
11
|
+
}
|
|
12
|
+
function replaceText($, el, search, replace, text_only) {
|
|
13
|
+
return $(el).each(function () {
|
|
14
|
+
let node = this.firstChild, val, new_val;
|
|
15
|
+
// Elements to be removed at the end.
|
|
16
|
+
const remove = [];
|
|
17
|
+
// Only continue if firstChild exists.
|
|
18
|
+
if (node) {
|
|
19
|
+
// Loop over all childNodes.
|
|
20
|
+
while (node) {
|
|
21
|
+
// Only process text nodes.
|
|
22
|
+
if (node.nodeType === 3) {
|
|
23
|
+
// The original node value.
|
|
24
|
+
val = node.nodeValue;
|
|
25
|
+
// The new value.
|
|
26
|
+
new_val = val.replace(search, replace);
|
|
27
|
+
// Only replace text if the new value is actually different!
|
|
28
|
+
if (new_val !== val) {
|
|
29
|
+
if (!text_only && /</.test(new_val)) {
|
|
30
|
+
// The new value contains HTML, set it in a slower but far more
|
|
31
|
+
// robust way.
|
|
32
|
+
$(node).before(new_val);
|
|
33
|
+
// Don't remove the node yet, or the loop will lose its place.
|
|
34
|
+
remove.push(node);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// The new value contains no HTML, so it can be set in this
|
|
38
|
+
// very fast, simple way.
|
|
39
|
+
node.nodeValue = new_val;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
node = node.nextSibling;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Time to remove those elements!
|
|
47
|
+
if (remove.length)
|
|
48
|
+
$(remove).remove();
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Annotate text using a list of GlossaryEntry
|
|
53
|
+
*
|
|
54
|
+
* @param {List<GlossaryEntry>}
|
|
55
|
+
* @param {string} glossaryFilePath
|
|
56
|
+
* @param {HTMLDom} $
|
|
57
|
+
*/
|
|
58
|
+
function annotateText(entries, glossaryFilePath, $) {
|
|
59
|
+
entries.forEach((entry) => {
|
|
60
|
+
const entryId = entry.getID();
|
|
61
|
+
const name = entry.getName();
|
|
62
|
+
const description = entry.getDescription();
|
|
63
|
+
const searchRegex = new RegExp(`\\b(${pregQuote(name.toLowerCase())})\\b`, "gi");
|
|
64
|
+
$("*").each(function () {
|
|
65
|
+
const $this = $(this);
|
|
66
|
+
if ($this.is(ANNOTATION_IGNORE) || $this.parents(ANNOTATION_IGNORE).length > 0)
|
|
67
|
+
return;
|
|
68
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 5 arguments, but got 4.
|
|
69
|
+
replaceText($, this, searchRegex, (match) => {
|
|
70
|
+
return (`<a href="/${glossaryFilePath}#${entryId}" ` +
|
|
71
|
+
`class="glossary-term" title="${escape_html_1.default(description)}">${match}</a>`);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
exports.default = annotateText;
|
|
@@ -0,0 +1,17 @@
|
|
|
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 promise_1 = __importDefault(require("../../utils/promise"));
|
|
7
|
+
/**
|
|
8
|
+
Edit all elements matching a selector
|
|
9
|
+
*/
|
|
10
|
+
function editHTMLElement($, selector, fn) {
|
|
11
|
+
const $elements = $(selector);
|
|
12
|
+
return promise_1.default.forEach($elements, (el) => {
|
|
13
|
+
const $el = $(el);
|
|
14
|
+
return fn($el);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
exports.default = editHTMLElement;
|
|
@@ -0,0 +1,42 @@
|
|
|
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 editHTMLElement_1 = __importDefault(require("./editHTMLElement"));
|
|
9
|
+
const fs_1 = __importDefault(require("../../utils/fs"));
|
|
10
|
+
const location_1 = __importDefault(require("../../utils/location"));
|
|
11
|
+
/**
|
|
12
|
+
Fetch all remote images
|
|
13
|
+
|
|
14
|
+
@param {string} rootFolder
|
|
15
|
+
@param {string} currentFile
|
|
16
|
+
@param {HTMLDom} $
|
|
17
|
+
@return {Promise}
|
|
18
|
+
*/
|
|
19
|
+
function fetchRemoteImages(rootFolder, currentFile, $) {
|
|
20
|
+
const currentDirectory = path_1.default.dirname(currentFile);
|
|
21
|
+
return editHTMLElement_1.default($, "img", ($img) => {
|
|
22
|
+
let src = $img.attr("src");
|
|
23
|
+
const extension = path_1.default.extname(src);
|
|
24
|
+
if (!location_1.default.isExternal(src)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
// We avoid generating twice the same PNG
|
|
28
|
+
const hash = crc_1.default.crc32(src).toString(16);
|
|
29
|
+
const fileName = hash + extension;
|
|
30
|
+
const filePath = path_1.default.join(rootFolder, fileName);
|
|
31
|
+
return fs_1.default
|
|
32
|
+
.assertFile(filePath, () => {
|
|
33
|
+
return fs_1.default.download(src, filePath);
|
|
34
|
+
})
|
|
35
|
+
.then(() => {
|
|
36
|
+
// Convert to relative
|
|
37
|
+
src = location_1.default.relative(currentDirectory, fileName);
|
|
38
|
+
$img.replaceWith(`<img src="${src}" />`);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
exports.default = fetchRemoteImages;
|
|
@@ -0,0 +1,59 @@
|
|
|
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 is_1 = __importDefault(require("is"));
|
|
7
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
8
|
+
const promise_1 = __importDefault(require("../../utils/promise"));
|
|
9
|
+
const editHTMLElement_1 = __importDefault(require("./editHTMLElement"));
|
|
10
|
+
/**
|
|
11
|
+
Return language for a code blocks from a list of class names
|
|
12
|
+
|
|
13
|
+
@param {Array<String>}
|
|
14
|
+
@return {string}
|
|
15
|
+
*/
|
|
16
|
+
function getLanguageForClass(classNames) {
|
|
17
|
+
return immutable_1.default.List(classNames)
|
|
18
|
+
.map((cl) => {
|
|
19
|
+
// Markdown
|
|
20
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'search' does not exist on type 'unknown'... Remove this comment to see the full error message
|
|
21
|
+
if (cl.search("lang-") === 0) {
|
|
22
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'slice' does not exist on type 'unknown'.
|
|
23
|
+
return cl.slice("lang-".length);
|
|
24
|
+
}
|
|
25
|
+
// Asciidoc
|
|
26
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'search' does not exist on type 'unknown'... Remove this comment to see the full error message
|
|
27
|
+
if (cl.search("language-") === 0) {
|
|
28
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'slice' does not exist on type 'unknown'.
|
|
29
|
+
return cl.slice("language-".length);
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
})
|
|
33
|
+
.find((cl) => {
|
|
34
|
+
return Boolean(cl);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
Highlight all code elements
|
|
39
|
+
|
|
40
|
+
@param {Function(lang, body) -> String} highlight
|
|
41
|
+
@param {HTMLDom} $
|
|
42
|
+
@return {Promise}
|
|
43
|
+
*/
|
|
44
|
+
function highlightCode(highlight, $) {
|
|
45
|
+
return editHTMLElement_1.default($, "code", ($code) => {
|
|
46
|
+
const classNames = ($code.attr("class") || "").split(" ");
|
|
47
|
+
const lang = getLanguageForClass(classNames);
|
|
48
|
+
const source = $code.text();
|
|
49
|
+
return promise_1.default(highlight(lang, source)).then((r) => {
|
|
50
|
+
if (is_1.default.string(r.html)) {
|
|
51
|
+
$code.html(r.html);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
$code.text(r.text);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
exports.default = highlightCode;
|