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.
Files changed (278) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +10 -0
  3. package/bin/honkit.js +8 -0
  4. package/lib/BuildGenerator.js +2 -0
  5. package/lib/__tests__/__fixtures__/honkit/book.js +9 -0
  6. package/lib/__tests__/githon.js +11 -0
  7. package/lib/__tests__/init.js +19 -0
  8. package/lib/__tests__/snapshot-honkit.js +45 -0
  9. package/lib/api/decodeConfig.js +17 -0
  10. package/lib/api/decodeGlobal.js +21 -0
  11. package/lib/api/decodePage.js +41 -0
  12. package/lib/api/deprecate.js +113 -0
  13. package/lib/api/encodeConfig.js +30 -0
  14. package/lib/api/encodeGlobal.js +226 -0
  15. package/lib/api/encodeNavigation.js +60 -0
  16. package/lib/api/encodePage.js +37 -0
  17. package/lib/api/encodeProgress.js +58 -0
  18. package/lib/api/encodeSummary.js +52 -0
  19. package/lib/api/index.js +15 -0
  20. package/lib/bin.js +46 -0
  21. package/lib/browser.js +41 -0
  22. package/lib/cli/build.js +36 -0
  23. package/lib/cli/buildEbook.js +63 -0
  24. package/lib/cli/getBook.js +24 -0
  25. package/lib/cli/getOutputFolder.js +19 -0
  26. package/lib/cli/index.js +11 -0
  27. package/lib/cli/init.js +17 -0
  28. package/lib/cli/options.js +38 -0
  29. package/lib/cli/parse.js +65 -0
  30. package/lib/cli/serve.js +184 -0
  31. package/lib/cli/server.js +116 -0
  32. package/lib/cli/watch.js +35 -0
  33. package/lib/constants/__tests__/configSchema.js +41 -0
  34. package/lib/constants/configDefault.js +9 -0
  35. package/lib/constants/configFiles.js +3 -0
  36. package/lib/constants/configSchema.js +235 -0
  37. package/lib/constants/defaultBlocks.js +48 -0
  38. package/lib/constants/defaultFilters.js +18 -0
  39. package/lib/constants/defaultPlugins.js +20 -0
  40. package/lib/constants/extsAsciidoc.js +3 -0
  41. package/lib/constants/extsMarkdown.js +3 -0
  42. package/lib/constants/ignoreFiles.js +3 -0
  43. package/lib/constants/pluginAssetsFolder.js +3 -0
  44. package/lib/constants/pluginHooks.js +3 -0
  45. package/lib/constants/pluginPrefix.js +3 -0
  46. package/lib/constants/pluginResources.js +7 -0
  47. package/lib/constants/templatesFolder.js +3 -0
  48. package/lib/constants/themePrefix.js +3 -0
  49. package/lib/fs/__tests__/mock.js +68 -0
  50. package/lib/fs/mock.js +88 -0
  51. package/lib/fs/node.js +44 -0
  52. package/lib/honkit.js +34 -0
  53. package/lib/index.js +17 -0
  54. package/lib/init.js +79 -0
  55. package/lib/json/encodeBook.js +41 -0
  56. package/lib/json/encodeBookWithPage.js +25 -0
  57. package/lib/json/encodeFile.js +20 -0
  58. package/lib/json/encodeGlossary.js +22 -0
  59. package/lib/json/encodeGlossaryEntry.js +16 -0
  60. package/lib/json/encodeLanguages.js +29 -0
  61. package/lib/json/encodeOutput.js +26 -0
  62. package/lib/json/encodeOutputWithPage.js +26 -0
  63. package/lib/json/encodePage.js +38 -0
  64. package/lib/json/encodeReadme.js +19 -0
  65. package/lib/json/encodeSummary.js +22 -0
  66. package/lib/json/encodeSummaryArticle.js +25 -0
  67. package/lib/json/encodeSummaryPart.js +19 -0
  68. package/lib/json/index.js +27 -0
  69. package/lib/models/__tests__/config.js +164 -0
  70. package/lib/models/__tests__/glossary.js +38 -0
  71. package/lib/models/__tests__/glossaryEntry.js +16 -0
  72. package/lib/models/__tests__/page.js +26 -0
  73. package/lib/models/__tests__/plugin.js +26 -0
  74. package/lib/models/__tests__/pluginDependency.js +71 -0
  75. package/lib/models/__tests__/summary.js +115 -0
  76. package/lib/models/__tests__/summaryArticle.js +62 -0
  77. package/lib/models/__tests__/summaryPart.js +24 -0
  78. package/lib/models/__tests__/templateBlock.js +172 -0
  79. package/lib/models/__tests__/templateEngine.js +49 -0
  80. package/lib/models/book.js +312 -0
  81. package/lib/models/config.js +152 -0
  82. package/lib/models/file.js +83 -0
  83. package/lib/models/fs.js +255 -0
  84. package/lib/models/glossary.js +90 -0
  85. package/lib/models/glossaryEntry.js +34 -0
  86. package/lib/models/hash.js +191 -0
  87. package/lib/models/ignore.js +40 -0
  88. package/lib/models/language.js +22 -0
  89. package/lib/models/languages.js +64 -0
  90. package/lib/models/output.js +109 -0
  91. package/lib/models/page.js +91 -0
  92. package/lib/models/parser.js +102 -0
  93. package/lib/models/plugin.js +139 -0
  94. package/lib/models/pluginDependency.js +192 -0
  95. package/lib/models/readme.js +38 -0
  96. package/lib/models/summary.js +199 -0
  97. package/lib/models/summaryArticle.js +169 -0
  98. package/lib/models/summaryPart.js +53 -0
  99. package/lib/models/templateBlock.js +230 -0
  100. package/lib/models/templateEngine.js +115 -0
  101. package/lib/models/templateOutput.js +36 -0
  102. package/lib/models/templateShortcut.js +65 -0
  103. package/lib/modifiers/config/__tests__/addPlugin.js +30 -0
  104. package/lib/modifiers/config/__tests__/removePlugin.js +29 -0
  105. package/lib/modifiers/config/__tests__/togglePlugin.js +28 -0
  106. package/lib/modifiers/config/addPlugin.js +27 -0
  107. package/lib/modifiers/config/editPlugin.js +13 -0
  108. package/lib/modifiers/config/getPluginConfig.js +22 -0
  109. package/lib/modifiers/config/hasPlugin.js +15 -0
  110. package/lib/modifiers/config/index.js +21 -0
  111. package/lib/modifiers/config/isDefaultPlugin.js +17 -0
  112. package/lib/modifiers/config/removePlugin.js +27 -0
  113. package/lib/modifiers/config/togglePlugin.js +32 -0
  114. package/lib/modifiers/index.js +11 -0
  115. package/lib/modifiers/summary/__tests__/editPartTitle.js +41 -0
  116. package/lib/modifiers/summary/__tests__/insertArticle.js +72 -0
  117. package/lib/modifiers/summary/__tests__/insertPart.js +56 -0
  118. package/lib/modifiers/summary/__tests__/mergeAtLevel.js +45 -0
  119. package/lib/modifiers/summary/__tests__/moveArticle.js +66 -0
  120. package/lib/modifiers/summary/__tests__/moveArticleAfter.js +75 -0
  121. package/lib/modifiers/summary/__tests__/removeArticle.js +54 -0
  122. package/lib/modifiers/summary/editArticleRef.js +20 -0
  123. package/lib/modifiers/summary/editArticleTitle.js +20 -0
  124. package/lib/modifiers/summary/editPartTitle.js +21 -0
  125. package/lib/modifiers/summary/index.js +27 -0
  126. package/lib/modifiers/summary/indexArticleLevels.js +21 -0
  127. package/lib/modifiers/summary/indexLevels.js +18 -0
  128. package/lib/modifiers/summary/indexPartLevels.js +25 -0
  129. package/lib/modifiers/summary/insertArticle.js +47 -0
  130. package/lib/modifiers/summary/insertPart.js +21 -0
  131. package/lib/modifiers/summary/mergeAtLevel.js +68 -0
  132. package/lib/modifiers/summary/moveArticle.js +27 -0
  133. package/lib/modifiers/summary/moveArticleAfter.js +59 -0
  134. package/lib/modifiers/summary/removeArticle.js +36 -0
  135. package/lib/modifiers/summary/removePart.js +18 -0
  136. package/lib/modifiers/summary/unshiftArticle.js +27 -0
  137. package/lib/output/__tests__/ebook.js +17 -0
  138. package/lib/output/__tests__/json.js +43 -0
  139. package/lib/output/__tests__/plugin-hooks.js +57 -0
  140. package/lib/output/__tests__/website.js +121 -0
  141. package/lib/output/callHook.js +51 -0
  142. package/lib/output/callPageHook.js +23 -0
  143. package/lib/output/createTemplateEngine.js +42 -0
  144. package/lib/output/ebook/getConvertOptions.js +69 -0
  145. package/lib/output/ebook/getCoverPath.js +30 -0
  146. package/lib/output/ebook/getPDFTemplate.js +40 -0
  147. package/lib/output/ebook/index.js +16 -0
  148. package/lib/output/ebook/onFinish.js +84 -0
  149. package/lib/output/ebook/onPage.js +23 -0
  150. package/lib/output/ebook/options.js +17 -0
  151. package/lib/output/generateAssets.js +26 -0
  152. package/lib/output/generateBook.js +167 -0
  153. package/lib/output/generatePage.js +90 -0
  154. package/lib/output/generatePages.js +52 -0
  155. package/lib/output/getModifiers.js +63 -0
  156. package/lib/output/helper/fileToOutput.js +30 -0
  157. package/lib/output/helper/fileToURL.js +30 -0
  158. package/lib/output/helper/index.js +3 -0
  159. package/lib/output/helper/resolveFileToURL.js +25 -0
  160. package/lib/output/helper/writeFile.js +26 -0
  161. package/lib/output/index.js +27 -0
  162. package/lib/output/json/index.js +14 -0
  163. package/lib/output/json/onFinish.js +39 -0
  164. package/lib/output/json/onPage.js +37 -0
  165. package/lib/output/json/options.js +11 -0
  166. package/lib/output/modifiers/__tests__/addHeadingId.js +23 -0
  167. package/lib/output/modifiers/__tests__/annotateText.js +39 -0
  168. package/lib/output/modifiers/__tests__/fetchRemoteImages.js +32 -0
  169. package/lib/output/modifiers/__tests__/highlightCode.js +48 -0
  170. package/lib/output/modifiers/__tests__/inlinePng.js +22 -0
  171. package/lib/output/modifiers/__tests__/inlineSvg.js +42 -0
  172. package/lib/output/modifiers/__tests__/resolveImages.js +39 -0
  173. package/lib/output/modifiers/__tests__/resolveLinks.js +81 -0
  174. package/lib/output/modifiers/__tests__/svgToImg.js +29 -0
  175. package/lib/output/modifiers/addHeadingId.js +26 -0
  176. package/lib/output/modifiers/annotateText.js +76 -0
  177. package/lib/output/modifiers/editHTMLElement.js +17 -0
  178. package/lib/output/modifiers/fetchRemoteImages.js +42 -0
  179. package/lib/output/modifiers/highlightCode.js +59 -0
  180. package/lib/output/modifiers/index.js +26 -0
  181. package/lib/output/modifiers/inlineAssets.js +29 -0
  182. package/lib/output/modifiers/inlinePng.js +43 -0
  183. package/lib/output/modifiers/inlineSvg.js +39 -0
  184. package/lib/output/modifiers/modifyHTML.js +27 -0
  185. package/lib/output/modifiers/resolveImages.js +30 -0
  186. package/lib/output/modifiers/resolveLinks.js +46 -0
  187. package/lib/output/modifiers/svgToImg.js +58 -0
  188. package/lib/output/page-cache.js +15 -0
  189. package/lib/output/prepareAssets.js +22 -0
  190. package/lib/output/preparePages.js +25 -0
  191. package/lib/output/preparePlugins.js +36 -0
  192. package/lib/output/testing/createMock.js +39 -0
  193. package/lib/output/testing/generateMock.js +55 -0
  194. package/lib/output/website/__tests__/i18n.js +40 -0
  195. package/lib/output/website/copyPluginAssets.js +92 -0
  196. package/lib/output/website/createTemplateEngine.js +136 -0
  197. package/lib/output/website/index.js +22 -0
  198. package/lib/output/website/listSearchPaths.js +20 -0
  199. package/lib/output/website/onAsset.js +29 -0
  200. package/lib/output/website/onFinish.js +35 -0
  201. package/lib/output/website/onInit.js +19 -0
  202. package/lib/output/website/onPage.js +73 -0
  203. package/lib/output/website/options.js +15 -0
  204. package/lib/output/website/prepareI18n.js +28 -0
  205. package/lib/output/website/prepareResources.js +49 -0
  206. package/lib/output/website/state.js +20 -0
  207. package/lib/parse/__tests__/listAssets.js +63 -0
  208. package/lib/parse/__tests__/parseBook.js +77 -0
  209. package/lib/parse/__tests__/parseGlossary.js +32 -0
  210. package/lib/parse/__tests__/parseIgnore.js +37 -0
  211. package/lib/parse/__tests__/parsePageFromString.js +34 -0
  212. package/lib/parse/__tests__/parseReadme.js +33 -0
  213. package/lib/parse/__tests__/parseSummary.js +30 -0
  214. package/lib/parse/findParsableFile.js +33 -0
  215. package/lib/parse/index.js +31 -0
  216. package/lib/parse/listAssets.js +36 -0
  217. package/lib/parse/lookupStructureFile.js +21 -0
  218. package/lib/parse/parseBook.js +68 -0
  219. package/lib/parse/parseConfig.js +52 -0
  220. package/lib/parse/parseGlossary.js +25 -0
  221. package/lib/parse/parseIgnore.js +43 -0
  222. package/lib/parse/parseLanguages.js +26 -0
  223. package/lib/parse/parsePage.js +21 -0
  224. package/lib/parse/parsePageFromString.js +25 -0
  225. package/lib/parse/parsePagesList.js +80 -0
  226. package/lib/parse/parseReadme.js +26 -0
  227. package/lib/parse/parseStructureFile.js +64 -0
  228. package/lib/parse/parseSummary.js +43 -0
  229. package/lib/parse/validateConfig.js +31 -0
  230. package/lib/parse/walkSummary.js +34 -0
  231. package/lib/parsers.js +60 -0
  232. package/lib/plugins/PluginResolver.js +84 -0
  233. package/lib/plugins/__tests__/findInstalled.js +25 -0
  234. package/lib/plugins/__tests__/listDependencies.js +28 -0
  235. package/lib/plugins/__tests__/sortDependencies.js +28 -0
  236. package/lib/plugins/__tests__/validatePlugin.js +99 -0
  237. package/lib/plugins/findInstalled.js +87 -0
  238. package/lib/plugins/index.js +17 -0
  239. package/lib/plugins/listBlocks.js +19 -0
  240. package/lib/plugins/listDependencies.js +33 -0
  241. package/lib/plugins/listDepsForBook.js +20 -0
  242. package/lib/plugins/listFilters.js +18 -0
  243. package/lib/plugins/listResources.js +44 -0
  244. package/lib/plugins/loadForBook.js +38 -0
  245. package/lib/plugins/loadPlugin.js +89 -0
  246. package/lib/plugins/package-name-util.js +48 -0
  247. package/lib/plugins/sortDependencies.js +30 -0
  248. package/lib/plugins/toNames.js +16 -0
  249. package/lib/plugins/validateConfig.js +60 -0
  250. package/lib/plugins/validatePlugin.js +36 -0
  251. package/lib/templating/__tests__/conrefsLoader.js +93 -0
  252. package/lib/templating/__tests__/postRender.js +52 -0
  253. package/lib/templating/__tests__/replaceShortcuts.js +27 -0
  254. package/lib/templating/conrefsLoader.js +88 -0
  255. package/lib/templating/index.js +19 -0
  256. package/lib/templating/listShortcuts.js +29 -0
  257. package/lib/templating/postRender.js +46 -0
  258. package/lib/templating/render.js +41 -0
  259. package/lib/templating/renderFile.js +39 -0
  260. package/lib/templating/replaceShortcuts.js +36 -0
  261. package/lib/templating/themesLoader.js +98 -0
  262. package/lib/utils/__tests__/git.js +47 -0
  263. package/lib/utils/__tests__/location.js +81 -0
  264. package/lib/utils/__tests__/path.js +19 -0
  265. package/lib/utils/command.js +104 -0
  266. package/lib/utils/error.js +88 -0
  267. package/lib/utils/fs.js +163 -0
  268. package/lib/utils/genKey.js +13 -0
  269. package/lib/utils/git.js +116 -0
  270. package/lib/utils/images.js +22 -0
  271. package/lib/utils/location.js +129 -0
  272. package/lib/utils/logger.js +158 -0
  273. package/lib/utils/mergeDefaults.js +18 -0
  274. package/lib/utils/path.js +62 -0
  275. package/lib/utils/promise.js +142 -0
  276. package/lib/utils/reducedObject.js +31 -0
  277. package/lib/utils/timing.js +90 -0
  278. package/package.json +112 -0
