erudit 2.0.0-dev.7

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 (314) hide show
  1. package/.nuxtrc +1 -0
  2. package/app/app.vue +172 -0
  3. package/app/assets/icons/alert.svg +3 -0
  4. package/app/assets/icons/angle-right.svg +3 -0
  5. package/app/assets/icons/arrow-in-text.svg +3 -0
  6. package/app/assets/icons/arrow-left.svg +3 -0
  7. package/app/assets/icons/arrow-up-to-right.svg +3 -0
  8. package/app/assets/icons/aside-open.svg +3 -0
  9. package/app/assets/icons/asterisk.svg +3 -0
  10. package/app/assets/icons/book-question.svg +3 -0
  11. package/app/assets/icons/book.svg +3 -0
  12. package/app/assets/icons/bug.svg +3 -0
  13. package/app/assets/icons/chip.svg +3 -0
  14. package/app/assets/icons/circle-help.svg +3 -0
  15. package/app/assets/icons/construction.svg +3 -0
  16. package/app/assets/icons/cross.svg +3 -0
  17. package/app/assets/icons/draw.svg +3 -0
  18. package/app/assets/icons/ellipsis-vertical.svg +3 -0
  19. package/app/assets/icons/file-check.svg +3 -0
  20. package/app/assets/icons/file-lines.svg +3 -0
  21. package/app/assets/icons/file-star.svg +3 -0
  22. package/app/assets/icons/folder-open.svg +3 -0
  23. package/app/assets/icons/folder.svg +3 -0
  24. package/app/assets/icons/globe.svg +3 -0
  25. package/app/assets/icons/house.svg +3 -0
  26. package/app/assets/icons/link-external.svg +3 -0
  27. package/app/assets/icons/link.svg +3 -0
  28. package/app/assets/icons/moon.svg +3 -0
  29. package/app/assets/icons/outline/book.svg +3 -0
  30. package/app/assets/icons/outline/file-lines.svg +3 -0
  31. package/app/assets/icons/pirate.svg +3 -0
  32. package/app/assets/icons/plus-circle.svg +3 -0
  33. package/app/assets/icons/plus.svg +3 -0
  34. package/app/assets/icons/puzzle.svg +3 -0
  35. package/app/assets/icons/search.svg +3 -0
  36. package/app/assets/icons/shuffle.svg +3 -0
  37. package/app/assets/icons/star.svg +3 -0
  38. package/app/assets/icons/sun-moon.svg +3 -0
  39. package/app/assets/icons/sun.svg +3 -0
  40. package/app/assets/icons/user.svg +3 -0
  41. package/app/assets/icons/users.svg +3 -0
  42. package/app/components/Loading.vue +23 -0
  43. package/app/components/SiteAside.vue +382 -0
  44. package/app/components/SiteMain.vue +35 -0
  45. package/app/components/ads/BannerTemplate.vue +51 -0
  46. package/app/components/ads/BottomBanner.vue +45 -0
  47. package/app/components/ads/LeftBanner.vue +50 -0
  48. package/app/components/aside/AsideListItem.vue +74 -0
  49. package/app/components/aside/AsideMajor.vue +56 -0
  50. package/app/components/aside/AsideMinor.vue +71 -0
  51. package/app/components/aside/major/PaneContentScroll.vue +23 -0
  52. package/app/components/aside/major/PaneSwitch.vue +54 -0
  53. package/app/components/aside/major/PaneSwitchButton.vue +63 -0
  54. package/app/components/aside/major/SiteInfo.vue +85 -0
  55. package/app/components/aside/major/panes/Language.vue +79 -0
  56. package/app/components/aside/major/panes/Pages.vue +34 -0
  57. package/app/components/aside/major/panes/Search.vue +3 -0
  58. package/app/components/aside/major/panes/nav/Nav.vue +91 -0
  59. package/app/components/aside/major/panes/nav/NavBook.vue +86 -0
  60. package/app/components/aside/major/panes/nav/NavBookLoading.vue +24 -0
  61. package/app/components/aside/major/panes/nav/NavGlobal.vue +16 -0
  62. package/app/components/aside/major/panes/nav/fnav/FNav.vue +105 -0
  63. package/app/components/aside/major/panes/nav/fnav/FNavBook.vue +32 -0
  64. package/app/components/aside/major/panes/nav/fnav/FNavFlags.vue +40 -0
  65. package/app/components/aside/major/panes/nav/fnav/FNavFolder.vue +60 -0
  66. package/app/components/aside/major/panes/nav/fnav/FNavItem.vue +34 -0
  67. package/app/components/aside/major/panes/nav/fnav/FNavSeparator.vue +80 -0
  68. package/app/components/aside/major/panes/nav/fnav/FNavTopic.vue +24 -0
  69. package/app/components/aside/major/panes/other/ItemContent.vue +29 -0
  70. package/app/components/aside/major/panes/other/ItemGenerator.vue +15 -0
  71. package/app/components/aside/major/panes/other/ItemTheme.vue +54 -0
  72. package/app/components/aside/major/panes/other/Other.vue +16 -0
  73. package/app/components/aside/minor/AsideMinorContributor.vue +5 -0
  74. package/app/components/aside/minor/AsideMinorNews.vue +11 -0
  75. package/app/components/aside/minor/AsideMinorPane.vue +16 -0
  76. package/app/components/aside/minor/AsideMinorTopLink.vue +67 -0
  77. package/app/components/aside/minor/Contribute.vue +145 -0
  78. package/app/components/aside/minor/content/AsideMinorContent.vue +92 -0
  79. package/app/components/aside/minor/topic/AsideMinorTopic.vue +32 -0
  80. package/app/components/aside/minor/topic/TopicContributors.vue +177 -0
  81. package/app/components/aside/minor/topic/TopicNav.vue +49 -0
  82. package/app/components/aside/minor/topic/TopicToc.vue +202 -0
  83. package/app/components/aside/minor/topic/TopicTocItem.vue +31 -0
  84. package/app/components/aside/utils/AsideOverlayPane.vue +40 -0
  85. package/app/components/bitran/BitranContent.vue +64 -0
  86. package/app/components/bitran/RenderWrapper.vue +12 -0
  87. package/app/components/contributor/ContributorAvatar.vue +43 -0
  88. package/app/components/contributor/ContributorListItem.vue +35 -0
  89. package/app/components/main/topic/MainTopic.vue +79 -0
  90. package/app/components/main/topic/TopicPartSwitch.vue +118 -0
  91. package/app/components/main/utils/Breadcrumb.vue +75 -0
  92. package/app/components/main/utils/ContentDecoration.vue +29 -0
  93. package/app/components/main/utils/ContentDescription.vue +20 -0
  94. package/app/components/main/utils/ContentFlag.vue +16 -0
  95. package/app/components/main/utils/ContentPopover.vue +176 -0
  96. package/app/components/main/utils/ContentPopovers.vue +105 -0
  97. package/app/components/main/utils/ContentReferences.vue +76 -0
  98. package/app/components/main/utils/ContentSection.vue +42 -0
  99. package/app/components/main/utils/ContentTitle.vue +37 -0
  100. package/app/components/main/utils/reference/ReferenceGroup.vue +41 -0
  101. package/app/components/main/utils/reference/ReferenceItem.vue +64 -0
  102. package/app/components/main/utils/reference/ReferenceSource.vue +110 -0
  103. package/app/components/preview/Preview.vue +177 -0
  104. package/app/components/preview/PreviewDisplay.vue +139 -0
  105. package/app/components/preview/PreviewFooterAction.vue +73 -0
  106. package/app/components/preview/PreviewLoading.vue +15 -0
  107. package/app/components/preview/PreviewScreen.vue +99 -0
  108. package/app/components/preview/display/Alert.vue +50 -0
  109. package/app/components/preview/display/Custom.vue +18 -0
  110. package/app/components/preview/display/GenericLink.vue +48 -0
  111. package/app/components/preview/display/PageLink.vue +20 -0
  112. package/app/components/preview/display/Unique.vue +49 -0
  113. package/app/components/transition/Fade.vue +22 -0
  114. package/app/components/tree/TreeContainer.vue +12 -0
  115. package/app/components/tree/TreeItem.vue +89 -0
  116. package/app/composables/bitran.ts +132 -0
  117. package/app/composables/bitranContent.ts +36 -0
  118. package/app/composables/bitranLocation.ts +7 -0
  119. package/app/composables/contentData.ts +36 -0
  120. package/app/composables/contentPage.ts +156 -0
  121. package/app/composables/contentRoute.ts +45 -0
  122. package/app/composables/darkMagic.ts +24 -0
  123. package/app/composables/externalApi.ts +63 -0
  124. package/app/composables/favicon.ts +8 -0
  125. package/app/composables/formatText.ts +86 -0
  126. package/app/composables/majorPane.ts +60 -0
  127. package/app/composables/phrases.ts +80 -0
  128. package/app/composables/theme.ts +29 -0
  129. package/app/composables/url.ts +33 -0
  130. package/app/pages/_test/preview.vue +110 -0
  131. package/app/pages/article/[...articleId].vue +3 -0
  132. package/app/pages/book/[...bookId].vue +47 -0
  133. package/app/pages/group/[...groupId].vue +64 -0
  134. package/app/pages/index.vue +32 -0
  135. package/app/pages/members.vue +7 -0
  136. package/app/pages/practice/[...practice].vue +3 -0
  137. package/app/pages/summary/[...summaryId].vue +3 -0
  138. package/app/public/favicon/article.svg +10 -0
  139. package/app/public/favicon/default.svg +10 -0
  140. package/app/public/favicon/practice.svg +10 -0
  141. package/app/public/favicon/summary.svg +10 -0
  142. package/app/public/logotype.svg +17 -0
  143. package/app/public/og-default.png +0 -0
  144. package/app/public/user.svg +10 -0
  145. package/app/scripts/_immediate.js +4 -0
  146. package/app/scripts/aside/index.ts +59 -0
  147. package/app/scripts/aside/major/nav.ts +26 -0
  148. package/app/scripts/aside/minor/state.ts +37 -0
  149. package/app/scripts/aside/minor/topic.ts +3 -0
  150. package/app/scripts/flag.ts +28 -0
  151. package/app/scripts/og.ts +27 -0
  152. package/app/scripts/preview/build.ts +84 -0
  153. package/app/scripts/preview/data/alert.ts +19 -0
  154. package/app/scripts/preview/data/custom.ts +8 -0
  155. package/app/scripts/preview/data/genericLink.ts +24 -0
  156. package/app/scripts/preview/data/pageLink.ts +20 -0
  157. package/app/scripts/preview/data/unique.ts +70 -0
  158. package/app/scripts/preview/data.ts +26 -0
  159. package/app/scripts/preview/display.ts +39 -0
  160. package/app/scripts/preview/footer.ts +9 -0
  161. package/app/scripts/preview/request.ts +51 -0
  162. package/app/scripts/preview/state.ts +63 -0
  163. package/app/styles/_immediate.css +3 -0
  164. package/app/styles/_util.scss +50 -0
  165. package/app/styles/_utils.scss +44 -0
  166. package/app/styles/app.scss +91 -0
  167. package/app/styles/def/_bp.scss +24 -0
  168. package/app/styles/def/_size.scss +7 -0
  169. package/app/styles/def/_z.scss +5 -0
  170. package/app/styles/default.scss +85 -0
  171. package/app/styles/normalize.scss +63 -0
  172. package/app/styles/partials/_darkMagic.scss +7 -0
  173. package/app/styles/partials/_fnav.scss +18 -0
  174. package/app/styles/partials/_preview.scss +7 -0
  175. package/globalPath.ts +24 -0
  176. package/globals/bitran.ts +39 -0
  177. package/globals/content.ts +22 -0
  178. package/globals/contributor.ts +5 -0
  179. package/globals/erudit.ts +5 -0
  180. package/globals/register.ts +18 -0
  181. package/languages/en.ts +95 -0
  182. package/languages/ru.ts +99 -0
  183. package/module/bitran.ts +34 -0
  184. package/module/config.ts +34 -0
  185. package/module/imports.ts +46 -0
  186. package/module/index.ts +35 -0
  187. package/module/logger.ts +10 -0
  188. package/module/paths.ts +22 -0
  189. package/module/restart.ts +61 -0
  190. package/nuxt.config.ts +96 -0
  191. package/package.json +32 -0
  192. package/server/api/aside/major/nav/bookIds.ts +5 -0
  193. package/server/api/aside/major/nav/bookNav/[...bookId].ts +20 -0
  194. package/server/api/aside/major/nav/global.ts +7 -0
  195. package/server/api/aside/minor/news.ts +7 -0
  196. package/server/api/aside/minor/path.ts +78 -0
  197. package/server/api/bitran/content/[location].ts +7 -0
  198. package/server/api/bitran/toc/[location].ts +7 -0
  199. package/server/api/content/data.ts +72 -0
  200. package/server/api/contributor/count.ts +6 -0
  201. package/server/api/fake/content.ts +11 -0
  202. package/server/api/fake/shared/languages.ts +12 -0
  203. package/server/api/language/functions.ts +12 -0
  204. package/server/api/language/phrase/[phraseId].ts +19 -0
  205. package/server/api/language/phraseIds.ts +8 -0
  206. package/server/api/preview/page/[...parts].ts +51 -0
  207. package/server/api/preview/unique/[location].ts +55 -0
  208. package/server/plugin/bitran/content.ts +176 -0
  209. package/server/plugin/bitran/core.ts +51 -0
  210. package/server/plugin/bitran/location.ts +25 -0
  211. package/server/plugin/bitran/products/include.ts +229 -0
  212. package/server/plugin/bitran/products/link.ts +114 -0
  213. package/server/plugin/bitran/setup.ts +10 -0
  214. package/server/plugin/bitran/toc.ts +82 -0
  215. package/server/plugin/build/close.ts +10 -0
  216. package/server/plugin/build/jobs/content/builderArgs.ts +8 -0
  217. package/server/plugin/build/jobs/content/generic.ts +176 -0
  218. package/server/plugin/build/jobs/content/parse.ts +90 -0
  219. package/server/plugin/build/jobs/content/path.ts +6 -0
  220. package/server/plugin/build/jobs/content/type/book.ts +9 -0
  221. package/server/plugin/build/jobs/content/type/group.ts +37 -0
  222. package/server/plugin/build/jobs/content/type/topic.ts +36 -0
  223. package/server/plugin/build/jobs/contributors.ts +66 -0
  224. package/server/plugin/build/jobs/language.ts +36 -0
  225. package/server/plugin/build/jobs/nav.ts +209 -0
  226. package/server/plugin/build/process.ts +25 -0
  227. package/server/plugin/build/rebuild.ts +55 -0
  228. package/server/plugin/build/setup.ts +21 -0
  229. package/server/plugin/content/absoluteId.ts +94 -0
  230. package/server/plugin/content/context.ts +112 -0
  231. package/server/plugin/db/entities/Book.ts +7 -0
  232. package/server/plugin/db/entities/Content.ts +49 -0
  233. package/server/plugin/db/entities/Contribution.ts +10 -0
  234. package/server/plugin/db/entities/Contributor.ts +16 -0
  235. package/server/plugin/db/entities/Group.ts +14 -0
  236. package/server/plugin/db/entities/Hash.ts +15 -0
  237. package/server/plugin/db/entities/Topic.ts +20 -0
  238. package/server/plugin/db/entities/Unique.ts +21 -0
  239. package/server/plugin/db/setup.ts +34 -0
  240. package/server/plugin/global.ts +18 -0
  241. package/server/plugin/importer.ts +12 -0
  242. package/server/plugin/index.ts +9 -0
  243. package/server/plugin/logger.ts +23 -0
  244. package/server/plugin/nav/node.ts +26 -0
  245. package/server/plugin/nav/utils.ts +129 -0
  246. package/server/plugin/repository/book.ts +21 -0
  247. package/server/plugin/repository/content.ts +238 -0
  248. package/server/plugin/repository/contributor.ts +8 -0
  249. package/server/plugin/repository/frontNav.ts +148 -0
  250. package/server/plugin/repository/topic.ts +32 -0
  251. package/server/tsconfig.json +7 -0
  252. package/shared/aside/minor.ts +50 -0
  253. package/shared/asset.ts +15 -0
  254. package/shared/bitran/alias.ts +17 -0
  255. package/shared/bitran/context.ts +7 -0
  256. package/shared/bitran/location.ts +166 -0
  257. package/shared/bitran/products/alias/core/factory.ts +46 -0
  258. package/shared/bitran/products/alias/core/index.ts +13 -0
  259. package/shared/bitran/products/alias/render/Alias.vue +10 -0
  260. package/shared/bitran/products/alias/render/icon.svg +3 -0
  261. package/shared/bitran/products/alias/render/index.ts +17 -0
  262. package/shared/bitran/products/alias/render/languages/en.ts +5 -0
  263. package/shared/bitran/products/alias/render/languages/ru.ts +5 -0
  264. package/shared/bitran/products/alias/shared.ts +11 -0
  265. package/shared/bitran/products/heading/core/factory.ts +53 -0
  266. package/shared/bitran/products/heading/core/index.ts +19 -0
  267. package/shared/bitran/products/heading/render/Heading.vue +47 -0
  268. package/shared/bitran/products/heading/render/icon.svg +3 -0
  269. package/shared/bitran/products/heading/render/index.ts +17 -0
  270. package/shared/bitran/products/heading/render/languages/en.ts +5 -0
  271. package/shared/bitran/products/heading/render/languages/ru.ts +5 -0
  272. package/shared/bitran/products/heading/shared.ts +13 -0
  273. package/shared/bitran/products/include/core/factory.ts +61 -0
  274. package/shared/bitran/products/include/core/index.ts +13 -0
  275. package/shared/bitran/products/include/render/Include.vue +13 -0
  276. package/shared/bitran/products/include/render/icon.svg +3 -0
  277. package/shared/bitran/products/include/render/index.ts +18 -0
  278. package/shared/bitran/products/include/render/languages/en.ts +5 -0
  279. package/shared/bitran/products/include/render/languages/ru.ts +5 -0
  280. package/shared/bitran/products/include/shared.ts +15 -0
  281. package/shared/bitran/products/link/core/factory.ts +20 -0
  282. package/shared/bitran/products/link/core/index.ts +17 -0
  283. package/shared/bitran/products/link/render/Link.vue +174 -0
  284. package/shared/bitran/products/link/render/icon.svg +3 -0
  285. package/shared/bitran/products/link/render/index.ts +17 -0
  286. package/shared/bitran/products/link/render/languages/en.ts +5 -0
  287. package/shared/bitran/products/link/render/languages/ru.ts +5 -0
  288. package/shared/bitran/products/link/shared.ts +15 -0
  289. package/shared/bitran/products/link/target.ts +134 -0
  290. package/shared/bitran/toc.ts +8 -0
  291. package/shared/content/context.ts +9 -0
  292. package/shared/content/data/base.ts +32 -0
  293. package/shared/content/data/index.ts +5 -0
  294. package/shared/content/data/type/book.ts +5 -0
  295. package/shared/content/data/type/group.ts +6 -0
  296. package/shared/content/data/type/topic.ts +11 -0
  297. package/shared/content/previousNext.ts +9 -0
  298. package/shared/contributor.ts +5 -0
  299. package/shared/frontNav.ts +41 -0
  300. package/shared/icons.ts +38 -0
  301. package/shared/image.ts +5 -0
  302. package/shared/link.ts +25 -0
  303. package/shared/types/language.ts +75 -0
  304. package/shared/utils/objectsEqual.ts +4 -0
  305. package/shared/utils/stringColor.ts +9 -0
  306. package/test/bitran/alias.test.ts +44 -0
  307. package/test/bitran/location.test.ts +143 -0
  308. package/test/bitran/products/alias.test.ts +83 -0
  309. package/test/bitran/products/heading.test.ts +119 -0
  310. package/test/bitran/products/include.test.ts +77 -0
  311. package/test/bitran/products/link/factory.test.ts +30 -0
  312. package/test/bitran/products/link/target.test.ts +138 -0
  313. package/tsconfig.json +8 -0
  314. package/utils/stress.ts +9 -0
