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,20 @@
|
|
|
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 mergeAtLevel_1 = __importDefault(require("./mergeAtLevel"));
|
|
7
|
+
/**
|
|
8
|
+
Edit the ref of an article
|
|
9
|
+
|
|
10
|
+
@param {Summary} summary
|
|
11
|
+
@param {string} level
|
|
12
|
+
@param {string} newRef
|
|
13
|
+
@return {Summary}
|
|
14
|
+
*/
|
|
15
|
+
function editArticleRef(summary, level, newRef) {
|
|
16
|
+
return mergeAtLevel_1.default(summary, level, {
|
|
17
|
+
ref: newRef,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
exports.default = editArticleRef;
|
|
@@ -0,0 +1,20 @@
|
|
|
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 mergeAtLevel_1 = __importDefault(require("./mergeAtLevel"));
|
|
7
|
+
/**
|
|
8
|
+
Edit title of an article
|
|
9
|
+
|
|
10
|
+
@param {Summary} summary
|
|
11
|
+
@param {string} level
|
|
12
|
+
@param {string} newTitle
|
|
13
|
+
@return {Summary}
|
|
14
|
+
*/
|
|
15
|
+
function editArticleTitle(summary, level, newTitle) {
|
|
16
|
+
return mergeAtLevel_1.default(summary, level, {
|
|
17
|
+
title: newTitle,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
exports.default = editArticleTitle;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
Edit title of a part in the summary
|
|
5
|
+
|
|
6
|
+
@param {Summary} summary
|
|
7
|
+
@param {number} index
|
|
8
|
+
@param {string} newTitle
|
|
9
|
+
@return {Summary}
|
|
10
|
+
*/
|
|
11
|
+
function editPartTitle(summary, index, newTitle) {
|
|
12
|
+
let parts = summary.getParts();
|
|
13
|
+
let part = parts.get(index);
|
|
14
|
+
if (!part) {
|
|
15
|
+
return summary;
|
|
16
|
+
}
|
|
17
|
+
part = part.set("title", newTitle);
|
|
18
|
+
parts = parts.set(index, part);
|
|
19
|
+
return summary.set("parts", parts);
|
|
20
|
+
}
|
|
21
|
+
exports.default = editPartTitle;
|
|
@@ -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 moveArticleAfter_1 = __importDefault(require("./moveArticleAfter"));
|
|
7
|
+
const moveArticle_1 = __importDefault(require("./moveArticle"));
|
|
8
|
+
const insertArticle_1 = __importDefault(require("./insertArticle"));
|
|
9
|
+
const removeArticle_1 = __importDefault(require("./removeArticle"));
|
|
10
|
+
const unshiftArticle_1 = __importDefault(require("./unshiftArticle"));
|
|
11
|
+
const editArticleTitle_1 = __importDefault(require("./editArticleTitle"));
|
|
12
|
+
const editArticleRef_1 = __importDefault(require("./editArticleRef"));
|
|
13
|
+
const insertPart_1 = __importDefault(require("./insertPart"));
|
|
14
|
+
const removePart_1 = __importDefault(require("./removePart"));
|
|
15
|
+
const editPartTitle_1 = __importDefault(require("./editPartTitle"));
|
|
16
|
+
exports.default = {
|
|
17
|
+
insertArticle: insertArticle_1.default,
|
|
18
|
+
moveArticle: moveArticle_1.default,
|
|
19
|
+
moveArticleAfter: moveArticleAfter_1.default,
|
|
20
|
+
removeArticle: removeArticle_1.default,
|
|
21
|
+
unshiftArticle: unshiftArticle_1.default,
|
|
22
|
+
editArticleTitle: editArticleTitle_1.default,
|
|
23
|
+
editArticleRef: editArticleRef_1.default,
|
|
24
|
+
insertPart: insertPart_1.default,
|
|
25
|
+
removePart: removePart_1.default,
|
|
26
|
+
editPartTitle: editPartTitle_1.default,
|
|
27
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
Index levels in an article tree
|
|
4
|
+
|
|
5
|
+
@param {Article}
|
|
6
|
+
@param {string} baseLevel
|
|
7
|
+
@return {Article}
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
function indexArticleLevels(article, baseLevel) {
|
|
11
|
+
baseLevel = baseLevel || article.getLevel();
|
|
12
|
+
let articles = article.getArticles();
|
|
13
|
+
articles = articles.map((inner, i) => {
|
|
14
|
+
return indexArticleLevels(inner, `${baseLevel}.${i + 1}`);
|
|
15
|
+
});
|
|
16
|
+
return article.merge({
|
|
17
|
+
level: baseLevel,
|
|
18
|
+
articles: articles,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
exports.default = indexArticleLevels;
|
|
@@ -0,0 +1,18 @@
|
|
|
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 indexPartLevels_1 = __importDefault(require("./indexPartLevels"));
|
|
7
|
+
/**
|
|
8
|
+
Index all levels in the summary
|
|
9
|
+
|
|
10
|
+
@param {Summary}
|
|
11
|
+
@return {Summary}
|
|
12
|
+
*/
|
|
13
|
+
function indexLevels(summary) {
|
|
14
|
+
let parts = summary.getParts();
|
|
15
|
+
parts = parts.map(indexPartLevels_1.default);
|
|
16
|
+
return summary.set("parts", parts);
|
|
17
|
+
}
|
|
18
|
+
exports.default = indexLevels;
|
|
@@ -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 indexArticleLevels_1 = __importDefault(require("./indexArticleLevels"));
|
|
7
|
+
/**
|
|
8
|
+
Index levels in a part
|
|
9
|
+
|
|
10
|
+
@param {Part}
|
|
11
|
+
@param {number} index
|
|
12
|
+
@return {Part}
|
|
13
|
+
*/
|
|
14
|
+
function indexPartLevels(part, index) {
|
|
15
|
+
const baseLevel = String(index + 1);
|
|
16
|
+
let articles = part.getArticles();
|
|
17
|
+
articles = articles.map((inner, i) => {
|
|
18
|
+
return indexArticleLevels_1.default(inner, `${baseLevel}.${i + 1}`);
|
|
19
|
+
});
|
|
20
|
+
return part.merge({
|
|
21
|
+
level: baseLevel,
|
|
22
|
+
articles: articles,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
exports.default = indexPartLevels;
|
|
@@ -0,0 +1,47 @@
|
|
|
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 summaryArticle_1 = __importDefault(require("../../models/summaryArticle"));
|
|
8
|
+
const mergeAtLevel_1 = __importDefault(require("./mergeAtLevel"));
|
|
9
|
+
const indexArticleLevels_1 = __importDefault(require("./indexArticleLevels"));
|
|
10
|
+
/**
|
|
11
|
+
Returns a new Summary with the article at the given level, with
|
|
12
|
+
subsequent article shifted.
|
|
13
|
+
|
|
14
|
+
@param {Summary} summary
|
|
15
|
+
@param {Article} article
|
|
16
|
+
@param {String|Article} level: level to insert at
|
|
17
|
+
@return {Summary}
|
|
18
|
+
*/
|
|
19
|
+
function insertArticle(summary, article, level) {
|
|
20
|
+
article = new summaryArticle_1.default(article);
|
|
21
|
+
level = is_1.default.string(level) ? level : level.getLevel();
|
|
22
|
+
let parent = summary.getParent(level);
|
|
23
|
+
if (!parent) {
|
|
24
|
+
return summary;
|
|
25
|
+
}
|
|
26
|
+
// Find the index to insert at
|
|
27
|
+
let articles = parent.getArticles();
|
|
28
|
+
const index = getLeafIndex(level);
|
|
29
|
+
// Insert the article at the right index
|
|
30
|
+
articles = articles.insert(index, article);
|
|
31
|
+
// Reindex the level from here
|
|
32
|
+
parent = parent.set("articles", articles);
|
|
33
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
|
|
34
|
+
parent = indexArticleLevels_1.default(parent);
|
|
35
|
+
return mergeAtLevel_1.default(summary, parent.getLevel(), parent);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
@param {string}
|
|
39
|
+
@return {number} The index of this level within its parent's children
|
|
40
|
+
*/
|
|
41
|
+
function getLeafIndex(level) {
|
|
42
|
+
const arr = level.split(".").map((char) => {
|
|
43
|
+
return parseInt(char, 10);
|
|
44
|
+
});
|
|
45
|
+
return arr[arr.length - 1] - 1;
|
|
46
|
+
}
|
|
47
|
+
exports.default = insertArticle;
|
|
@@ -0,0 +1,21 @@
|
|
|
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 summaryPart_1 = __importDefault(require("../../models/summaryPart"));
|
|
7
|
+
const indexLevels_1 = __importDefault(require("./indexLevels"));
|
|
8
|
+
/**
|
|
9
|
+
Returns a new Summary with a part inserted at given index
|
|
10
|
+
|
|
11
|
+
@param {Summary} summary
|
|
12
|
+
@param {Part} part
|
|
13
|
+
@param {number} index
|
|
14
|
+
@return {Summary}
|
|
15
|
+
*/
|
|
16
|
+
function insertPart(summary, part, index) {
|
|
17
|
+
part = new summaryPart_1.default(part);
|
|
18
|
+
const parts = summary.getParts().insert(index, part);
|
|
19
|
+
return indexLevels_1.default(summary.set("parts", parts));
|
|
20
|
+
}
|
|
21
|
+
exports.default = insertPart;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
Edit a list of articles
|
|
5
|
+
|
|
6
|
+
@param {List<Article>} articles
|
|
7
|
+
@param {string} level
|
|
8
|
+
@param {Article} newArticle
|
|
9
|
+
@return {List<Article>}
|
|
10
|
+
*/
|
|
11
|
+
function editArticleInList(articles, level, newArticle) {
|
|
12
|
+
return articles.map((article) => {
|
|
13
|
+
const articleLevel = article.getLevel();
|
|
14
|
+
if (articleLevel === level) {
|
|
15
|
+
// it is the article to edit
|
|
16
|
+
return article.merge(newArticle);
|
|
17
|
+
}
|
|
18
|
+
else if (level.indexOf(articleLevel) === 0) {
|
|
19
|
+
// it is a parent
|
|
20
|
+
const articles = editArticleInList(article.getArticles(), level, newArticle);
|
|
21
|
+
return article.set("articles", articles);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
// This is not the article you are looking for
|
|
25
|
+
return article;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
Edit an article in a part
|
|
31
|
+
|
|
32
|
+
@param {Part} part
|
|
33
|
+
@param {string} level
|
|
34
|
+
@param {Article} newArticle
|
|
35
|
+
@return {Part}
|
|
36
|
+
*/
|
|
37
|
+
function editArticleInPart(part, level, newArticle) {
|
|
38
|
+
let articles = part.getArticles();
|
|
39
|
+
articles = editArticleInList(articles, level, newArticle);
|
|
40
|
+
return part.set("articles", articles);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
Edit an article, or a part, in a summary. Does a shallow merge.
|
|
44
|
+
|
|
45
|
+
@param {Summary} summary
|
|
46
|
+
@param {string} level
|
|
47
|
+
@param {Article|Part} newValue
|
|
48
|
+
@return {Summary}
|
|
49
|
+
*/
|
|
50
|
+
function mergeAtLevel(summary, level, newValue) {
|
|
51
|
+
const levelParts = level.split(".");
|
|
52
|
+
const partIndex = Number(levelParts[0]) - 1;
|
|
53
|
+
let parts = summary.getParts();
|
|
54
|
+
let part = parts.get(partIndex);
|
|
55
|
+
if (!part) {
|
|
56
|
+
return summary;
|
|
57
|
+
}
|
|
58
|
+
const isEditingPart = levelParts.length < 2;
|
|
59
|
+
if (isEditingPart) {
|
|
60
|
+
part = part.merge(newValue);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
part = editArticleInPart(part, level, newValue);
|
|
64
|
+
}
|
|
65
|
+
parts = parts.set(partIndex, part);
|
|
66
|
+
return summary.set("parts", parts);
|
|
67
|
+
}
|
|
68
|
+
exports.default = mergeAtLevel;
|
|
@@ -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 is_1 = __importDefault(require("is"));
|
|
7
|
+
const removeArticle_1 = __importDefault(require("./removeArticle"));
|
|
8
|
+
const insertArticle_1 = __importDefault(require("./insertArticle"));
|
|
9
|
+
/**
|
|
10
|
+
Returns a new summary, with the given article removed from its
|
|
11
|
+
origin level, and placed at the given target level.
|
|
12
|
+
|
|
13
|
+
@param {Summary} summary
|
|
14
|
+
@param {String|SummaryArticle} origin: level to remove
|
|
15
|
+
@param {String|SummaryArticle} target: the level where the article will be found
|
|
16
|
+
@return {Summary}
|
|
17
|
+
*/
|
|
18
|
+
function moveArticle(summary, origin, target) {
|
|
19
|
+
// Coerce to level
|
|
20
|
+
const originLevel = is_1.default.string(origin) ? origin : origin.getLevel();
|
|
21
|
+
const targetLevel = is_1.default.string(target) ? target : target.getLevel();
|
|
22
|
+
const article = summary.getByLevel(originLevel);
|
|
23
|
+
// Remove first
|
|
24
|
+
const removed = removeArticle_1.default(summary, originLevel);
|
|
25
|
+
return insertArticle_1.default(removed, article, targetLevel);
|
|
26
|
+
}
|
|
27
|
+
exports.default = moveArticle;
|
|
@@ -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 removeArticle_1 = __importDefault(require("./removeArticle"));
|
|
8
|
+
const insertArticle_1 = __importDefault(require("./insertArticle"));
|
|
9
|
+
/**
|
|
10
|
+
Returns a new summary, with the an article moved after another
|
|
11
|
+
article. Unlike `moveArticle`, does not ensure that the article
|
|
12
|
+
will be found at the target's level plus one.
|
|
13
|
+
|
|
14
|
+
@param {Summary} summary
|
|
15
|
+
@param {String|SummaryArticle} origin
|
|
16
|
+
@param {String|SummaryArticle} afterTarget
|
|
17
|
+
@return {Summary}
|
|
18
|
+
*/
|
|
19
|
+
function moveArticleAfter(summary, origin, afterTarget) {
|
|
20
|
+
// Coerce to level
|
|
21
|
+
const originLevel = is_1.default.string(origin) ? origin : origin.getLevel();
|
|
22
|
+
const afterTargetLevel = is_1.default.string(afterTarget) ? afterTarget : afterTarget.getLevel();
|
|
23
|
+
const article = summary.getByLevel(originLevel);
|
|
24
|
+
const targetLevel = increment(afterTargetLevel);
|
|
25
|
+
if (targetLevel < origin) {
|
|
26
|
+
// Remove first
|
|
27
|
+
const removed = removeArticle_1.default(summary, originLevel);
|
|
28
|
+
// Insert then
|
|
29
|
+
return insertArticle_1.default(removed, article, targetLevel);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// Insert right after first
|
|
33
|
+
const inserted = insertArticle_1.default(summary, article, targetLevel);
|
|
34
|
+
// Remove old one
|
|
35
|
+
return removeArticle_1.default(inserted, originLevel);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
@param {string}
|
|
40
|
+
@return {Array<Number>}
|
|
41
|
+
*/
|
|
42
|
+
function levelToArray(l) {
|
|
43
|
+
return l.split(".").map((char) => {
|
|
44
|
+
return parseInt(char, 10);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
@param {Array<Number>}
|
|
49
|
+
@return {string}
|
|
50
|
+
*/
|
|
51
|
+
function arrayToLevel(a) {
|
|
52
|
+
return a.join(".");
|
|
53
|
+
}
|
|
54
|
+
function increment(level) {
|
|
55
|
+
level = levelToArray(level);
|
|
56
|
+
level[level.length - 1]++;
|
|
57
|
+
return arrayToLevel(level);
|
|
58
|
+
}
|
|
59
|
+
exports.default = moveArticleAfter;
|
|
@@ -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 is_1 = __importDefault(require("is"));
|
|
7
|
+
const mergeAtLevel_1 = __importDefault(require("./mergeAtLevel"));
|
|
8
|
+
const indexArticleLevels_1 = __importDefault(require("./indexArticleLevels"));
|
|
9
|
+
/**
|
|
10
|
+
Remove an article from a level.
|
|
11
|
+
|
|
12
|
+
@param {Summary} summary
|
|
13
|
+
@param {String|SummaryArticle} level: level to remove
|
|
14
|
+
@return {Summary}
|
|
15
|
+
*/
|
|
16
|
+
function removeArticle(summary, level) {
|
|
17
|
+
// Coerce to level
|
|
18
|
+
level = is_1.default.string(level) ? level : level.getLevel();
|
|
19
|
+
let parent = summary.getParent(level);
|
|
20
|
+
let articles = parent.getArticles();
|
|
21
|
+
// Find the index to remove
|
|
22
|
+
const index = articles.findIndex((art) => {
|
|
23
|
+
return art.getLevel() === level;
|
|
24
|
+
});
|
|
25
|
+
if (index === -1) {
|
|
26
|
+
return summary;
|
|
27
|
+
}
|
|
28
|
+
// Remove from children
|
|
29
|
+
articles = articles.remove(index);
|
|
30
|
+
parent = parent.set("articles", articles);
|
|
31
|
+
// Reindex the level from here
|
|
32
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
|
|
33
|
+
parent = indexArticleLevels_1.default(parent);
|
|
34
|
+
return mergeAtLevel_1.default(summary, parent.getLevel(), parent);
|
|
35
|
+
}
|
|
36
|
+
exports.default = removeArticle;
|
|
@@ -0,0 +1,18 @@
|
|
|
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 indexLevels_1 = __importDefault(require("./indexLevels"));
|
|
7
|
+
/**
|
|
8
|
+
Remove a part at given index
|
|
9
|
+
|
|
10
|
+
@param {Summary} summary
|
|
11
|
+
@param {Number|} index
|
|
12
|
+
@return {Summary}
|
|
13
|
+
*/
|
|
14
|
+
function removePart(summary, index) {
|
|
15
|
+
const parts = summary.getParts().remove(index);
|
|
16
|
+
return indexLevels_1.default(summary.set("parts", parts));
|
|
17
|
+
}
|
|
18
|
+
exports.default = removePart;
|