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,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hashString = exports.hash = void 0;
|
|
4
|
+
// v8 has an optimization for storing 31-bit signed numbers.
|
|
5
|
+
// Values which have either 00 or 11 as the high order bits qualify.
|
|
6
|
+
// This function drops the highest order bit in a signed number, maintaining
|
|
7
|
+
// the sign bit.
|
|
8
|
+
function smi(i32) {
|
|
9
|
+
return ((i32 >>> 1) & 0x40000000) | (i32 & 0xbfffffff);
|
|
10
|
+
}
|
|
11
|
+
const defaultValueOf = Object.prototype.valueOf;
|
|
12
|
+
// If possible, use a WeakMap.
|
|
13
|
+
const usingWeakMap = typeof WeakMap === "function";
|
|
14
|
+
let weakMap;
|
|
15
|
+
if (usingWeakMap) {
|
|
16
|
+
weakMap = new WeakMap();
|
|
17
|
+
}
|
|
18
|
+
let objHashUID = 0;
|
|
19
|
+
let UID_HASH_KEY = "__immutablehash__";
|
|
20
|
+
if (typeof Symbol === "function") {
|
|
21
|
+
// @ts-expect-error ts-migrate(2322) FIXME: Type 'symbol' is not assignable to type 'string'.
|
|
22
|
+
UID_HASH_KEY = Symbol(UID_HASH_KEY);
|
|
23
|
+
}
|
|
24
|
+
const STRING_HASH_CACHE_MIN_STRLEN = 16;
|
|
25
|
+
const STRING_HASH_CACHE_MAX_SIZE = 255;
|
|
26
|
+
let STRING_HASH_CACHE_SIZE = 0;
|
|
27
|
+
let stringHashCache = {};
|
|
28
|
+
const hash = function hash(o) {
|
|
29
|
+
switch (typeof o) {
|
|
30
|
+
case "boolean":
|
|
31
|
+
// The hash values for built-in constants are a 1 value for each 5-byte
|
|
32
|
+
// shift region expect for the first, which encodes the value. This
|
|
33
|
+
// reduces the odds of a hash collision for these common values.
|
|
34
|
+
return o ? 0x42108421 : 0x42108420;
|
|
35
|
+
case "number":
|
|
36
|
+
return hashNumber(o);
|
|
37
|
+
case "string":
|
|
38
|
+
return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
|
|
39
|
+
case "object":
|
|
40
|
+
case "function":
|
|
41
|
+
if (o === null) {
|
|
42
|
+
return 0x42108422;
|
|
43
|
+
}
|
|
44
|
+
if (typeof o.hashCode === "function") {
|
|
45
|
+
// Drop any high bits from accidentally long hash codes.
|
|
46
|
+
return smi(o.hashCode(o));
|
|
47
|
+
}
|
|
48
|
+
if (o.valueOf !== defaultValueOf && typeof o.valueOf === "function") {
|
|
49
|
+
o = o.valueOf(o);
|
|
50
|
+
}
|
|
51
|
+
return hashJSObj(o);
|
|
52
|
+
case "undefined":
|
|
53
|
+
return 0x42108423;
|
|
54
|
+
default:
|
|
55
|
+
if (typeof o.toString === "function") {
|
|
56
|
+
return hashString(o.toString());
|
|
57
|
+
}
|
|
58
|
+
throw new Error(`Value type ${typeof o} cannot be hashed.`);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
exports.hash = hash;
|
|
62
|
+
// Compress arbitrarily large numbers into smi hashes.
|
|
63
|
+
function hashNumber(n) {
|
|
64
|
+
if (n !== n || n === Infinity) {
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
let hash = n | 0;
|
|
68
|
+
if (hash !== n) {
|
|
69
|
+
hash ^= n * 0xffffffff;
|
|
70
|
+
}
|
|
71
|
+
while (n > 0xffffffff) {
|
|
72
|
+
n /= 0xffffffff;
|
|
73
|
+
hash ^= n;
|
|
74
|
+
}
|
|
75
|
+
return smi(hash);
|
|
76
|
+
}
|
|
77
|
+
function cachedHashString(string) {
|
|
78
|
+
let hashed = stringHashCache[string];
|
|
79
|
+
if (hashed === undefined) {
|
|
80
|
+
hashed = hashString(string);
|
|
81
|
+
if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
|
|
82
|
+
STRING_HASH_CACHE_SIZE = 0;
|
|
83
|
+
stringHashCache = {};
|
|
84
|
+
}
|
|
85
|
+
STRING_HASH_CACHE_SIZE++;
|
|
86
|
+
stringHashCache[string] = hashed;
|
|
87
|
+
}
|
|
88
|
+
return hashed;
|
|
89
|
+
}
|
|
90
|
+
// http://jsperf.com/hashing-strings
|
|
91
|
+
function hashString(string) {
|
|
92
|
+
// This is the hash from JVM
|
|
93
|
+
// The hash code for a string is computed as
|
|
94
|
+
// s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
|
|
95
|
+
// where s[i] is the ith character of the string and n is the length of
|
|
96
|
+
// the string. We "mod" the result to make it between 0 (inclusive) and 2^31
|
|
97
|
+
// (exclusive) by dropping high bits.
|
|
98
|
+
let hashed = 0;
|
|
99
|
+
for (let ii = 0; ii < string.length; ii++) {
|
|
100
|
+
hashed = (31 * hashed + string.charCodeAt(ii)) | 0;
|
|
101
|
+
}
|
|
102
|
+
return smi(hashed);
|
|
103
|
+
}
|
|
104
|
+
exports.hashString = hashString;
|
|
105
|
+
function hashJSObj(obj) {
|
|
106
|
+
let hashed;
|
|
107
|
+
if (usingWeakMap) {
|
|
108
|
+
hashed = weakMap.get(obj);
|
|
109
|
+
if (hashed !== undefined) {
|
|
110
|
+
return hashed;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
hashed = obj[UID_HASH_KEY];
|
|
114
|
+
if (hashed !== undefined) {
|
|
115
|
+
return hashed;
|
|
116
|
+
}
|
|
117
|
+
if (!canDefineProperty) {
|
|
118
|
+
hashed = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
|
|
119
|
+
if (hashed !== undefined) {
|
|
120
|
+
return hashed;
|
|
121
|
+
}
|
|
122
|
+
hashed = getIENodeHash(obj);
|
|
123
|
+
if (hashed !== undefined) {
|
|
124
|
+
return hashed;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
hashed = ++objHashUID;
|
|
128
|
+
if (objHashUID & 0x40000000) {
|
|
129
|
+
objHashUID = 0;
|
|
130
|
+
}
|
|
131
|
+
if (usingWeakMap) {
|
|
132
|
+
weakMap.set(obj, hashed);
|
|
133
|
+
}
|
|
134
|
+
else if (isExtensible !== undefined && isExtensible(obj) === false) {
|
|
135
|
+
throw new Error("Non-extensible objects are not allowed as keys.");
|
|
136
|
+
}
|
|
137
|
+
else if (canDefineProperty) {
|
|
138
|
+
Object.defineProperty(obj, UID_HASH_KEY, {
|
|
139
|
+
enumerable: false,
|
|
140
|
+
configurable: false,
|
|
141
|
+
writable: false,
|
|
142
|
+
value: hashed,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
else if (obj.propertyIsEnumerable !== undefined &&
|
|
146
|
+
obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
|
|
147
|
+
// Since we can't define a non-enumerable property on the object
|
|
148
|
+
// we'll hijack one of the less-used non-enumerable properties to
|
|
149
|
+
// save our hash on it. Since this is a function it will not show up in
|
|
150
|
+
// `JSON.stringify` which is what we want.
|
|
151
|
+
obj.propertyIsEnumerable = function () {
|
|
152
|
+
return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
|
|
153
|
+
};
|
|
154
|
+
obj.propertyIsEnumerable[UID_HASH_KEY] = hashed;
|
|
155
|
+
}
|
|
156
|
+
else if (obj.nodeType !== undefined) {
|
|
157
|
+
// At this point we couldn't get the IE `uniqueID` to use as a hash
|
|
158
|
+
// and we couldn't use a non-enumerable property to exploit the
|
|
159
|
+
// dontEnum bug so we simply add the `UID_HASH_KEY` on the node
|
|
160
|
+
// itself.
|
|
161
|
+
obj[UID_HASH_KEY] = hashed;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
throw new Error("Unable to set a non-enumerable property on object.");
|
|
165
|
+
}
|
|
166
|
+
return hashed;
|
|
167
|
+
}
|
|
168
|
+
// Get references to ES5 object methods.
|
|
169
|
+
const isExtensible = Object.isExtensible;
|
|
170
|
+
// True if Object.defineProperty works as expected. IE8 fails this test.
|
|
171
|
+
const canDefineProperty = (function () {
|
|
172
|
+
try {
|
|
173
|
+
Object.defineProperty({}, "@", {});
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
})();
|
|
180
|
+
// IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
|
|
181
|
+
// and avoid memory leaks from the IE cloneNode bug.
|
|
182
|
+
function getIENodeHash(node) {
|
|
183
|
+
if (node && node.nodeType > 0) {
|
|
184
|
+
switch (node.nodeType) {
|
|
185
|
+
case 1: // Element
|
|
186
|
+
return node.uniqueID;
|
|
187
|
+
case 9: // Document
|
|
188
|
+
return node.documentElement && node.documentElement.uniqueID;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 ignore_1 = __importDefault(require("ignore"));
|
|
8
|
+
/*
|
|
9
|
+
Immutable version of node-ignore
|
|
10
|
+
*/
|
|
11
|
+
class Ignore extends immutable_1.default.Record({
|
|
12
|
+
ignore: ignore_1.default(),
|
|
13
|
+
}, "Ignore") {
|
|
14
|
+
getIgnore() {
|
|
15
|
+
return this.get("ignore");
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
Test if a file is ignored by these rules
|
|
19
|
+
|
|
20
|
+
@return {boolean}
|
|
21
|
+
* @param filename
|
|
22
|
+
*/
|
|
23
|
+
isFileIgnored(filename) {
|
|
24
|
+
const ignore = this.getIgnore();
|
|
25
|
+
return ignore.filter([filename]).length == 0;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
Add rules
|
|
29
|
+
@param {string}
|
|
30
|
+
@return {Ignore}
|
|
31
|
+
*/
|
|
32
|
+
add(rule) {
|
|
33
|
+
const ignore = this.getIgnore();
|
|
34
|
+
const newIgnore = ignore_1.default();
|
|
35
|
+
newIgnore.add(ignore);
|
|
36
|
+
newIgnore.add(rule);
|
|
37
|
+
return this.set("ignore", newIgnore);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.default = Ignore;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
8
|
+
class Language extends immutable_1.default.Record({
|
|
9
|
+
title: String(),
|
|
10
|
+
path: String(),
|
|
11
|
+
}) {
|
|
12
|
+
getTitle() {
|
|
13
|
+
return this.get("title");
|
|
14
|
+
}
|
|
15
|
+
getPath() {
|
|
16
|
+
return this.get("path");
|
|
17
|
+
}
|
|
18
|
+
getID() {
|
|
19
|
+
return path_1.default.basename(this.getPath());
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.default = Language;
|
|
@@ -0,0 +1,64 @@
|
|
|
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 file_1 = __importDefault(require("./file"));
|
|
8
|
+
const language_1 = __importDefault(require("./language"));
|
|
9
|
+
class Languages extends immutable_1.default.Record({
|
|
10
|
+
file: new file_1.default(),
|
|
11
|
+
list: immutable_1.default.OrderedMap(),
|
|
12
|
+
}) {
|
|
13
|
+
getFile() {
|
|
14
|
+
return this.get("file");
|
|
15
|
+
}
|
|
16
|
+
getList() {
|
|
17
|
+
return this.get("list");
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
Get default languages
|
|
21
|
+
|
|
22
|
+
@return {Language}
|
|
23
|
+
*/
|
|
24
|
+
getDefaultLanguage() {
|
|
25
|
+
return this.getList().first();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
Get a language by its ID
|
|
29
|
+
|
|
30
|
+
@param {string} lang
|
|
31
|
+
@return {Language}
|
|
32
|
+
*/
|
|
33
|
+
getLanguage(lang) {
|
|
34
|
+
return this.getList().get(lang);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
Return count of langs
|
|
38
|
+
|
|
39
|
+
@return {number}
|
|
40
|
+
*/
|
|
41
|
+
getCount() {
|
|
42
|
+
return this.getList().size;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
Create a languages list from a JS object
|
|
46
|
+
|
|
47
|
+
@return {Language}
|
|
48
|
+
*/
|
|
49
|
+
static createFromList(file, langs) {
|
|
50
|
+
let list = immutable_1.default.OrderedMap();
|
|
51
|
+
langs.forEach((lang) => {
|
|
52
|
+
lang = new language_1.default({
|
|
53
|
+
title: lang.title,
|
|
54
|
+
path: lang.ref,
|
|
55
|
+
});
|
|
56
|
+
list = list.set(lang.getID(), lang);
|
|
57
|
+
});
|
|
58
|
+
return new Languages({
|
|
59
|
+
file: file,
|
|
60
|
+
list: list,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.default = Languages;
|
|
@@ -0,0 +1,109 @@
|
|
|
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 fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
9
|
+
const parsePageFromString_1 = __importDefault(require("../parse/parsePageFromString"));
|
|
10
|
+
const book_1 = __importDefault(require("./book"));
|
|
11
|
+
const location_1 = __importDefault(require("../utils/location"));
|
|
12
|
+
class Output extends immutable_1.default.Record({
|
|
13
|
+
book: new book_1.default(),
|
|
14
|
+
// Name of the generator being used
|
|
15
|
+
generator: String(),
|
|
16
|
+
// Map of plugins to use (String -> Plugin)
|
|
17
|
+
plugins: immutable_1.default.OrderedMap(),
|
|
18
|
+
// Map pages to generation (String -> Page)
|
|
19
|
+
pages: immutable_1.default.OrderedMap(),
|
|
20
|
+
// List assets (String)
|
|
21
|
+
assets: immutable_1.default.List(),
|
|
22
|
+
// Option for the generation
|
|
23
|
+
options: immutable_1.default.Map(),
|
|
24
|
+
// Internal state for the generation
|
|
25
|
+
state: immutable_1.default.Map(),
|
|
26
|
+
// incrementalChangeFileSet for incremental building
|
|
27
|
+
// If it is empty, should build all
|
|
28
|
+
incrementalChangeFileSet: immutable_1.default.Set(),
|
|
29
|
+
}) {
|
|
30
|
+
getBook() {
|
|
31
|
+
return this.get("book");
|
|
32
|
+
}
|
|
33
|
+
getGenerator() {
|
|
34
|
+
return this.get("generator");
|
|
35
|
+
}
|
|
36
|
+
getPlugins() {
|
|
37
|
+
return this.get("plugins");
|
|
38
|
+
}
|
|
39
|
+
getPages() {
|
|
40
|
+
return this.get("pages");
|
|
41
|
+
}
|
|
42
|
+
getOptions() {
|
|
43
|
+
return this.get("options");
|
|
44
|
+
}
|
|
45
|
+
getAssets() {
|
|
46
|
+
return this.get("assets");
|
|
47
|
+
}
|
|
48
|
+
getState() {
|
|
49
|
+
return this.get("state");
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
Return a page byt its file path
|
|
53
|
+
|
|
54
|
+
@param {string} filePath
|
|
55
|
+
@return {Page|undefined}
|
|
56
|
+
*/
|
|
57
|
+
getPage(filePath) {
|
|
58
|
+
filePath = location_1.default.normalize(filePath);
|
|
59
|
+
const pages = this.getPages();
|
|
60
|
+
return pages.get(filePath);
|
|
61
|
+
}
|
|
62
|
+
reloadPage(contentRootDir, filePath) {
|
|
63
|
+
const relativePath = location_1.default.normalize(path_1.default.normalize(path_1.default.relative(contentRootDir, filePath)));
|
|
64
|
+
const pages = this.getPages();
|
|
65
|
+
const page = pages.get(relativePath);
|
|
66
|
+
if (!page) {
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
const newPage = parsePageFromString_1.default(page, fs_1.default.readFileSync(filePath, "utf-8"));
|
|
70
|
+
return this.merge({
|
|
71
|
+
pages: pages.set(relativePath, newPage),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
Get root folder for output
|
|
76
|
+
|
|
77
|
+
@return {string}
|
|
78
|
+
*/
|
|
79
|
+
getRoot() {
|
|
80
|
+
return this.getOptions().get("root");
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
Update state of output
|
|
84
|
+
|
|
85
|
+
@param {Map} newState
|
|
86
|
+
@return {Output}
|
|
87
|
+
*/
|
|
88
|
+
setState(newState) {
|
|
89
|
+
return this.set("state", newState);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
Update options
|
|
93
|
+
|
|
94
|
+
@param {Map} newOptions
|
|
95
|
+
@return {Output}
|
|
96
|
+
*/
|
|
97
|
+
setOptions(newOptions) {
|
|
98
|
+
return this.set("options", newOptions);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
Return logegr for this output (same as book)
|
|
102
|
+
|
|
103
|
+
@return {Logger}
|
|
104
|
+
*/
|
|
105
|
+
getLogger() {
|
|
106
|
+
return this.getBook().getLogger();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.default = Output;
|
|
@@ -0,0 +1,91 @@
|
|
|
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 js_yaml_1 = __importDefault(require("js-yaml"));
|
|
8
|
+
const file_1 = __importDefault(require("./file"));
|
|
9
|
+
const hash_1 = require("./hash");
|
|
10
|
+
class Page extends immutable_1.default.Record({
|
|
11
|
+
file: new file_1.default(),
|
|
12
|
+
// Attributes extracted from the YAML header
|
|
13
|
+
attributes: immutable_1.default.Map(),
|
|
14
|
+
// Content of the page
|
|
15
|
+
content: String(),
|
|
16
|
+
// Direction of the text
|
|
17
|
+
dir: String("ltr"),
|
|
18
|
+
}) {
|
|
19
|
+
getFile() {
|
|
20
|
+
return this.get("file");
|
|
21
|
+
}
|
|
22
|
+
getAttributes() {
|
|
23
|
+
return this.get("attributes");
|
|
24
|
+
}
|
|
25
|
+
getContent() {
|
|
26
|
+
return this.get("content");
|
|
27
|
+
}
|
|
28
|
+
getDir() {
|
|
29
|
+
return this.get("dir");
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Return page as text
|
|
33
|
+
* @return {string}
|
|
34
|
+
*/
|
|
35
|
+
toText() {
|
|
36
|
+
const attrs = this.getAttributes();
|
|
37
|
+
const content = this.getContent();
|
|
38
|
+
if (attrs.size === 0) {
|
|
39
|
+
return content;
|
|
40
|
+
}
|
|
41
|
+
const frontMatter = `---\n${js_yaml_1.default.safeDump(attrs.toJS(), { skipInvalid: true })}---\n\n`;
|
|
42
|
+
return frontMatter + (content || "");
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Return path of the page
|
|
46
|
+
* @return {string}
|
|
47
|
+
*/
|
|
48
|
+
getPath() {
|
|
49
|
+
return this.getFile().getPath();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create a page for a file
|
|
53
|
+
* @param {File} file
|
|
54
|
+
* @return {Page}
|
|
55
|
+
*/
|
|
56
|
+
static createForFile(file) {
|
|
57
|
+
return new Page({
|
|
58
|
+
file: file,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Load a page for a file
|
|
63
|
+
* @param {File} file
|
|
64
|
+
* @param {string} content
|
|
65
|
+
* @return {Page}
|
|
66
|
+
*/
|
|
67
|
+
static loadFile(file, content) {
|
|
68
|
+
return new Page({
|
|
69
|
+
file: file,
|
|
70
|
+
content: content,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
static fromJSON(json) {
|
|
74
|
+
return new Page({
|
|
75
|
+
file: new file_1.default(json.file),
|
|
76
|
+
// Attributes extracted from the YAML header
|
|
77
|
+
attributes: immutable_1.default.Map(json.atributes),
|
|
78
|
+
// Content of the page
|
|
79
|
+
content: json.content,
|
|
80
|
+
// Direction of the text
|
|
81
|
+
dir: json.dir,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
static toJSON(page) {
|
|
85
|
+
return page.toJS();
|
|
86
|
+
}
|
|
87
|
+
hash() {
|
|
88
|
+
return hash_1.hashString(JSON.stringify(this.toJS()));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.default = Page;
|