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,199 @@
|
|
|
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 error_1 = __importDefault(require("../utils/error"));
|
|
9
|
+
const location_1 = __importDefault(require("../utils/location"));
|
|
10
|
+
const file_1 = __importDefault(require("./file"));
|
|
11
|
+
const summaryPart_1 = __importDefault(require("./summaryPart"));
|
|
12
|
+
const summaryArticle_1 = __importDefault(require("./summaryArticle"));
|
|
13
|
+
const parsers_1 = __importDefault(require("../parsers"));
|
|
14
|
+
class Summary extends immutable_1.default.Record({
|
|
15
|
+
file: new file_1.default(),
|
|
16
|
+
parts: immutable_1.default.List(),
|
|
17
|
+
}, "Summary") {
|
|
18
|
+
getFile() {
|
|
19
|
+
return this.get("file");
|
|
20
|
+
}
|
|
21
|
+
getParts() {
|
|
22
|
+
return this.get("parts");
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
Return a part by its index
|
|
26
|
+
*/
|
|
27
|
+
getPart(i) {
|
|
28
|
+
const parts = this.getParts();
|
|
29
|
+
return parts.get(i);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
Return an article using an iterator to find it.
|
|
33
|
+
if "partIter" is set, it can also return a Part.
|
|
34
|
+
|
|
35
|
+
@param {Function} iter
|
|
36
|
+
@param {Function} [partIter]
|
|
37
|
+
@return {Article|Part}
|
|
38
|
+
*/
|
|
39
|
+
getArticle(iter, partIter) {
|
|
40
|
+
const parts = this.getParts();
|
|
41
|
+
return parts.reduce((result, part) => {
|
|
42
|
+
if (result)
|
|
43
|
+
return result;
|
|
44
|
+
if (partIter && partIter(part))
|
|
45
|
+
return part;
|
|
46
|
+
return summaryArticle_1.default.findArticle(part, iter);
|
|
47
|
+
}, null);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
Return a part/article by its level
|
|
51
|
+
|
|
52
|
+
@param {string} level
|
|
53
|
+
@return {Article|Part}
|
|
54
|
+
*/
|
|
55
|
+
getByLevel(level) {
|
|
56
|
+
function iterByLevel(article) {
|
|
57
|
+
return article.getLevel() === level;
|
|
58
|
+
}
|
|
59
|
+
return this.getArticle(iterByLevel, iterByLevel);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
Return an article by its path
|
|
63
|
+
|
|
64
|
+
@param {string} filePath
|
|
65
|
+
@return {Article}
|
|
66
|
+
*/
|
|
67
|
+
getByPath(filePath) {
|
|
68
|
+
return this.getArticle((article) => {
|
|
69
|
+
const articlePath = article.getPath();
|
|
70
|
+
return articlePath && location_1.default.areIdenticalPaths(articlePath, filePath);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
Return the first article
|
|
75
|
+
|
|
76
|
+
@return {Article}
|
|
77
|
+
*/
|
|
78
|
+
getFirstArticle() {
|
|
79
|
+
return this.getArticle((article) => {
|
|
80
|
+
return true;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
Return next article of an article
|
|
85
|
+
|
|
86
|
+
*/
|
|
87
|
+
getNextArticle(current) {
|
|
88
|
+
const level = typeof current === "string" ? current : current.getLevel();
|
|
89
|
+
let wasPrev = false;
|
|
90
|
+
return this.getArticle((article) => {
|
|
91
|
+
if (wasPrev && !article.hasAnchor()) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
if (!wasPrev) {
|
|
95
|
+
wasPrev = article.getLevel() === level;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
Return previous article of an article
|
|
102
|
+
|
|
103
|
+
@param {Article} current
|
|
104
|
+
@return {Article}
|
|
105
|
+
*/
|
|
106
|
+
getPrevArticle(current) {
|
|
107
|
+
const level = is_1.default.string(current) ? current : current.getLevel();
|
|
108
|
+
let prev = undefined;
|
|
109
|
+
this.getArticle((article) => {
|
|
110
|
+
if (article.getLevel() == level) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
if (!article.hasAnchor()) {
|
|
114
|
+
prev = article;
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
});
|
|
118
|
+
return prev;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
Return the parent article, or parent part of an article
|
|
122
|
+
|
|
123
|
+
@param {String|Article} current
|
|
124
|
+
@return {Article|Part|Null}
|
|
125
|
+
*/
|
|
126
|
+
getParent(level) {
|
|
127
|
+
// Coerce to level
|
|
128
|
+
level = is_1.default.string(level) ? level : level.getLevel();
|
|
129
|
+
// Get parent level
|
|
130
|
+
const parentLevel = getParentLevel(level);
|
|
131
|
+
if (!parentLevel) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
// Get parent of the position
|
|
135
|
+
const parentArticle = this.getByLevel(parentLevel);
|
|
136
|
+
return parentArticle || null;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
Render summary as text
|
|
140
|
+
|
|
141
|
+
@param {string} parseExt Extension of the parser to use
|
|
142
|
+
@return {Promise<String>}
|
|
143
|
+
*/
|
|
144
|
+
toText(parseExt) {
|
|
145
|
+
const file = this.getFile();
|
|
146
|
+
const parts = this.getParts();
|
|
147
|
+
const parser = parseExt ? parsers_1.default.getByExt(parseExt) : file.getParser();
|
|
148
|
+
if (!parser) {
|
|
149
|
+
throw error_1.default.FileNotParsableError({
|
|
150
|
+
filename: file.getPath(),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return parser.renderSummary({
|
|
154
|
+
parts: parts.toJS(),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
Return all articles as a list
|
|
159
|
+
|
|
160
|
+
@return {List<Article>}
|
|
161
|
+
*/
|
|
162
|
+
getArticlesAsList() {
|
|
163
|
+
const accu = [];
|
|
164
|
+
this.getArticle((article) => {
|
|
165
|
+
accu.push(article);
|
|
166
|
+
});
|
|
167
|
+
return immutable_1.default.List(accu);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
Create a new summary for a list of parts
|
|
171
|
+
|
|
172
|
+
@param {Lust|Array} parts
|
|
173
|
+
@return {Summary}
|
|
174
|
+
*/
|
|
175
|
+
static createFromParts(file, parts) {
|
|
176
|
+
parts = parts.map((part, i) => {
|
|
177
|
+
if (part instanceof summaryPart_1.default) {
|
|
178
|
+
return part;
|
|
179
|
+
}
|
|
180
|
+
return summaryPart_1.default.create(part, i + 1);
|
|
181
|
+
});
|
|
182
|
+
return new Summary({
|
|
183
|
+
file: file,
|
|
184
|
+
// @ts-expect-error ts-migrate(2350) FIXME: Only a void function can be called with the 'new' ... Remove this comment to see the full error message
|
|
185
|
+
parts: new immutable_1.default.List(parts),
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
Returns parent level of a level
|
|
191
|
+
|
|
192
|
+
@param {string} level
|
|
193
|
+
@return {string}
|
|
194
|
+
*/
|
|
195
|
+
function getParentLevel(level) {
|
|
196
|
+
const parts = level.split(".");
|
|
197
|
+
return parts.slice(0, -1).join(".");
|
|
198
|
+
}
|
|
199
|
+
exports.default = Summary;
|
|
@@ -0,0 +1,169 @@
|
|
|
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 immutable_1 = __importDefault(require("immutable"));
|
|
7
|
+
const location_1 = __importDefault(require("../utils/location"));
|
|
8
|
+
class SummaryArticle extends immutable_1.default.Record({
|
|
9
|
+
level: String(),
|
|
10
|
+
title: String(),
|
|
11
|
+
ref: String(),
|
|
12
|
+
articles: immutable_1.default.List(),
|
|
13
|
+
}, "SummaryArticle") {
|
|
14
|
+
getLevel() {
|
|
15
|
+
return this.get("level");
|
|
16
|
+
}
|
|
17
|
+
getTitle() {
|
|
18
|
+
return this.get("title");
|
|
19
|
+
}
|
|
20
|
+
getRef() {
|
|
21
|
+
return this.get("ref");
|
|
22
|
+
}
|
|
23
|
+
getArticles() {
|
|
24
|
+
return this.get("articles");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Return how deep the article is.
|
|
28
|
+
* The README has a depth of 1
|
|
29
|
+
*
|
|
30
|
+
* @return {number}
|
|
31
|
+
*/
|
|
32
|
+
getDepth() {
|
|
33
|
+
return this.getLevel().split(".").length - 1;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get path (without anchor) to the pointing file.
|
|
37
|
+
* It also normalizes the file path.
|
|
38
|
+
*
|
|
39
|
+
* @return {string}
|
|
40
|
+
*/
|
|
41
|
+
getPath() {
|
|
42
|
+
if (this.isExternal()) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
const ref = this.getRef();
|
|
46
|
+
if (!ref) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const parts = ref.split("#");
|
|
50
|
+
const pathname = parts.length > 1 ? parts.slice(0, -1).join("#") : ref;
|
|
51
|
+
// Normalize path to remove ('./', '/...', etc)
|
|
52
|
+
return location_1.default.flatten(pathname);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Return url if article is external
|
|
56
|
+
*
|
|
57
|
+
* @return {string}
|
|
58
|
+
*/
|
|
59
|
+
getUrl() {
|
|
60
|
+
return this.isExternal() ? this.getRef() : undefined;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get anchor for this article (or undefined)
|
|
64
|
+
*
|
|
65
|
+
* @return {string}
|
|
66
|
+
*/
|
|
67
|
+
getAnchor() {
|
|
68
|
+
const ref = this.getRef();
|
|
69
|
+
const parts = ref.split("#");
|
|
70
|
+
const anchor = parts.length > 1 ? `#${parts[parts.length - 1]}` : undefined;
|
|
71
|
+
return anchor;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Create a new level for a new child article
|
|
75
|
+
*
|
|
76
|
+
* @return {string}
|
|
77
|
+
*/
|
|
78
|
+
createChildLevel() {
|
|
79
|
+
const level = this.getLevel();
|
|
80
|
+
const subArticles = this.getArticles();
|
|
81
|
+
const childLevel = `${level}.${subArticles.size + 1}`;
|
|
82
|
+
return childLevel;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Is article pointing to a page of an absolute url
|
|
86
|
+
*
|
|
87
|
+
* @return {boolean}
|
|
88
|
+
*/
|
|
89
|
+
isPage() {
|
|
90
|
+
return Boolean(!this.isExternal() && this.getRef());
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Check if this article is a file (exatcly)
|
|
94
|
+
*
|
|
95
|
+
* @param {File} file
|
|
96
|
+
* @return {boolean}
|
|
97
|
+
*/
|
|
98
|
+
isFile(file) {
|
|
99
|
+
return file.getPath() === this.getPath() && this.getAnchor() === undefined;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Check if this article is the introduction of the book
|
|
103
|
+
*
|
|
104
|
+
* @param {Book|Readme} book
|
|
105
|
+
* @return {boolean}
|
|
106
|
+
*/
|
|
107
|
+
isReadme(book) {
|
|
108
|
+
// @ts-expect-error: union
|
|
109
|
+
const readme = book.getFile ? book : book.getReadme();
|
|
110
|
+
const file = readme.getFile();
|
|
111
|
+
return this.isFile(file);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Is article pointing to aan absolute url
|
|
115
|
+
*
|
|
116
|
+
* @return {boolean}
|
|
117
|
+
*/
|
|
118
|
+
isExternal() {
|
|
119
|
+
return location_1.default.isExternal(this.getRef());
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create a SummaryArticle
|
|
123
|
+
*
|
|
124
|
+
* @param {Object} def
|
|
125
|
+
* @return {SummaryArticle}
|
|
126
|
+
*/
|
|
127
|
+
static create(def, level) {
|
|
128
|
+
const articles = (def.articles || []).map((article, i) => {
|
|
129
|
+
if (article instanceof SummaryArticle) {
|
|
130
|
+
return article;
|
|
131
|
+
}
|
|
132
|
+
return SummaryArticle.create(article, [level, i + 1].join("."));
|
|
133
|
+
});
|
|
134
|
+
return new SummaryArticle({
|
|
135
|
+
level: level,
|
|
136
|
+
title: def.title,
|
|
137
|
+
ref: def.ref || def.path || "",
|
|
138
|
+
articles: immutable_1.default.List(articles),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Has anchor for this article
|
|
143
|
+
*
|
|
144
|
+
* @return {boolean}
|
|
145
|
+
*/
|
|
146
|
+
hasAnchor() {
|
|
147
|
+
const ref = this.getRef();
|
|
148
|
+
return ref.includes("#");
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Find an article from a base one
|
|
152
|
+
*
|
|
153
|
+
* @param {Article|Part} base
|
|
154
|
+
* @param {Function(article)} iter
|
|
155
|
+
* @return {Article}
|
|
156
|
+
*/
|
|
157
|
+
static findArticle(base, iter) {
|
|
158
|
+
const articles = base.getArticles();
|
|
159
|
+
return articles.reduce((result, article) => {
|
|
160
|
+
if (result)
|
|
161
|
+
return result;
|
|
162
|
+
if (iter(article)) {
|
|
163
|
+
return article;
|
|
164
|
+
}
|
|
165
|
+
return SummaryArticle.findArticle(article, iter);
|
|
166
|
+
}, null);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.default = SummaryArticle;
|
|
@@ -0,0 +1,53 @@
|
|
|
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 immutable_1 = __importDefault(require("immutable"));
|
|
7
|
+
const summaryArticle_1 = __importDefault(require("./summaryArticle"));
|
|
8
|
+
class SummaryPart extends immutable_1.default.Record({
|
|
9
|
+
level: String(),
|
|
10
|
+
title: String(),
|
|
11
|
+
articles: immutable_1.default.List(),
|
|
12
|
+
}) {
|
|
13
|
+
getLevel() {
|
|
14
|
+
return this.get("level");
|
|
15
|
+
}
|
|
16
|
+
getTitle() {
|
|
17
|
+
return this.get("title");
|
|
18
|
+
}
|
|
19
|
+
getArticles() {
|
|
20
|
+
return this.get("articles");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a new level for a new child article
|
|
24
|
+
*
|
|
25
|
+
* @return {string}
|
|
26
|
+
*/
|
|
27
|
+
createChildLevel() {
|
|
28
|
+
const level = this.getLevel();
|
|
29
|
+
const subArticles = this.getArticles();
|
|
30
|
+
const childLevel = `${level}.${subArticles.size + 1}`;
|
|
31
|
+
return childLevel;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a SummaryPart
|
|
35
|
+
*
|
|
36
|
+
* @param {Object} def
|
|
37
|
+
* @return {SummaryPart}
|
|
38
|
+
*/
|
|
39
|
+
static create(def, level) {
|
|
40
|
+
const articles = (def.articles || []).map((article, i) => {
|
|
41
|
+
if (article instanceof summaryArticle_1.default) {
|
|
42
|
+
return article;
|
|
43
|
+
}
|
|
44
|
+
return summaryArticle_1.default.create(article, [level, i + 1].join("."));
|
|
45
|
+
});
|
|
46
|
+
return new SummaryPart({
|
|
47
|
+
level: String(level),
|
|
48
|
+
title: def.title,
|
|
49
|
+
articles: immutable_1.default.List(articles),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.default = SummaryPart;
|
|
@@ -0,0 +1,230 @@
|
|
|
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 extend_1 = __importDefault(require("extend"));
|
|
8
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
9
|
+
const promise_1 = __importDefault(require("../utils/promise"));
|
|
10
|
+
const genKey_1 = __importDefault(require("../utils/genKey"));
|
|
11
|
+
const templateShortcut_1 = __importDefault(require("./templateShortcut"));
|
|
12
|
+
const NODE_ENDARGS = "%%endargs%%";
|
|
13
|
+
class TemplateBlock extends immutable_1.default.Record({
|
|
14
|
+
// Name of block, also the start tag
|
|
15
|
+
name: String(),
|
|
16
|
+
// End tag, default to "end<name>"
|
|
17
|
+
end: String(),
|
|
18
|
+
// Function to process the block content
|
|
19
|
+
process: Function(),
|
|
20
|
+
// List of String, for inner block tags
|
|
21
|
+
blocks: immutable_1.default.List(),
|
|
22
|
+
// List of shortcuts to replace with this block
|
|
23
|
+
shortcuts: immutable_1.default.Map(),
|
|
24
|
+
}, "TemplateBlock") {
|
|
25
|
+
getName() {
|
|
26
|
+
return this.get("name");
|
|
27
|
+
}
|
|
28
|
+
getEndTag() {
|
|
29
|
+
return this.get("end") || `end${this.getName()}`;
|
|
30
|
+
}
|
|
31
|
+
getProcess() {
|
|
32
|
+
return this.get("process");
|
|
33
|
+
}
|
|
34
|
+
getBlocks() {
|
|
35
|
+
return this.get("blocks");
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Return shortcuts associated with this block or undefined
|
|
39
|
+
* @return {TemplateShortcut|undefined}
|
|
40
|
+
*/
|
|
41
|
+
getShortcuts() {
|
|
42
|
+
const shortcuts = this.get("shortcuts");
|
|
43
|
+
if (shortcuts.size === 0) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
return templateShortcut_1.default.createForBlock(this, shortcuts);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Return name for the nunjucks extension
|
|
50
|
+
* @return {string}
|
|
51
|
+
*/
|
|
52
|
+
getExtensionName() {
|
|
53
|
+
return `Block${this.getName()}Extension`;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Return a nunjucks extension to represents this block
|
|
57
|
+
* @return {Nunjucks.Extension}
|
|
58
|
+
*/
|
|
59
|
+
toNunjucksExt(mainContext, blocksOutput) {
|
|
60
|
+
blocksOutput = blocksOutput || {};
|
|
61
|
+
const that = this;
|
|
62
|
+
const name = this.getName();
|
|
63
|
+
const endTag = this.getEndTag();
|
|
64
|
+
const blocks = this.getBlocks().toJS();
|
|
65
|
+
function Ext() {
|
|
66
|
+
this.tags = [name];
|
|
67
|
+
this.parse = function (parser, nodes) {
|
|
68
|
+
let lastBlockName = null;
|
|
69
|
+
let lastBlockArgs = null;
|
|
70
|
+
const allBlocks = blocks.concat([endTag]);
|
|
71
|
+
// Parse first block
|
|
72
|
+
const tok = parser.nextToken();
|
|
73
|
+
lastBlockArgs = parser.parseSignature(null, true);
|
|
74
|
+
parser.advanceAfterBlockEnd(tok.value);
|
|
75
|
+
const args = new nodes.NodeList();
|
|
76
|
+
const bodies = [];
|
|
77
|
+
const blockNamesNode = new nodes.Array(tok.lineno, tok.colno);
|
|
78
|
+
const blockArgCounts = new nodes.Array(tok.lineno, tok.colno);
|
|
79
|
+
// Parse while we found "end<block>"
|
|
80
|
+
do {
|
|
81
|
+
// Read body
|
|
82
|
+
const currentBody = parser.parseUntilBlocks.apply(parser, allBlocks);
|
|
83
|
+
// Handle body with previous block name and args
|
|
84
|
+
blockNamesNode.addChild(new nodes.Literal(args.lineno, args.colno, lastBlockName));
|
|
85
|
+
blockArgCounts.addChild(new nodes.Literal(args.lineno, args.colno, lastBlockArgs.children.length));
|
|
86
|
+
bodies.push(currentBody);
|
|
87
|
+
// Append arguments of this block as arguments of the run function
|
|
88
|
+
lastBlockArgs.children.forEach((child) => {
|
|
89
|
+
args.addChild(child);
|
|
90
|
+
});
|
|
91
|
+
// Read new block
|
|
92
|
+
lastBlockName = parser.nextToken().value;
|
|
93
|
+
// Parse signature and move to the end of the block
|
|
94
|
+
if (lastBlockName != endTag) {
|
|
95
|
+
lastBlockArgs = parser.parseSignature(null, true);
|
|
96
|
+
}
|
|
97
|
+
parser.advanceAfterBlockEnd(lastBlockName);
|
|
98
|
+
} while (lastBlockName != endTag);
|
|
99
|
+
args.addChild(blockNamesNode);
|
|
100
|
+
args.addChild(blockArgCounts);
|
|
101
|
+
args.addChild(new nodes.Literal(args.lineno, args.colno, NODE_ENDARGS));
|
|
102
|
+
return new nodes.CallExtensionAsync(this, "run", args, bodies);
|
|
103
|
+
};
|
|
104
|
+
this.run = function (context) {
|
|
105
|
+
const fnArgs = Array.prototype.slice.call(arguments, 1);
|
|
106
|
+
let args;
|
|
107
|
+
const blocks = [];
|
|
108
|
+
let bodies = [];
|
|
109
|
+
// Extract callback
|
|
110
|
+
const callback = fnArgs.pop();
|
|
111
|
+
// Detect end of arguments
|
|
112
|
+
const endArgIndex = fnArgs.indexOf(NODE_ENDARGS);
|
|
113
|
+
// Extract arguments and bodies
|
|
114
|
+
args = fnArgs.slice(0, endArgIndex);
|
|
115
|
+
bodies = fnArgs.slice(endArgIndex + 1);
|
|
116
|
+
// Extract block counts
|
|
117
|
+
const blockArgCounts = args.pop();
|
|
118
|
+
const blockNames = args.pop();
|
|
119
|
+
// Recreate list of blocks
|
|
120
|
+
blockNames.forEach((name, i) => {
|
|
121
|
+
const countArgs = blockArgCounts[i];
|
|
122
|
+
const blockBody = bodies.shift();
|
|
123
|
+
const blockArgs = countArgs > 0 ? args.slice(0, countArgs) : [];
|
|
124
|
+
args = args.slice(countArgs);
|
|
125
|
+
const blockKwargs = extractKwargs(blockArgs);
|
|
126
|
+
blocks.push({
|
|
127
|
+
name: name,
|
|
128
|
+
body: blockBody(),
|
|
129
|
+
args: blockArgs,
|
|
130
|
+
kwargs: blockKwargs,
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
const mainBlock = blocks.shift();
|
|
134
|
+
mainBlock.blocks = blocks;
|
|
135
|
+
promise_1.default()
|
|
136
|
+
.then(() => {
|
|
137
|
+
const ctx = extend_1.default({
|
|
138
|
+
ctx: context,
|
|
139
|
+
}, mainContext || {});
|
|
140
|
+
return that.applyBlock(mainBlock, ctx);
|
|
141
|
+
})
|
|
142
|
+
.then((result) => {
|
|
143
|
+
return that.blockResultToHtml(result, blocksOutput);
|
|
144
|
+
})
|
|
145
|
+
.nodeify(callback);
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
// @ts-expect-error: nunjucks.Extension
|
|
149
|
+
return Ext;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Apply a block to a content
|
|
153
|
+
* @param {Object} inner
|
|
154
|
+
* @param {Object} context
|
|
155
|
+
* @return {Promise<String>|String}
|
|
156
|
+
*/
|
|
157
|
+
applyBlock(inner, context) {
|
|
158
|
+
const processFn = this.getProcess();
|
|
159
|
+
inner = inner || {};
|
|
160
|
+
inner.args = inner.args || [];
|
|
161
|
+
inner.kwargs = inner.kwargs || {};
|
|
162
|
+
inner.blocks = inner.blocks || [];
|
|
163
|
+
const r = processFn.call(context, inner);
|
|
164
|
+
if (promise_1.default.isPromiseAlike(r)) {
|
|
165
|
+
return r.then(this.normalizeBlockResult.bind(this));
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
return this.normalizeBlockResult(r);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Normalize result from a block process function
|
|
173
|
+
* @param {Object|String} result
|
|
174
|
+
* @return {Object}
|
|
175
|
+
*/
|
|
176
|
+
normalizeBlockResult(result) {
|
|
177
|
+
if (is_1.default.string(result)) {
|
|
178
|
+
result = { body: result };
|
|
179
|
+
}
|
|
180
|
+
result.name = this.getName();
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Convert a block result to HTML
|
|
185
|
+
* @param {Object} result
|
|
186
|
+
* @param {Object} blocksOutput: stored post processing blocks in this object
|
|
187
|
+
* @return {string}
|
|
188
|
+
*/
|
|
189
|
+
blockResultToHtml(result, blocksOutput) {
|
|
190
|
+
let indexedKey;
|
|
191
|
+
const toIndex = !result.parse || result.post !== undefined;
|
|
192
|
+
if (toIndex) {
|
|
193
|
+
indexedKey = genKey_1.default();
|
|
194
|
+
blocksOutput[indexedKey] = result;
|
|
195
|
+
}
|
|
196
|
+
// Parsable block, just return it
|
|
197
|
+
if (result.parse) {
|
|
198
|
+
return result.body;
|
|
199
|
+
}
|
|
200
|
+
// Return it as a position marker
|
|
201
|
+
return `{{-%${indexedKey}%-}}`;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Create a template block from a function or an object
|
|
205
|
+
* @param {string} blockName
|
|
206
|
+
* @param {Object} block
|
|
207
|
+
* @return {TemplateBlock}
|
|
208
|
+
*/
|
|
209
|
+
static create(blockName, block) {
|
|
210
|
+
if (is_1.default.fn(block)) {
|
|
211
|
+
// @ts-expect-error ts-migrate(2350) FIXME: Only a void function can be called with the 'new' ... Remove this comment to see the full error message
|
|
212
|
+
block = new immutable_1.default.Map({
|
|
213
|
+
process: block,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
block = new TemplateBlock(block);
|
|
217
|
+
block = block.set("name", blockName);
|
|
218
|
+
return block;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Extract kwargs from an arguments array
|
|
223
|
+
* @param {Array} args
|
|
224
|
+
* @return {Object}
|
|
225
|
+
*/
|
|
226
|
+
function extractKwargs(args) {
|
|
227
|
+
const last = args[args.length - 1];
|
|
228
|
+
return is_1.default.object(last) && last.__keywords ? args.pop() : {};
|
|
229
|
+
}
|
|
230
|
+
exports.default = TemplateBlock;
|