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,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Return list of plugin names. This method is nly used in unit tests.
|
|
5
|
+
*
|
|
6
|
+
* @param {OrderedMap<String:Plugin} plugins
|
|
7
|
+
* @return {Array<String>}
|
|
8
|
+
*/
|
|
9
|
+
function toNames(plugins) {
|
|
10
|
+
return plugins
|
|
11
|
+
.map((plugin) => {
|
|
12
|
+
return plugin.getName();
|
|
13
|
+
})
|
|
14
|
+
.toArray();
|
|
15
|
+
}
|
|
16
|
+
exports.default = toNames;
|
|
@@ -0,0 +1,60 @@
|
|
|
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 jsonschema_1 = __importDefault(require("jsonschema"));
|
|
8
|
+
const json_schema_defaults_1 = __importDefault(require("json-schema-defaults"));
|
|
9
|
+
const promise_1 = __importDefault(require("../utils/promise"));
|
|
10
|
+
const error_1 = __importDefault(require("../utils/error"));
|
|
11
|
+
const mergeDefaults_1 = __importDefault(require("../utils/mergeDefaults"));
|
|
12
|
+
/**
|
|
13
|
+
Validate one plugin for a book and update book's confiration
|
|
14
|
+
|
|
15
|
+
@param {Book}
|
|
16
|
+
@param {Plugin}
|
|
17
|
+
@return {Book}
|
|
18
|
+
*/
|
|
19
|
+
function validatePluginConfig(book, plugin) {
|
|
20
|
+
let config = book.getConfig();
|
|
21
|
+
const packageInfos = plugin.getPackage();
|
|
22
|
+
const configKey = ["pluginsConfig", plugin.getName()].join(".");
|
|
23
|
+
let pluginConfig = config.getValue(configKey, {}).toJS();
|
|
24
|
+
const schema = (packageInfos.get("gitbook") || immutable_1.default.Map()).toJS();
|
|
25
|
+
if (!schema)
|
|
26
|
+
return book;
|
|
27
|
+
// Normalize schema
|
|
28
|
+
schema.id = `/${configKey}`;
|
|
29
|
+
schema.type = "object";
|
|
30
|
+
// Validate and throw if invalid
|
|
31
|
+
const v = new jsonschema_1.default.Validator();
|
|
32
|
+
const result = v.validate(pluginConfig, schema, {
|
|
33
|
+
propertyName: configKey,
|
|
34
|
+
});
|
|
35
|
+
// Throw error
|
|
36
|
+
if (result.errors.length > 0) {
|
|
37
|
+
throw new error_1.default.ConfigurationError(new Error(result.errors[0].stack));
|
|
38
|
+
}
|
|
39
|
+
// Insert default values
|
|
40
|
+
const defaults = json_schema_defaults_1.default(schema);
|
|
41
|
+
pluginConfig = mergeDefaults_1.default(pluginConfig, defaults);
|
|
42
|
+
// Update configuration
|
|
43
|
+
config = config.setValue(configKey, pluginConfig);
|
|
44
|
+
// Return new book
|
|
45
|
+
return book.set("config", config);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
Validate a book configuration for plugins and
|
|
49
|
+
returns an update configuration with default values.
|
|
50
|
+
|
|
51
|
+
@param {Book}
|
|
52
|
+
@param {OrderedMap<String:Plugin>}
|
|
53
|
+
@return {Promise<Book>}
|
|
54
|
+
*/
|
|
55
|
+
function validateConfig(book, plugins) {
|
|
56
|
+
return promise_1.default.reduce(plugins, (newBook, plugin) => {
|
|
57
|
+
return validatePluginConfig(newBook, plugin);
|
|
58
|
+
}, book);
|
|
59
|
+
}
|
|
60
|
+
exports.default = validateConfig;
|
|
@@ -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 honkit_1 = __importDefault(require("../honkit"));
|
|
7
|
+
const promise_1 = __importDefault(require("../utils/promise"));
|
|
8
|
+
/**
|
|
9
|
+
Validate a plugin
|
|
10
|
+
|
|
11
|
+
@param {Plugin} plugin
|
|
12
|
+
@return {Promise<Plugin>}
|
|
13
|
+
*/
|
|
14
|
+
function validatePlugin(plugin) {
|
|
15
|
+
const packageInfos = plugin.getPackage();
|
|
16
|
+
const isValid = plugin.isLoaded() &&
|
|
17
|
+
packageInfos &&
|
|
18
|
+
packageInfos.get("name") &&
|
|
19
|
+
packageInfos.get("engines") &&
|
|
20
|
+
(packageInfos.get("engines").get("gitbook") || packageInfos.get("engines").get("honkit"));
|
|
21
|
+
const pluginName = packageInfos.get("name") || "unknown plugin";
|
|
22
|
+
if (!isValid) {
|
|
23
|
+
return promise_1.default.reject(new Error(`Error loading plugin "${pluginName}" at "${plugin.getPath()}"`));
|
|
24
|
+
}
|
|
25
|
+
const gitbookVersion = packageInfos.get("engines").get("gitbook");
|
|
26
|
+
const honkitVersion = packageInfos.get("engines").get("honkit");
|
|
27
|
+
// support "gitbook" and "honkit"
|
|
28
|
+
if (gitbookVersion && !honkit_1.default.satisfies(gitbookVersion)) {
|
|
29
|
+
return promise_1.default.reject(new Error(`HonKit doesn't satisfy the requirements of this plugin: ${pluginName} require ${honkitVersion}`));
|
|
30
|
+
}
|
|
31
|
+
if (honkitVersion && !honkit_1.default.satisfies(honkitVersion)) {
|
|
32
|
+
return promise_1.default.reject(new Error(`HonKit doesn't satisfy the requirements of this plugin: ${pluginName} require ${honkitVersion}`));
|
|
33
|
+
}
|
|
34
|
+
return promise_1.default(plugin);
|
|
35
|
+
}
|
|
36
|
+
exports.default = validatePlugin;
|
|
@@ -0,0 +1,93 @@
|
|
|
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 templateEngine_1 = __importDefault(require("../../models/templateEngine"));
|
|
8
|
+
const render_1 = __importDefault(require("../render"));
|
|
9
|
+
const conrefsLoader_1 = __importDefault(require("../conrefsLoader"));
|
|
10
|
+
describe("ConrefsLoader", () => {
|
|
11
|
+
const dirName = `${__dirname}/`;
|
|
12
|
+
const fileName = path_1.default.join(dirName, "test.md");
|
|
13
|
+
describe("Git", () => {
|
|
14
|
+
const engine = new templateEngine_1.default({
|
|
15
|
+
// @ts-expect-error: Expected 0 arguments, but got 1.
|
|
16
|
+
loader: new conrefsLoader_1.default(dirName),
|
|
17
|
+
});
|
|
18
|
+
test("should include content from git", () => {
|
|
19
|
+
jest.setTimeout(20 * 1000);
|
|
20
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 4 arguments, but got 3.
|
|
21
|
+
return render_1.default(engine, fileName, '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md" %}').then((out) => {
|
|
22
|
+
expect(out.getContent()).toBe("Hello from git");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
test("should handle deep inclusion (1)", () => {
|
|
26
|
+
jest.setTimeout(20 * 1000);
|
|
27
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 4 arguments, but got 3.
|
|
28
|
+
return render_1.default(engine, fileName, '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test2.md" %}').then((out) => {
|
|
29
|
+
expect(out.getContent()).toBe("First Hello. Hello from git");
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
test("should handle deep inclusion (2)", () => {
|
|
33
|
+
jest.setTimeout(20 * 1000);
|
|
34
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 4 arguments, but got 3.
|
|
35
|
+
return render_1.default(engine, fileName, '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test3.md" %}').then((out) => {
|
|
36
|
+
expect(out.getContent()).toBe("First Hello. Hello from git");
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
describe("Local", () => {
|
|
41
|
+
const engine = new templateEngine_1.default({
|
|
42
|
+
// @ts-expect-error: Expected 0 arguments, but got 1.
|
|
43
|
+
loader: new conrefsLoader_1.default(dirName),
|
|
44
|
+
});
|
|
45
|
+
describe("Relative", () => {
|
|
46
|
+
test("should resolve basic relative filepath", () => {
|
|
47
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 4 arguments, but got 3.
|
|
48
|
+
return render_1.default(engine, fileName, '{% include "include.md" %}').then((out) => {
|
|
49
|
+
expect(out.getContent()).toBe("Hello World");
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
test("should resolve basic parent filepath", () => {
|
|
53
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 4 arguments, but got 3.
|
|
54
|
+
return render_1.default(engine, path_1.default.join(dirName, "hello/test.md"), '{% include "../include.md" %}').then((out) => {
|
|
55
|
+
expect(out.getContent()).toBe("Hello World");
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe("Absolute", () => {
|
|
60
|
+
test("should resolve absolute filepath", () => {
|
|
61
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 4 arguments, but got 3.
|
|
62
|
+
return render_1.default(engine, fileName, '{% include "/include.md" %}').then((out) => {
|
|
63
|
+
expect(out.getContent()).toBe("Hello World");
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
test("should resolve absolute filepath when in a directory", () => {
|
|
67
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 4 arguments, but got 3.
|
|
68
|
+
return render_1.default(engine, path_1.default.join(dirName, "hello/test.md"), '{% include "/include.md" %}').then((out) => {
|
|
69
|
+
expect(out.getContent()).toBe("Hello World");
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
describe("transform", () => {
|
|
75
|
+
function transform(filePath, source) {
|
|
76
|
+
expect(typeof filePath).toBe("string");
|
|
77
|
+
expect(typeof source).toBe("string");
|
|
78
|
+
expect(filePath).toBe(path_1.default.resolve(__dirname, "include.md"));
|
|
79
|
+
expect(source).toBe("Hello World");
|
|
80
|
+
return `test-${source}-endtest`;
|
|
81
|
+
}
|
|
82
|
+
const engine = new templateEngine_1.default({
|
|
83
|
+
// @ts-expect-error: Expected 0 arguments, but got 1.
|
|
84
|
+
loader: new conrefsLoader_1.default(dirName, transform),
|
|
85
|
+
});
|
|
86
|
+
test("should transform included content", () => {
|
|
87
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 4 arguments, but got 3.
|
|
88
|
+
return render_1.default(engine, fileName, '{% include "include.md" %}').then((out) => {
|
|
89
|
+
expect(out.getContent()).toBe("test-Hello World-endtest");
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
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 templateEngine_1 = __importDefault(require("../../models/templateEngine"));
|
|
7
|
+
const templateBlock_1 = __importDefault(require("../../models/templateBlock"));
|
|
8
|
+
const render_1 = __importDefault(require("../render"));
|
|
9
|
+
const postRender_1 = __importDefault(require("../postRender"));
|
|
10
|
+
describe("postRender", () => {
|
|
11
|
+
let testPost;
|
|
12
|
+
const engine = templateEngine_1.default.create({
|
|
13
|
+
blocks: [
|
|
14
|
+
templateBlock_1.default.create("lower", (blk) => {
|
|
15
|
+
return blk.body.toLowerCase();
|
|
16
|
+
}),
|
|
17
|
+
templateBlock_1.default.create("prefix", (blk) => {
|
|
18
|
+
return {
|
|
19
|
+
body: `_${blk.body}_`,
|
|
20
|
+
post: function () {
|
|
21
|
+
testPost = true;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
});
|
|
27
|
+
test("should correctly replace block", () => {
|
|
28
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 4 arguments, but got 3.
|
|
29
|
+
return render_1.default(engine, "README.md", "Hello {% lower %}Samy{% endlower %}")
|
|
30
|
+
.then((output) => {
|
|
31
|
+
expect(output.getContent()).toMatch(/Hello \{\{\-([\S]+)\-\}\}/);
|
|
32
|
+
expect(output.getBlocks().size).toBe(1);
|
|
33
|
+
return postRender_1.default(engine, output);
|
|
34
|
+
})
|
|
35
|
+
.then((result) => {
|
|
36
|
+
expect(result).toBe("Hello samy");
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
test("should correctly replace blocks", () => {
|
|
40
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 4 arguments, but got 3.
|
|
41
|
+
return render_1.default(engine, "README.md", "Hello {% lower %}Samy{% endlower %}{% prefix %}Pesse{% endprefix %}")
|
|
42
|
+
.then((output) => {
|
|
43
|
+
expect(output.getContent()).toMatch(/Hello \{\{\-([\S]+)\-\}\}\{\{\-([\S]+)\-\}\}/);
|
|
44
|
+
expect(output.getBlocks().size).toBe(2);
|
|
45
|
+
return postRender_1.default(engine, output);
|
|
46
|
+
})
|
|
47
|
+
.then((result) => {
|
|
48
|
+
expect(result).toBe("Hello samy_Pesse_");
|
|
49
|
+
expect(testPost).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -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 immutable_1 = __importDefault(require("immutable"));
|
|
7
|
+
const templateBlock_1 = __importDefault(require("../../models/templateBlock"));
|
|
8
|
+
const replaceShortcuts_1 = __importDefault(require("../replaceShortcuts"));
|
|
9
|
+
describe("replaceShortcuts", () => {
|
|
10
|
+
const blocks = immutable_1.default.List([
|
|
11
|
+
templateBlock_1.default.create("math", {
|
|
12
|
+
shortcuts: {
|
|
13
|
+
start: "$$",
|
|
14
|
+
end: "$$",
|
|
15
|
+
parsers: ["markdown"],
|
|
16
|
+
},
|
|
17
|
+
}),
|
|
18
|
+
]);
|
|
19
|
+
test("should correctly replace inline matches by block", () => {
|
|
20
|
+
const content = replaceShortcuts_1.default(blocks, "test.md", "Hello $$a = b$$");
|
|
21
|
+
expect(content).toBe("Hello {% math %}a = b{% endmath %}");
|
|
22
|
+
});
|
|
23
|
+
test("should correctly replace block matches", () => {
|
|
24
|
+
const content = replaceShortcuts_1.default(blocks, "test.md", "Hello\n$$\na = b\n$$\n");
|
|
25
|
+
expect(content).toBe("Hello\n{% math %}\na = b\n{% endmath %}\n");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
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 nunjucks_1 = __importDefault(require("nunjucks"));
|
|
8
|
+
const fs_1 = __importDefault(require("../utils/fs"));
|
|
9
|
+
const git_1 = __importDefault(require("../utils/git"));
|
|
10
|
+
const location_1 = __importDefault(require("../utils/location"));
|
|
11
|
+
const path_2 = __importDefault(require("../utils/path"));
|
|
12
|
+
/**
|
|
13
|
+
* Template loader resolving both:
|
|
14
|
+
* - relative url ("./test.md")
|
|
15
|
+
* - absolute url ("/test.md")
|
|
16
|
+
* - git url ("")
|
|
17
|
+
*
|
|
18
|
+
* @param {string} rootFolder
|
|
19
|
+
* @param {Function(filePath, source)} transformFn (optional)
|
|
20
|
+
* @param {Logger} logger (optional)
|
|
21
|
+
*/
|
|
22
|
+
const ConrefsLoader = nunjucks_1.default.Loader.extend({
|
|
23
|
+
async: true,
|
|
24
|
+
init: function (rootFolder, transformFn, logger) {
|
|
25
|
+
this.rootFolder = rootFolder;
|
|
26
|
+
this.transformFn = transformFn;
|
|
27
|
+
this.logger = logger;
|
|
28
|
+
this.git = new git_1.default();
|
|
29
|
+
},
|
|
30
|
+
// @ts-expect-error: Property 'extend' does not exist on type 'typeof Loader'.
|
|
31
|
+
getSource: function (sourceURL, callback) {
|
|
32
|
+
const that = this;
|
|
33
|
+
this.git
|
|
34
|
+
.resolve(sourceURL)
|
|
35
|
+
.then((filepath) => {
|
|
36
|
+
// Is local file
|
|
37
|
+
if (!filepath) {
|
|
38
|
+
filepath = path_1.default.resolve(sourceURL);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
if (that.logger)
|
|
42
|
+
that.logger.debug.ln("resolve from git", sourceURL, "to", filepath);
|
|
43
|
+
}
|
|
44
|
+
// Read file from absolute path
|
|
45
|
+
return fs_1.default
|
|
46
|
+
.readFile(filepath)
|
|
47
|
+
.then((source) => {
|
|
48
|
+
source = source.toString("utf8");
|
|
49
|
+
if (that.transformFn) {
|
|
50
|
+
return that.transformFn(filepath, source);
|
|
51
|
+
}
|
|
52
|
+
return source;
|
|
53
|
+
})
|
|
54
|
+
.then((source) => {
|
|
55
|
+
return {
|
|
56
|
+
src: source,
|
|
57
|
+
path: filepath,
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
})
|
|
61
|
+
.nodeify(callback);
|
|
62
|
+
},
|
|
63
|
+
resolve: function (from, to) {
|
|
64
|
+
// If origin is in the book, we enforce result file to be in the book
|
|
65
|
+
if (path_2.default.isInRoot(this.rootFolder, from)) {
|
|
66
|
+
// Path of current template in the rootFolder (not absolute to fs)
|
|
67
|
+
const fromRelative = path_1.default.relative(this.rootFolder, from);
|
|
68
|
+
// Resolve "to" to a filepath relative to rootFolder
|
|
69
|
+
const href = location_1.default.toAbsolute(to, path_1.default.dirname(fromRelative), "");
|
|
70
|
+
// Return absolute path
|
|
71
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 1 arguments, but got 2.
|
|
72
|
+
return path_2.default.resolveInRoot(this.rootFolder, href);
|
|
73
|
+
}
|
|
74
|
+
// If origin is in a git repository, we resolve file in the git repository
|
|
75
|
+
const gitRoot = this.git.resolveRoot(from);
|
|
76
|
+
if (gitRoot) {
|
|
77
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 1 arguments, but got 2.
|
|
78
|
+
return path_2.default.resolveInRoot(gitRoot, to);
|
|
79
|
+
}
|
|
80
|
+
// If origin is not in the book (include from a git content ref)
|
|
81
|
+
return path_1.default.resolve(path_1.default.dirname(from), to);
|
|
82
|
+
},
|
|
83
|
+
// Handle all files as relative, so that nunjucks pass responsability to 'resolve'
|
|
84
|
+
isRelative: function (filename) {
|
|
85
|
+
return location_1.default.isRelative(filename);
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
exports.default = ConrefsLoader;
|
|
@@ -0,0 +1,19 @@
|
|
|
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 render_1 = __importDefault(require("./render"));
|
|
7
|
+
const postRender_1 = __importDefault(require("./postRender"));
|
|
8
|
+
const renderFile_1 = __importDefault(require("./renderFile"));
|
|
9
|
+
const replaceShortcuts_1 = __importDefault(require("./replaceShortcuts"));
|
|
10
|
+
const conrefsLoader_1 = __importDefault(require("./conrefsLoader"));
|
|
11
|
+
const themesLoader_1 = __importDefault(require("./themesLoader"));
|
|
12
|
+
exports.default = {
|
|
13
|
+
render: render_1.default,
|
|
14
|
+
renderFile: renderFile_1.default,
|
|
15
|
+
postRender: postRender_1.default,
|
|
16
|
+
replaceShortcuts: replaceShortcuts_1.default,
|
|
17
|
+
ConrefsLoader: conrefsLoader_1.default,
|
|
18
|
+
ThemesLoader: themesLoader_1.default,
|
|
19
|
+
};
|
|
@@ -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 immutable_1 = __importDefault(require("immutable"));
|
|
7
|
+
const parsers_1 = __importDefault(require("../parsers"));
|
|
8
|
+
/**
|
|
9
|
+
* Return a list of all shortcuts that can apply
|
|
10
|
+
* to a file for a TemplatEngine
|
|
11
|
+
*
|
|
12
|
+
* @param {List<TemplateBlock>} engine
|
|
13
|
+
* @param {string} filePath
|
|
14
|
+
* @return {List<TemplateShortcut>}
|
|
15
|
+
*/
|
|
16
|
+
function listShortcuts(blocks, filePath) {
|
|
17
|
+
const parser = parsers_1.default.getForFile(filePath);
|
|
18
|
+
if (!parser) {
|
|
19
|
+
return immutable_1.default.List();
|
|
20
|
+
}
|
|
21
|
+
return blocks
|
|
22
|
+
.map((block) => {
|
|
23
|
+
return block.getShortcuts();
|
|
24
|
+
})
|
|
25
|
+
.filter((shortcuts) => {
|
|
26
|
+
return shortcuts && shortcuts.acceptParser(parser.getName());
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
exports.default = listShortcuts;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const promise_1 = __importDefault(require("../utils/promise"));
|
|
7
|
+
/**
|
|
8
|
+
* Replace position markers of blocks by body after processing
|
|
9
|
+
* This is done to avoid that markdown/asciidoc processer parse the block content
|
|
10
|
+
*
|
|
11
|
+
* @param {string} content
|
|
12
|
+
* @return {Object} {blocks: Set, content: String}
|
|
13
|
+
*/
|
|
14
|
+
function replaceBlocks(content, blocks) {
|
|
15
|
+
const newContent = content.replace(/\{\{\-\%([\s\S]+?)\%\-\}\}/g, (match, key) => {
|
|
16
|
+
let replacedWith = match;
|
|
17
|
+
const block = blocks.get(key);
|
|
18
|
+
if (block) {
|
|
19
|
+
replacedWith = replaceBlocks(block.get("body"), blocks);
|
|
20
|
+
}
|
|
21
|
+
return replacedWith;
|
|
22
|
+
});
|
|
23
|
+
return newContent;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Post render a template:
|
|
27
|
+
* - Execute "post" for blocks
|
|
28
|
+
* - Replace block content
|
|
29
|
+
*
|
|
30
|
+
* @param {TemplateEngine} engine
|
|
31
|
+
* @param {TemplateOutput} content
|
|
32
|
+
* @return {Promise<String>}
|
|
33
|
+
*/
|
|
34
|
+
function postRender(engine, output) {
|
|
35
|
+
const content = output.getContent();
|
|
36
|
+
const blocks = output.getBlocks();
|
|
37
|
+
const result = replaceBlocks(content, blocks);
|
|
38
|
+
return promise_1.default.forEach(blocks, (block) => {
|
|
39
|
+
const post = block.get("post");
|
|
40
|
+
if (!post) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
return post();
|
|
44
|
+
}).thenResolve(result);
|
|
45
|
+
}
|
|
46
|
+
exports.default = postRender;
|