@@ -0,0 +1,38 @@
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 file_1 = __importDefault(require("../file"));
7
+ const glossary_1 = __importDefault(require("../glossary"));
8
+ const glossaryEntry_1 = __importDefault(require("../glossaryEntry"));
9
+ describe("Glossary", () => {
10
+ const glossary = glossary_1.default.createFromEntries(new file_1.default(), [
11
+ {
12
+ name: "Hello World",
13
+ description: "Awesome!",
14
+ },
15
+ {
16
+ name: "JavaScript",
17
+ description: "This is a cool language",
18
+ },
19
+ ]);
20
+ describe("createFromEntries", () => {
21
+ test("must add all entries", () => {
22
+ const entries = glossary.getEntries();
23
+ expect(entries.size).toBe(2);
24
+ });
25
+ test("must add entries as GlossaryEntries", () => {
26
+ const entries = glossary.getEntries();
27
+ const entry = entries.get("hello-world");
28
+ expect(entry instanceof glossaryEntry_1.default).toBeTruthy();
29
+ });
30
+ });
31
+ describe("toText", () => {
32
+ test("return as markdown", () => {
33
+ return glossary.toText(".md").then((text) => {
34
+ expect(text).toContain("# Glossary");
35
+ });
36
+ });
37
+ });
38
+ });
@@ -0,0 +1,16 @@
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 glossaryEntry_1 = __importDefault(require("../glossaryEntry"));
7
+ describe("GlossaryEntry", () => {
8
+ describe("getID", () => {
9
+ test("must return a normalized ID", () => {
10
+ const entry = new glossaryEntry_1.default({
11
+ name: "Hello World",
12
+ });
13
+ expect(entry.getID()).toBe("hello-world");
14
+ });
15
+ });
16
+ });
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const immutable_1 = __importDefault(require("immutable"));
7
+ const page_1 = __importDefault(require("../page"));
8
+ describe("Page", () => {
9
+ describe("toText", () => {
10
+ test("must not prepend frontmatter if no attributes", () => {
11
+ const page = new page_1.default().merge({
12
+ content: "Hello World",
13
+ });
14
+ expect(page.toText()).toBe("Hello World");
15
+ });
16
+ test("must prepend frontmatter if attributes", () => {
17
+ const page = new page_1.default().merge({
18
+ content: "Hello World",
19
+ attributes: immutable_1.default.fromJS({
20
+ hello: "world",
21
+ }),
22
+ });
23
+ expect(page.toText()).toBe("---\nhello: world\n---\n\nHello World");
24
+ });
25
+ });
26
+ });
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const plugin_1 = __importDefault(require("../plugin"));
7
+ describe("Plugin", () => {
8
+ describe("createFromString", () => {
9
+ test("must parse name", () => {
10
+ const plugin = plugin_1.default.createFromString("hello");
11
+ expect(plugin.getName()).toBe("hello");
12
+ expect(plugin.getVersion()).toBe("*");
13
+ });
14
+ test("must parse version", () => {
15
+ const plugin = plugin_1.default.createFromString("hello@1.0.0");
16
+ expect(plugin.getName()).toBe("hello");
17
+ expect(plugin.getVersion()).toBe("1.0.0");
18
+ });
19
+ });
20
+ describe("isLoaded", () => {
21
+ test("must return false for empty plugin", () => {
22
+ const plugin = plugin_1.default.createFromString("hello");
23
+ expect(plugin.isLoaded()).toBe(false);
24
+ });
25
+ });
26
+ });
@@ -0,0 +1,71 @@
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 pluginDependency_1 = __importDefault(require("../pluginDependency"));
8
+ describe("PluginDependency", () => {
9
+ describe("createFromString", () => {
10
+ test("must parse name", () => {
11
+ const plugin = pluginDependency_1.default.createFromString("hello");
12
+ expect(plugin.getName()).toBe("hello");
13
+ expect(plugin.getVersion()).toBe("*");
14
+ });
15
+ test("must parse state", () => {
16
+ const plugin = pluginDependency_1.default.createFromString("-hello");
17
+ expect(plugin.getName()).toBe("hello");
18
+ expect(plugin.isEnabled()).toBe(false);
19
+ });
20
+ describe("Version", () => {
21
+ test("must parse version", () => {
22
+ const plugin = pluginDependency_1.default.createFromString("hello@1.0.0");
23
+ expect(plugin.getName()).toBe("hello");
24
+ expect(plugin.getVersion()).toBe("1.0.0");
25
+ });
26
+ test("must parse semver", () => {
27
+ const plugin = pluginDependency_1.default.createFromString("hello@>=4.0.0");
28
+ expect(plugin.getName()).toBe("hello");
29
+ expect(plugin.getVersion()).toBe(">=4.0.0");
30
+ });
31
+ });
32
+ describe("GIT Version", () => {
33
+ test("must handle HTTPS urls", () => {
34
+ const plugin = pluginDependency_1.default.createFromString("hello@git+https://github.com/GitbookIO/plugin-ga.git");
35
+ expect(plugin.getName()).toBe("hello");
36
+ expect(plugin.getVersion()).toBe("git+https://github.com/GitbookIO/plugin-ga.git");
37
+ });
38
+ test("must handle SSH urls", () => {
39
+ const plugin = pluginDependency_1.default.createFromString("hello@git+ssh://samy@github.com/GitbookIO/plugin-ga.git");
40
+ expect(plugin.getName()).toBe("hello");
41
+ expect(plugin.getVersion()).toBe("git+ssh://samy@github.com/GitbookIO/plugin-ga.git");
42
+ });
43
+ });
44
+ describe("listToArray", () => {
45
+ test("must create an array from a list of plugin dependencies", () => {
46
+ const list = pluginDependency_1.default.listToArray(immutable_1.default.List([
47
+ pluginDependency_1.default.createFromString("hello@1.0.0"),
48
+ pluginDependency_1.default.createFromString("noversion"),
49
+ pluginDependency_1.default.createFromString("-disabled"),
50
+ ]));
51
+ expect(list).toEqual(["hello@1.0.0", "noversion", "-disabled"]);
52
+ });
53
+ });
54
+ describe("listFromArray", () => {
55
+ test("must create an array from a list of plugin dependencies", () => {
56
+ const arr = immutable_1.default.fromJS([
57
+ "hello@1.0.0",
58
+ {
59
+ name: "plugin-ga",
60
+ version: "git+ssh://samy@github.com/GitbookIO/plugin-ga.git",
61
+ },
62
+ ]);
63
+ const list = pluginDependency_1.default.listFromArray(arr);
64
+ expect(list.first().getName()).toBe("hello");
65
+ expect(list.first().getVersion()).toBe("1.0.0");
66
+ expect(list.last().getName()).toBe("plugin-ga");
67
+ expect(list.last().getVersion()).toBe("git+ssh://samy@github.com/GitbookIO/plugin-ga.git");
68
+ });
69
+ });
70
+ });
71
+ });
@@ -0,0 +1,115 @@
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 summary_1 = __importDefault(require("../summary"));
7
+ const file_1 = __importDefault(require("../file"));
8
+ describe("Summary", () => {
9
+ const summary = summary_1.default.createFromParts(new file_1.default(), [
10
+ {
11
+ articles: [
12
+ // 1.1
13
+ {
14
+ title: "My First Article",
15
+ ref: "README.md",
16
+ },
17
+ // 1.2
18
+ {
19
+ title: "My Second Article",
20
+ ref: "article.md",
21
+ },
22
+ // 1.3
23
+ {
24
+ title: "My Third Article with anchor",
25
+ ref: "article-anchor.md",
26
+ articles: [
27
+ {
28
+ title: "Article with anchor",
29
+ ref: "article-anchor.md#anchor",
30
+ },
31
+ ],
32
+ },
33
+ // 1.4
34
+ {
35
+ title: "Article without ref",
36
+ },
37
+ // 1.5
38
+ {
39
+ title: "Article with absolute ref",
40
+ ref: "https://google.fr",
41
+ },
42
+ ],
43
+ },
44
+ {
45
+ title: "Test",
46
+ },
47
+ ]);
48
+ describe("createFromEntries", () => {
49
+ test("must add all parts", () => {
50
+ const parts = summary.getParts();
51
+ expect(parts.size).toBe(2);
52
+ });
53
+ });
54
+ describe("getNextArticle", () => {
55
+ it("return next article", () => {
56
+ const nextArticle = summary.getNextArticle("1.1");
57
+ expect(nextArticle.getLevel()).toBe("1.2");
58
+ });
59
+ it("ignore anchor article", () => {
60
+ const nextArticle = summary.getNextArticle("1.3"); // next is anchor
61
+ expect(nextArticle.getLevel()).toBe("1.4");
62
+ });
63
+ });
64
+ describe("getPrevArticle", () => {
65
+ it("return prev article", () => {
66
+ const prevArticle = summary.getPrevArticle("1.2");
67
+ expect(prevArticle.getLevel()).toBe("1.1");
68
+ });
69
+ it("ignore anchor article", () => {
70
+ const prevArticle = summary.getPrevArticle("1.4");
71
+ expect(prevArticle.getLevel()).toBe("1.3");
72
+ });
73
+ });
74
+ describe("getByLevel", () => {
75
+ test("can return a Part", () => {
76
+ const part = summary.getByLevel("1");
77
+ expect(part).toBeDefined();
78
+ expect(part.getArticles().size).toBe(5);
79
+ });
80
+ test("can return a Part (2)", () => {
81
+ const part = summary.getByLevel("2");
82
+ expect(part).toBeDefined();
83
+ expect(part.getTitle()).toBe("Test");
84
+ expect(part.getArticles().size).toBe(0);
85
+ });
86
+ test("can return an Article", () => {
87
+ const article = summary.getByLevel("1.1");
88
+ expect(article).toBeDefined();
89
+ expect(article.getTitle()).toBe("My First Article");
90
+ });
91
+ });
92
+ describe("getByPath", () => {
93
+ test("return correct article", () => {
94
+ const article = summary.getByPath("README.md");
95
+ expect(article).toBeDefined();
96
+ expect(article.getTitle()).toBe("My First Article");
97
+ });
98
+ test("return correct article", () => {
99
+ const article = summary.getByPath("article.md");
100
+ expect(article).toBeDefined();
101
+ expect(article.getTitle()).toBe("My Second Article");
102
+ });
103
+ test("return undefined if not found", () => {
104
+ const article = summary.getByPath("NOT_EXISTING.md");
105
+ expect(article).toBeFalsy();
106
+ });
107
+ });
108
+ describe("toText", () => {
109
+ test("return as markdown", () => {
110
+ return summary.toText(".md").then((text) => {
111
+ expect(text).toContain("# Summary");
112
+ });
113
+ });
114
+ });
115
+ });
@@ -0,0 +1,62 @@
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 summaryArticle_1 = __importDefault(require("../summaryArticle"));
7
+ const file_1 = __importDefault(require("../file"));
8
+ describe("SummaryArticle", () => {
9
+ describe("createChildLevel", () => {
10
+ test("must create the right level", () => {
11
+ const article = summaryArticle_1.default.create({}, "1.1");
12
+ expect(article.createChildLevel()).toBe("1.1.1");
13
+ });
14
+ test("must create the right level when has articles", () => {
15
+ const article = summaryArticle_1.default.create({
16
+ articles: [
17
+ {
18
+ title: "Test",
19
+ },
20
+ ],
21
+ }, "1.1");
22
+ expect(article.createChildLevel()).toBe("1.1.2");
23
+ });
24
+ });
25
+ describe("isFile", () => {
26
+ test("must return true when exactly the file", () => {
27
+ const article = summaryArticle_1.default.create({
28
+ ref: "hello.md",
29
+ }, "1.1");
30
+ const file = file_1.default.createWithFilepath("hello.md");
31
+ expect(article.isFile(file)).toBe(true);
32
+ });
33
+ test("must return true when path is not normalized", () => {
34
+ const article = summaryArticle_1.default.create({
35
+ ref: "/hello.md",
36
+ }, "1.1");
37
+ const file = file_1.default.createWithFilepath("hello.md");
38
+ expect(article.isFile(file)).toBe(true);
39
+ });
40
+ test("must return false when has anchor", () => {
41
+ const article = summaryArticle_1.default.create({
42
+ ref: "hello.md#world",
43
+ }, "1.1");
44
+ const file = file_1.default.createWithFilepath("hello.md");
45
+ expect(article.isFile(file)).toBe(false);
46
+ });
47
+ });
48
+ describe("hasAnchor", function () {
49
+ it("must return false when ref does not have anchor", function () {
50
+ var article = summaryArticle_1.default.create({
51
+ ref: "hello.md",
52
+ }, "1.1");
53
+ expect(article.hasAnchor()).toBe(false);
54
+ });
55
+ it("must return true when has anchor", function () {
56
+ var article = summaryArticle_1.default.create({
57
+ ref: "hello.md#world",
58
+ }, "1.1");
59
+ expect(article.hasAnchor()).toBe(true);
60
+ });
61
+ });
62
+ });
@@ -0,0 +1,24 @@
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("../summaryPart"));
7
+ describe("SummaryPart", () => {
8
+ describe("createChildLevel", () => {
9
+ test("must create the right level", () => {
10
+ const article = summaryPart_1.default.create({}, "1");
11
+ expect(article.createChildLevel()).toBe("1.1");
12
+ });
13
+ test("must create the right level when has articles", () => {
14
+ const article = summaryPart_1.default.create({
15
+ articles: [
16
+ {
17
+ title: "Test",
18
+ },
19
+ ],
20
+ }, "1");
21
+ expect(article.createChildLevel()).toBe("1.2");
22
+ });
23
+ });
24
+ });
@@ -0,0 +1,172 @@
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 nunjucks_1 = __importDefault(require("nunjucks"));
7
+ const immutable_1 = __importDefault(require("immutable"));
8
+ const promise_1 = __importDefault(require("../../utils/promise"));
9
+ const templateBlock_1 = __importDefault(require("../templateBlock"));
10
+ describe("TemplateBlock", () => {
11
+ describe("create", () => {
12
+ test("must initialize a simple TemplateBlock from a function", () => {
13
+ const templateBlock = templateBlock_1.default.create("sayhello", (block) => {
14
+ return {
15
+ body: "<p>Hello, World!</p>",
16
+ parse: true,
17
+ };
18
+ });
19
+ // Check basic templateBlock properties
20
+ expect(templateBlock.getName()).toBe("sayhello");
21
+ expect(templateBlock.getEndTag()).toBe("endsayhello");
22
+ expect(templateBlock.getBlocks().size).toBe(0);
23
+ expect(templateBlock.getExtensionName()).toBe("BlocksayhelloExtension");
24
+ // Check result of applying block
25
+ return promise_1.default()
26
+ .then(() => {
27
+ return templateBlock.applyBlock();
28
+ })
29
+ .then((result) => {
30
+ expect(result.name).toBe("sayhello");
31
+ expect(result.body).toBe("<p>Hello, World!</p>");
32
+ });
33
+ });
34
+ });
35
+ describe("getShortcuts", () => {
36
+ test("must return undefined if no shortcuts", () => {
37
+ const templateBlock = templateBlock_1.default.create("sayhello", (block) => {
38
+ return {
39
+ body: "<p>Hello, World!</p>",
40
+ parse: true,
41
+ };
42
+ });
43
+ expect(templateBlock.getShortcuts()).toBeFalsy();
44
+ });
45
+ test("must return complete shortcut", () => {
46
+ const templateBlock = templateBlock_1.default.create("sayhello", {
47
+ process: function (block) {
48
+ return "<p>Hello, World!</p>";
49
+ },
50
+ shortcuts: {
51
+ parsers: ["markdown"],
52
+ start: "$",
53
+ end: "-",
54
+ },
55
+ });
56
+ const shortcut = templateBlock.getShortcuts();
57
+ expect(shortcut).toBeDefined();
58
+ expect(shortcut.getStart()).toEqual("$");
59
+ expect(shortcut.getEnd()).toEqual("-");
60
+ expect(shortcut.getStartTag()).toEqual("sayhello");
61
+ expect(shortcut.getEndTag()).toEqual("endsayhello");
62
+ });
63
+ });
64
+ describe("toNunjucksExt()", () => {
65
+ test("should replace by block anchor", () => {
66
+ const templateBlock = templateBlock_1.default.create("sayhello", (block) => {
67
+ return "Hello";
68
+ });
69
+ let blocks = {};
70
+ // Create a fresh Nunjucks environment
71
+ const env = new nunjucks_1.default.Environment(null, { autoescape: false });
72
+ // Add template block to environement
73
+ const Ext = templateBlock.toNunjucksExt({}, blocks);
74
+ env.addExtension(templateBlock.getExtensionName(), new Ext());
75
+ // Render a template using the block
76
+ const src = "{% sayhello %}{% endsayhello %}";
77
+ return promise_1.default.nfcall(env.renderString.bind(env), src).then((res) => {
78
+ blocks = immutable_1.default.fromJS(blocks);
79
+ expect(blocks.size).toBe(1);
80
+ const blockId = blocks.keySeq().get(0);
81
+ const block = blocks.get(blockId);
82
+ expect(res).toBe(`{{-%${blockId}%-}}`);
83
+ expect(block.get("body")).toBe("Hello");
84
+ expect(block.get("name")).toBe("sayhello");
85
+ });
86
+ });
87
+ test("must create a valid nunjucks extension", () => {
88
+ const templateBlock = templateBlock_1.default.create("sayhello", (block) => {
89
+ return {
90
+ body: "<p>Hello, World!</p>",
91
+ parse: true,
92
+ };
93
+ });
94
+ // Create a fresh Nunjucks environment
95
+ const env = new nunjucks_1.default.Environment(null, { autoescape: false });
96
+ // Add template block to environement
97
+ const Ext = templateBlock.toNunjucksExt();
98
+ env.addExtension(templateBlock.getExtensionName(), new Ext());
99
+ // Render a template using the block
100
+ const src = "{% sayhello %}{% endsayhello %}";
101
+ return promise_1.default.nfcall(env.renderString.bind(env), src).then((res) => {
102
+ expect(res).toBe("<p>Hello, World!</p>");
103
+ });
104
+ });
105
+ test("must apply block arguments correctly", () => {
106
+ const templateBlock = templateBlock_1.default.create("sayhello", (block) => {
107
+ return {
108
+ body: `<${block.kwargs.tag}>Hello, ${block.kwargs.name}!</${block.kwargs.tag}>`,
109
+ parse: true,
110
+ };
111
+ });
112
+ // Create a fresh Nunjucks environment
113
+ const env = new nunjucks_1.default.Environment(null, { autoescape: false });
114
+ // Add template block to environement
115
+ const Ext = templateBlock.toNunjucksExt();
116
+ env.addExtension(templateBlock.getExtensionName(), new Ext());
117
+ // Render a template using the block
118
+ const src = '{% sayhello name="Samy", tag="p" %}{% endsayhello %}';
119
+ return promise_1.default.nfcall(env.renderString.bind(env), src).then((res) => {
120
+ expect(res).toBe("<p>Hello, Samy!</p>");
121
+ });
122
+ });
123
+ test("must accept an async function", () => {
124
+ const templateBlock = templateBlock_1.default.create("sayhello", (block) => {
125
+ return promise_1.default().then(() => {
126
+ return {
127
+ body: `Hello ${block.body}`,
128
+ parse: true,
129
+ };
130
+ });
131
+ });
132
+ // Create a fresh Nunjucks environment
133
+ const env = new nunjucks_1.default.Environment(null, { autoescape: false });
134
+ // Add template block to environement
135
+ const Ext = templateBlock.toNunjucksExt();
136
+ env.addExtension(templateBlock.getExtensionName(), new Ext());
137
+ // Render a template using the block
138
+ const src = "{% sayhello %}Samy{% endsayhello %}";
139
+ return promise_1.default.nfcall(env.renderString.bind(env), src).then((res) => {
140
+ expect(res).toBe("Hello Samy");
141
+ });
142
+ });
143
+ test("must handle nested blocks", () => {
144
+ const templateBlock = new templateBlock_1.default({
145
+ name: "yoda",
146
+ blocks: immutable_1.default.List(["start", "end"]),
147
+ process: function (block) {
148
+ const nested = {};
149
+ block.blocks.forEach((blk) => {
150
+ nested[blk.name] = blk.body.trim();
151
+ });
152
+ return {
153
+ body: `<p class="yoda">${nested.end} ${nested.start}</p>`,
154
+ parse: true,
155
+ };
156
+ },
157
+ });
158
+ // Create a fresh Nunjucks environment
159
+ const env = new nunjucks_1.default.Environment(null, { autoescape: false });
160
+ // Add template block to environement
161
+ // @ts-expect-error ts-migrate(2339) FIXME: Property 'toNunjucksExt' does not exist on type 'M... Remove this comment to see the full error message
162
+ const Ext = templateBlock.toNunjucksExt();
163
+ // @ts-expect-error ts-migrate(2339) FIXME: Property 'getExtensionName' does not exist on type... Remove this comment to see the full error message
164
+ env.addExtension(templateBlock.getExtensionName(), new Ext());
165
+ // Render a template using the block
166
+ const src = "{% yoda %}{% start %}this sentence should be{% end %}inverted{% endyoda %}";
167
+ return promise_1.default.nfcall(env.renderString.bind(env), src).then((res) => {
168
+ expect(res).toBe('<p class="yoda">inverted this sentence should be</p>');
169
+ });
170
+ });
171
+ });
172
+ });