package/shared/link.ts ADDED
@@ -0,0 +1,25 @@
1
+ import type { ContentType, TopicPart } from 'erudit-cog/schema';
2
+ import type { BitranLocation } from './bitran/location';
3
+
4
+ export function createBitranLocationLink(location: BitranLocation) {
5
+ let link = `/${location.type}/${location.path}`;
6
+
7
+ if (location.unique) link += `#${location.unique}`;
8
+
9
+ return link;
10
+ }
11
+
12
+ export function createContentLink(contentType: ContentType, contentId: string) {
13
+ // if (contentType === 'topic')
14
+ // throw Error(`Use 'createTopicPartLink' to create links to topics!`);
15
+
16
+ return `/${contentType}/${contentId}`;
17
+ }
18
+
19
+ export function createTopicPartLink(topicPart: TopicPart, contentId: string) {
20
+ return `/${topicPart}/${contentId}`;
21
+ }
22
+
23
+ export function createContributorLink(contributorId: string) {
24
+ return `/contributor/${contributorId}`;
25
+ }
@@ -0,0 +1,75 @@
1
+ export interface EruditPhrases {
2
+ _language_title: string;
3
+ _language_code: string;
4
+
5
+ site_info_title: string;
6
+ site_info_slogan: string;
7
+ seo_index_title: string;
8
+ seo_index_description: string;
9
+ seo_article_description: (contentTitle: string) => string;
10
+ seo_summary_description: (contentTitle: string) => string;
11
+ seo_practice_description: (contentTitle: string) => string;
12
+ index: string;
13
+ pages: string;
14
+ search: string;
15
+ language: string;
16
+ other: string;
17
+ ads_replacer: string;
18
+ theme: string;
19
+ theme_system: string;
20
+ theme_light: string;
21
+ theme_dark: string;
22
+ content: string;
23
+ generator: string;
24
+ main_page: string;
25
+ members: string;
26
+ add_translation: string;
27
+ empty_nav: string;
28
+ flag_dev: string;
29
+ flag_dev_description: string;
30
+ flag_advanced: string;
31
+ flag_advanced_description: string;
32
+ flag_secondary: string;
33
+ flag_secondary_description: string;
34
+ popover_dependencies: string;
35
+ popover_dependencies_description: string;
36
+ to_index: string;
37
+ about_book: string;
38
+ close: string;
39
+ back: string;
40
+ goto: string;
41
+ error: string;
42
+ external_link: string;
43
+ external_link_warn: string;
44
+ internal_link: string;
45
+ internal_link_warn: string;
46
+ book: string;
47
+ group: string;
48
+ topic: string;
49
+ article: string;
50
+ summary: string;
51
+ practice: string;
52
+ contributor: string;
53
+ element_id: string;
54
+ preview_missing_title: string;
55
+ preview_missing_explain: string;
56
+ preview_missing_explain_mismatch: string;
57
+ preview_hash_mismatch_title: string;
58
+ preview_hash_mismatch_explain: string;
59
+ current_page_hash: string;
60
+ expected_page_hash: string;
61
+ empty_toc: string;
62
+ contributors: string;
63
+ no_contributors: string;
64
+ make_contribution: string;
65
+ material_improvement: string;
66
+ how_to_improve: string;
67
+ edit_page: string;
68
+ report_problem: string;
69
+ references: string;
70
+ reference_source_featured: string;
71
+ references_description: string;
72
+ }
73
+
74
+ export type EruditPhraseId = keyof Partial<EruditPhrases>;
75
+ export type EruditPhrase = EruditPhrases[keyof EruditPhrases];
@@ -0,0 +1,4 @@
1
+ export function objectsEqual(a: any, b: any) {
2
+ const str = (obj: any) => JSON.stringify(obj)?.split('').sort().join('');
3
+ return str(a) === str(b);
4
+ }
@@ -0,0 +1,9 @@
1
+ export function stringColor(text: string) {
2
+ let hash = 0;
3
+
4
+ for (let i = 0; i < text.length; i++) {
5
+ hash = text.charCodeAt(i) + ((hash << 5) - hash);
6
+ }
7
+
8
+ return `hsl(${hash % 360}, 85%, 35%)`;
9
+ }
@@ -0,0 +1,44 @@
1
+ import { tryReplaceAlias } from '@erudit/shared/bitran/alias';
2
+
3
+ const aliases = {
4
+ a1: 'foo',
5
+ a2: 'bar',
6
+ a3: 'baz',
7
+ };
8
+
9
+ const replaceTargets = ['~a1', '~a2', '~a3'];
10
+
11
+ const noTouchTargets = [
12
+ 'foo|bar|baz',
13
+ 'https://www.google.com',
14
+ '~',
15
+ ' ~a1',
16
+ '~ a1',
17
+ '~a1 ',
18
+ '~a1 a2',
19
+ ];
20
+
21
+ const throwTargets = ['~a4'];
22
+
23
+ //
24
+ //
25
+ //
26
+
27
+ describe('tryReplaceAlias', () => {
28
+ for (const target of replaceTargets) {
29
+ // @ts-ignore
30
+ const replaceValue = aliases[target.substring(1)];
31
+
32
+ it(`should replace target "${target}" with "${replaceValue}"`, () => {
33
+ expect(tryReplaceAlias(target, aliases)).toBe(replaceValue);
34
+ });
35
+ }
36
+
37
+ it.each(noTouchTargets)('should not change target "%s"', (target) => {
38
+ expect(tryReplaceAlias(target, aliases)).toBe(target);
39
+ });
40
+
41
+ it.each(throwTargets)('should throw on target "%s"', (target) => {
42
+ expect(() => tryReplaceAlias(target, aliases)).toThrow();
43
+ });
44
+ });
@@ -0,0 +1,143 @@
1
+ import {
2
+ decodeBitranLocation,
3
+ encodeBitranLocation,
4
+ parseBitranLocation,
5
+ parsePartialBitranLocation,
6
+ stringifyBitranLocation,
7
+ type BitranLocation,
8
+ } from '@erudit/shared/bitran/location';
9
+
10
+ const locations: [BitranLocation, string][] = [
11
+ // Full locations
12
+ [{ type: 'article', path: 'foo', unique: 'bar' }, 'article|foo|bar'],
13
+ [{ type: 'group', path: 'foo', unique: 'bar' }, 'group|foo|bar'],
14
+ // Type + path
15
+ [{ type: 'article', path: 'foo' }, 'article|foo'],
16
+ [{ type: 'group', path: 'foo' }, 'group|foo'],
17
+ ];
18
+
19
+ const partialLocations: [string, BitranLocation, BitranLocation][] = [
20
+ // Full string location
21
+ [
22
+ 'article|foo/bar|baz',
23
+ { type: 'group', path: 'qux' },
24
+ { type: 'article', path: 'foo/bar', unique: 'baz' },
25
+ ],
26
+ // Only unique
27
+ [
28
+ 'baz',
29
+ { type: 'summary', path: 'foo/bar' },
30
+ { type: 'summary', path: 'foo/bar', unique: 'baz' },
31
+ ],
32
+ [
33
+ 'baz',
34
+ { type: 'contributor', path: 'John' },
35
+ { type: 'contributor', path: 'John', unique: 'baz' },
36
+ ],
37
+ // Topic context
38
+ [
39
+ 'article|baz',
40
+ { type: 'practice', path: 'foo/bar' },
41
+ { type: 'article', path: 'foo/bar', unique: 'baz' },
42
+ ],
43
+ ];
44
+
45
+ const invalidPartialLocations: [string, BitranLocation][] = [
46
+ // Referencing topic part in non-topic context
47
+ ['article|bar', { type: 'contributor', path: 'foo' }],
48
+ ];
49
+
50
+ const invalidLocations = [
51
+ // Too few parts
52
+ { type: 'article' },
53
+ { path: 'foo' },
54
+ { unique: 'foo' },
55
+ // Unknown type
56
+ { type: 'foo' },
57
+ { type: 'foo', path: 'bar', unique: 'baz' },
58
+ // Locations that require path
59
+ { type: 'article', unique: 'foo' },
60
+ { type: 'summary', unique: 'foo' },
61
+ { type: 'practice', unique: 'foo' },
62
+ { type: 'group', unique: 'foo' },
63
+ { type: 'contributor', unique: 'foo' },
64
+ ];
65
+
66
+ const invalidStrLocations = [
67
+ // Too few parts
68
+ 'article',
69
+ 'group',
70
+ // Unknown type
71
+ 'foo',
72
+ 'foo|bar',
73
+ 'foo|bar|baz',
74
+ // Empty string unique
75
+ 'article|foo/bar|',
76
+ ];
77
+
78
+ //
79
+ //
80
+ //
81
+
82
+ describe('stringifyBitranLocation', () => {
83
+ for (const [location, expected] of locations) {
84
+ it(`should produce "${expected}"`, () => {
85
+ expect(stringifyBitranLocation(location)).toBe(expected);
86
+ });
87
+ }
88
+
89
+ for (const invalidLocation of invalidLocations) {
90
+ it(`should throw on location ${JSON.stringify(invalidLocation)}`, () => {
91
+ expect(() =>
92
+ stringifyBitranLocation(invalidLocation as BitranLocation),
93
+ ).toThrow();
94
+ });
95
+ }
96
+ });
97
+
98
+ describe('parseBitranLocation', () => {
99
+ for (const [location, expected] of locations) {
100
+ it(`should produce ${JSON.stringify(expected)}`, () => {
101
+ expect(parseBitranLocation(expected)).toEqual(location);
102
+ });
103
+ }
104
+
105
+ for (const invalidStrLocation of invalidStrLocations) {
106
+ it(`should throw on location "${invalidStrLocation}"`, () => {
107
+ expect(() => parseBitranLocation(invalidStrLocation)).toThrow();
108
+ });
109
+ }
110
+ });
111
+
112
+ describe('parsePartialBitranLocation', () => {
113
+ for (const [locationStr, context, expected] of partialLocations) {
114
+ it(`should produce ${JSON.stringify(expected)}`, () => {
115
+ expect(parsePartialBitranLocation(locationStr, context)).toEqual(
116
+ expected,
117
+ );
118
+ });
119
+ }
120
+
121
+ for (const [locationStr, context] of invalidPartialLocations) {
122
+ it(`should throw on location "${locationStr}"`, () => {
123
+ expect(() =>
124
+ parsePartialBitranLocation(locationStr, context),
125
+ ).toThrow();
126
+ });
127
+ }
128
+ });
129
+
130
+ describe('decode/encodeBitranLocation', () => {
131
+ it.each([
132
+ '',
133
+ 'foo',
134
+ 'foo|bar',
135
+ 'foo|bar|baz',
136
+ 'foo|bar/baz|qux',
137
+ 'foo|bar/baz/qux|corge:grault:waldo',
138
+ ])('should not change string location %p', (testCase) =>
139
+ expect(decodeBitranLocation(encodeBitranLocation(testCase))).toBe(
140
+ testCase,
141
+ ),
142
+ );
143
+ });
@@ -0,0 +1,83 @@
1
+ import { createBitranCore, ParagraphNode } from 'bitran/core';
2
+ import { ErrorNode } from 'bitran/default';
3
+
4
+ import { AliasNode, defineAlias } from '@shared/bitran/products/alias/core';
5
+ import type { AliasType } from '@shared/bitran/products/alias/shared';
6
+
7
+ const bitran = createBitranCore({
8
+ products: {
9
+ alias: defineAlias({
10
+ a1: 'context alias 1',
11
+ a3: 'context alias 3',
12
+ }),
13
+ },
14
+ });
15
+
16
+ test('Alias parse and stringify', async () => {
17
+ const text = `
18
+
19
+ ~ foo article|foo|bar
20
+
21
+ ~ bar article|foo|bar
22
+ ~ baz article|foo|bar
23
+
24
+ `;
25
+
26
+ const parsed = await bitran.parser.parse(text);
27
+
28
+ const data: AliasType['ParseData'][] = [
29
+ { foo: 'article|foo|bar' },
30
+ {
31
+ bar: 'article|foo|bar',
32
+ baz: 'article|foo|bar',
33
+ },
34
+ ];
35
+
36
+ expect(
37
+ parsed.children.map((node) => (node as AliasNode).parseData),
38
+ ).toEqual(data);
39
+
40
+ expect(bitran.stringifier.stringify(parsed)).toEqual(text.trim());
41
+ });
42
+
43
+ test('Fake aliases', async () => {
44
+ const text = `
45
+
46
+ ~ NoSpaceBetween
47
+
48
+ ~ foo targetFoo
49
+ ~ NoSpaceBetween
50
+
51
+ ~ NoSpaceBetween
52
+ ~ foo targetFoo
53
+
54
+ Some text
55
+ ~ foo targetFoo
56
+
57
+ ~foo
58
+
59
+ ~ foo targetFoo
60
+ Some text
61
+
62
+ `;
63
+
64
+ const paragraphs = (await bitran.parser.parse(text)).children;
65
+
66
+ for (const paragraph of paragraphs)
67
+ expect(paragraph).toBeInstanceOf(ParagraphNode);
68
+ });
69
+
70
+ test('Invalid aliases', async () => {
71
+ const text = `
72
+
73
+ ~ a1 <invalid>
74
+
75
+ ~ a2 fooTarget
76
+ ~ a3 <invalid>
77
+
78
+ `;
79
+
80
+ const aliases = (await bitran.parser.parse(text)).children;
81
+
82
+ for (const alias of aliases) expect(alias).toBeInstanceOf(ErrorNode);
83
+ });
@@ -0,0 +1,119 @@
1
+ import { ErrorNode } from 'bitran/default';
2
+ import { createBitranCore, ParagraphNode } from 'bitran/core';
3
+
4
+ import {
5
+ defineLocaleHeading,
6
+ heading,
7
+ HeadingNode,
8
+ } from '@shared/bitran/products/heading/core';
9
+
10
+ const bitran = createBitranCore({
11
+ products: {
12
+ heading,
13
+ },
14
+ });
15
+
16
+ test('Headings parse and stringify', async () => {
17
+ const text = `
18
+
19
+ # Hello!
20
+
21
+ ## This is me.
22
+
23
+ ### All this is valid, event "with $special$ characters"!
24
+
25
+ `;
26
+
27
+ const parsed = await bitran.parser.parse(text);
28
+
29
+ expect(
30
+ parsed.children.map((node) => (node as HeadingNode).parseData),
31
+ ).toEqual([
32
+ { level: 0, title: 'Hello!' },
33
+ { level: 1, title: 'This is me.' },
34
+ {
35
+ level: 2,
36
+ title: 'All this is valid, event "with $special$ characters"!',
37
+ },
38
+ ]);
39
+
40
+ expect(bitran.stringifier.stringify(parsed)).toEqual(text.trim());
41
+ });
42
+
43
+ test('Invalid headings', async () => {
44
+ const text = `
45
+
46
+ #### Just too many!
47
+
48
+ `;
49
+
50
+ const headings = (await bitran.parser.parse(text)).children;
51
+
52
+ for (const heading of headings) expect(heading).toBeInstanceOf(ErrorNode);
53
+ });
54
+
55
+ test('Paragraphs which tricks parser to think they are headings', async () => {
56
+ const text = `
57
+
58
+ #
59
+
60
+ ###
61
+
62
+ # Some
63
+ text
64
+
65
+ Some
66
+ # text
67
+
68
+ `;
69
+
70
+ const paragraphs = (await bitran.parser.parse(text)).children;
71
+
72
+ for (const paragraph of paragraphs)
73
+ expect(paragraph).toBeInstanceOf(ParagraphNode);
74
+ });
75
+
76
+ test('Auto IDs with unset locale', async () => {
77
+ const text = `
78
+
79
+ # Some long phrase
80
+
81
+ # Containing-!#$%*():bad characters
82
+
83
+ # И немного текста
84
+
85
+ # Some long phrase
86
+
87
+ `;
88
+
89
+ const headings = (await bitran.parser.parse(text)).children;
90
+
91
+ expect(
92
+ headings.map((heading) => (heading as HeadingNode).generated.autoId),
93
+ ).toEqual([
94
+ 'some-long-phrase',
95
+ 'containing-dollarpercentbad-characters',
96
+ 'i-nemnogo-teksta',
97
+ 'some-long-phrase-',
98
+ ]);
99
+ });
100
+
101
+ test('Auto IDs with locale', async () => {
102
+ const text = `
103
+
104
+ # Маленький Подъезд
105
+
106
+ `;
107
+
108
+ const localeBitran = createBitranCore({
109
+ products: {
110
+ heading: defineLocaleHeading({ languageCode: 'bg' }),
111
+ },
112
+ });
113
+
114
+ const headings = (await localeBitran.parser.parse(text)).children;
115
+
116
+ expect(
117
+ headings.map((heading) => (heading as HeadingNode).generated.autoId),
118
+ ).toEqual(['malenykiy-podaezd']);
119
+ });
@@ -0,0 +1,77 @@
1
+ import { createBitranCore, ParagraphNode } from 'bitran/core';
2
+
3
+ import { include, IncludeNode } from '@shared/bitran/products/include/core';
4
+ import { includeName } from '@shared/bitran/products/include/shared';
5
+
6
+ const bitranCore = createBitranCore({
7
+ products: {
8
+ [includeName]: include,
9
+ },
10
+ });
11
+
12
+ test('Includes parse and stringify', async () => {
13
+ const text = `
14
+
15
+ <~ definition:set
16
+
17
+ <~ group|triangle|theorem:pifagorean-theorem
18
+
19
+ <~ summary|baz
20
+
21
+ `;
22
+
23
+ const parsed = await bitranCore.parser.parse(text);
24
+
25
+ const locations: string[] = [
26
+ 'definition:set',
27
+ 'group|triangle|theorem:pifagorean-theorem',
28
+ 'summary|baz',
29
+ ];
30
+
31
+ expect(
32
+ parsed.children.map((node) => (node as IncludeNode).parseData.location),
33
+ ).toEqual(locations);
34
+
35
+ expect(bitranCore.stringifier.stringify(parsed)).toEqual(text.trim());
36
+ });
37
+
38
+ test('Resolved include parse and stringify', async () => {
39
+ const text = `
40
+
41
+ @__include
42
+ location: foo
43
+ resolved: true
44
+ blocks: |
45
+ Paragraph 1
46
+
47
+ Paragraph 2
48
+
49
+ `;
50
+
51
+ const parsed = await bitranCore.parser.parse(text);
52
+
53
+ expect(bitranCore.stringifier.stringify(parsed)).toEqual(text.trim());
54
+ });
55
+
56
+ test('Invalid includes', async () => {
57
+ const text = `
58
+
59
+ <~  
60
+
61
+ <~
62
+
63
+ <~ one two three
64
+
65
+ <~ id
66
+ text
67
+
68
+ Some
69
+ <~ id
70
+
71
+ `;
72
+
73
+ const paragraphs = (await bitranCore.parser.parse(text)).children;
74
+
75
+ for (const paragraph of paragraphs)
76
+ expect(paragraph).toBeInstanceOf(ParagraphNode);
77
+ });
@@ -0,0 +1,30 @@
1
+ import { createBitranCore } from 'bitran/core';
2
+
3
+ import { link, LinkNode } from '@shared/bitran/products/link/core';
4
+ import type { LinkData } from '@shared/bitran/products/link/shared';
5
+
6
+ const bitran = createBitranCore({
7
+ products: {
8
+ link,
9
+ },
10
+ });
11
+
12
+ test('Link parse and stringify', async () => {
13
+ const text = `This [is](target1) long line <<of [text](target2)>>!`;
14
+
15
+ const parsed = await bitran.parser.parseInliners(text);
16
+
17
+ // @ts-ignore
18
+ const links = [parsed[1], parsed[3]['parseData'].children[1]];
19
+
20
+ for (const link of links) expect(link).toBeInstanceOf(LinkNode);
21
+
22
+ expect(links[0].parseData).toEqual(<LinkData>{
23
+ label: 'is',
24
+ target: 'target1',
25
+ });
26
+ expect(links[1].parseData).toEqual(<LinkData>{
27
+ label: 'text',
28
+ target: 'target2',
29
+ });
30
+ });