@diplodoc/transform 4.0.0

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 (355) hide show
  1. package/CHANGELOG.diplodoc.md +38 -0
  2. package/CHANGELOG.md +404 -0
  3. package/LICENSE +21 -0
  4. package/README.md +41 -0
  5. package/README.ru.md +36 -0
  6. package/dist/css/yfm.css +736 -0
  7. package/dist/css/yfm.css.map +7 -0
  8. package/dist/css/yfm.min.css +2 -0
  9. package/dist/css/yfm.min.css.map +7 -0
  10. package/dist/js/code.d.ts +1 -0
  11. package/dist/js/cut.d.ts +1 -0
  12. package/dist/js/index.d.ts +5 -0
  13. package/dist/js/polyfill.d.ts +1 -0
  14. package/dist/js/tabs.d.ts +1 -0
  15. package/dist/js/term/index.d.ts +1 -0
  16. package/dist/js/term/utils.d.ts +10 -0
  17. package/dist/js/utils.d.ts +2 -0
  18. package/dist/js/yfm.js +432 -0
  19. package/dist/js/yfm.js.map +7 -0
  20. package/dist/js/yfm.min.js +2 -0
  21. package/dist/js/yfm.min.js.map +7 -0
  22. package/lib/getObject.d.ts +2 -0
  23. package/lib/getObject.js +11 -0
  24. package/lib/getObject.js.map +1 -0
  25. package/lib/headings.d.ts +4 -0
  26. package/lib/headings.js +73 -0
  27. package/lib/headings.js.map +1 -0
  28. package/lib/highlight.d.ts +3 -0
  29. package/lib/highlight.js +29 -0
  30. package/lib/highlight.js.map +1 -0
  31. package/lib/index.d.ts +7 -0
  32. package/lib/index.js +35 -0
  33. package/lib/index.js.map +1 -0
  34. package/lib/liquid/conditions.d.ts +4 -0
  35. package/lib/liquid/conditions.js +181 -0
  36. package/lib/liquid/conditions.js.map +1 -0
  37. package/lib/liquid/cycles.d.ts +4 -0
  38. package/lib/liquid/cycles.js +160 -0
  39. package/lib/liquid/cycles.js.map +1 -0
  40. package/lib/liquid/errors.d.ts +3 -0
  41. package/lib/liquid/errors.js +13 -0
  42. package/lib/liquid/errors.js.map +1 -0
  43. package/lib/liquid/evaluation.d.ts +3 -0
  44. package/lib/liquid/evaluation.js +138 -0
  45. package/lib/liquid/evaluation.js.map +1 -0
  46. package/lib/liquid/filters.d.ts +9 -0
  47. package/lib/liquid/filters.js +22 -0
  48. package/lib/liquid/filters.js.map +1 -0
  49. package/lib/liquid/index.d.ts +9 -0
  50. package/lib/liquid/index.js +87 -0
  51. package/lib/liquid/index.js.map +1 -0
  52. package/lib/liquid/lexical.d.ts +14 -0
  53. package/lib/liquid/lexical.js +79 -0
  54. package/lib/liquid/lexical.js.map +1 -0
  55. package/lib/liquid/services/argv.d.ts +15 -0
  56. package/lib/liquid/services/argv.js +17 -0
  57. package/lib/liquid/services/argv.js.map +1 -0
  58. package/lib/liquid/sourceMap.d.ts +24 -0
  59. package/lib/liquid/sourceMap.js +56 -0
  60. package/lib/liquid/sourceMap.js.map +1 -0
  61. package/lib/liquid/substitutions.d.ts +2 -0
  62. package/lib/liquid/substitutions.js +36 -0
  63. package/lib/liquid/substitutions.js.map +1 -0
  64. package/lib/liquid/utils.d.ts +8 -0
  65. package/lib/liquid/utils.js +24 -0
  66. package/lib/liquid/utils.js.map +1 -0
  67. package/lib/log.d.ts +18 -0
  68. package/lib/log.js +54 -0
  69. package/lib/log.js.map +1 -0
  70. package/lib/md.d.ts +14 -0
  71. package/lib/md.js +96 -0
  72. package/lib/md.js.map +1 -0
  73. package/lib/plugins/anchors/collect.d.ts +5 -0
  74. package/lib/plugins/anchors/collect.js +81 -0
  75. package/lib/plugins/anchors/collect.js.map +1 -0
  76. package/lib/plugins/anchors/constants.d.ts +2 -0
  77. package/lib/plugins/anchors/constants.js +6 -0
  78. package/lib/plugins/anchors/constants.js.map +1 -0
  79. package/lib/plugins/anchors/index.d.ts +7 -0
  80. package/lib/plugins/anchors/index.js +134 -0
  81. package/lib/plugins/anchors/index.js.map +1 -0
  82. package/lib/plugins/changelog/collect.d.ts +8 -0
  83. package/lib/plugins/changelog/collect.js +50 -0
  84. package/lib/plugins/changelog/collect.js.map +1 -0
  85. package/lib/plugins/changelog/index.d.ts +6 -0
  86. package/lib/plugins/changelog/index.js +131 -0
  87. package/lib/plugins/changelog/index.js.map +1 -0
  88. package/lib/plugins/changelog/types.d.ts +10 -0
  89. package/lib/plugins/changelog/types.js +3 -0
  90. package/lib/plugins/changelog/types.js.map +1 -0
  91. package/lib/plugins/checkbox/checkbox.d.ts +7 -0
  92. package/lib/plugins/checkbox/checkbox.js +91 -0
  93. package/lib/plugins/checkbox/checkbox.js.map +1 -0
  94. package/lib/plugins/checkbox/index.d.ts +8 -0
  95. package/lib/plugins/checkbox/index.js +12 -0
  96. package/lib/plugins/checkbox/index.js.map +1 -0
  97. package/lib/plugins/code.d.ts +3 -0
  98. package/lib/plugins/code.js +61 -0
  99. package/lib/plugins/code.js.map +1 -0
  100. package/lib/plugins/cut.d.ts +3 -0
  101. package/lib/plugins/cut.js +70 -0
  102. package/lib/plugins/cut.js.map +1 -0
  103. package/lib/plugins/deflist.d.ts +3 -0
  104. package/lib/plugins/deflist.js +8 -0
  105. package/lib/plugins/deflist.js.map +1 -0
  106. package/lib/plugins/file/const.d.ts +27 -0
  107. package/lib/plugins/file/const.js +47 -0
  108. package/lib/plugins/file/const.js.map +1 -0
  109. package/lib/plugins/file/file.d.ts +8 -0
  110. package/lib/plugins/file/file.js +63 -0
  111. package/lib/plugins/file/file.js.map +1 -0
  112. package/lib/plugins/file/index.d.ts +4 -0
  113. package/lib/plugins/file/index.js +9 -0
  114. package/lib/plugins/file/index.js.map +1 -0
  115. package/lib/plugins/images/collect.d.ts +8 -0
  116. package/lib/plugins/images/collect.js +43 -0
  117. package/lib/plugins/images/collect.js.map +1 -0
  118. package/lib/plugins/images/index.d.ts +10 -0
  119. package/lib/plugins/images/index.js +81 -0
  120. package/lib/plugins/images/index.js.map +1 -0
  121. package/lib/plugins/imsize/const.d.ts +7 -0
  122. package/lib/plugins/imsize/const.js +12 -0
  123. package/lib/plugins/imsize/const.js.map +1 -0
  124. package/lib/plugins/imsize/helpers.d.ts +6 -0
  125. package/lib/plugins/imsize/helpers.js +64 -0
  126. package/lib/plugins/imsize/helpers.js.map +1 -0
  127. package/lib/plugins/imsize/index.d.ts +8 -0
  128. package/lib/plugins/imsize/index.js +12 -0
  129. package/lib/plugins/imsize/index.js.map +1 -0
  130. package/lib/plugins/imsize/plugin.d.ts +3 -0
  131. package/lib/plugins/imsize/plugin.js +188 -0
  132. package/lib/plugins/imsize/plugin.js.map +1 -0
  133. package/lib/plugins/includes/collect.d.ts +8 -0
  134. package/lib/plugins/includes/collect.js +49 -0
  135. package/lib/plugins/includes/collect.js.map +1 -0
  136. package/lib/plugins/includes/index.d.ts +8 -0
  137. package/lib/plugins/includes/index.js +98 -0
  138. package/lib/plugins/includes/index.js.map +1 -0
  139. package/lib/plugins/links/collect.d.ts +7 -0
  140. package/lib/plugins/links/collect.js +74 -0
  141. package/lib/plugins/links/collect.js.map +1 -0
  142. package/lib/plugins/links/constants.d.ts +1 -0
  143. package/lib/plugins/links/constants.js +5 -0
  144. package/lib/plugins/links/constants.js.map +1 -0
  145. package/lib/plugins/links/index.d.ts +24 -0
  146. package/lib/plugins/links/index.js +178 -0
  147. package/lib/plugins/links/index.js.map +1 -0
  148. package/lib/plugins/meta.d.ts +3 -0
  149. package/lib/plugins/meta.js +8 -0
  150. package/lib/plugins/meta.js.map +1 -0
  151. package/lib/plugins/monospace.d.ts +3 -0
  152. package/lib/plugins/monospace.js +109 -0
  153. package/lib/plugins/monospace.js.map +1 -0
  154. package/lib/plugins/notes.d.ts +3 -0
  155. package/lib/plugins/notes.js +103 -0
  156. package/lib/plugins/notes.js.map +1 -0
  157. package/lib/plugins/sup.d.ts +3 -0
  158. package/lib/plugins/sup.js +8 -0
  159. package/lib/plugins/sup.js.map +1 -0
  160. package/lib/plugins/table/index.d.ts +3 -0
  161. package/lib/plugins/table/index.js +215 -0
  162. package/lib/plugins/table/index.js.map +1 -0
  163. package/lib/plugins/tabs.d.ts +4 -0
  164. package/lib/plugins/tabs.js +4 -0
  165. package/lib/plugins/tabs.js.map +1 -0
  166. package/lib/plugins/term/constants.d.ts +1 -0
  167. package/lib/plugins/term/constants.js +5 -0
  168. package/lib/plugins/term/constants.js.map +1 -0
  169. package/lib/plugins/term/index.d.ts +3 -0
  170. package/lib/plugins/term/index.js +108 -0
  171. package/lib/plugins/term/index.js.map +1 -0
  172. package/lib/plugins/term/termDefinitions.d.ts +4 -0
  173. package/lib/plugins/term/termDefinitions.js +125 -0
  174. package/lib/plugins/term/termDefinitions.js.map +1 -0
  175. package/lib/plugins/typings.d.ts +12 -0
  176. package/lib/plugins/typings.js +3 -0
  177. package/lib/plugins/typings.js.map +1 -0
  178. package/lib/plugins/utils.d.ts +6 -0
  179. package/lib/plugins/utils.js +30 -0
  180. package/lib/plugins/utils.js.map +1 -0
  181. package/lib/plugins/video/const.d.ts +10 -0
  182. package/lib/plugins/video/const.js +22 -0
  183. package/lib/plugins/video/const.js.map +1 -0
  184. package/lib/plugins/video/index.d.ts +8 -0
  185. package/lib/plugins/video/index.js +104 -0
  186. package/lib/plugins/video/index.js.map +1 -0
  187. package/lib/plugins/video/parsers.d.ts +6 -0
  188. package/lib/plugins/video/parsers.js +64 -0
  189. package/lib/plugins/video/parsers.js.map +1 -0
  190. package/lib/plugins/video/types.d.ts +34 -0
  191. package/lib/plugins/video/types.js +3 -0
  192. package/lib/plugins/video/types.js.map +1 -0
  193. package/lib/plugins/video/utils.d.ts +2 -0
  194. package/lib/plugins/video/utils.js +25 -0
  195. package/lib/plugins/video/utils.js.map +1 -0
  196. package/lib/plugins.d.ts +3 -0
  197. package/lib/plugins.js +36 -0
  198. package/lib/plugins.js.map +1 -0
  199. package/lib/sanitize.d.ts +12 -0
  200. package/lib/sanitize.js +572 -0
  201. package/lib/sanitize.js.map +1 -0
  202. package/lib/title.d.ts +7 -0
  203. package/lib/title.js +18 -0
  204. package/lib/title.js.map +1 -0
  205. package/lib/typings.d.ts +57 -0
  206. package/lib/typings.js +3 -0
  207. package/lib/typings.js.map +1 -0
  208. package/lib/utils.d.ts +13 -0
  209. package/lib/utils.js +79 -0
  210. package/lib/utils.js.map +1 -0
  211. package/lib/utilsFS.d.ts +27 -0
  212. package/lib/utilsFS.js +89 -0
  213. package/lib/utilsFS.js.map +1 -0
  214. package/lib/yfmlint/index.d.ts +26 -0
  215. package/lib/yfmlint/index.js +72 -0
  216. package/lib/yfmlint/index.js.map +1 -0
  217. package/lib/yfmlint/markdownlint-custom-rule/index.d.ts +9 -0
  218. package/lib/yfmlint/markdownlint-custom-rule/index.js +22 -0
  219. package/lib/yfmlint/markdownlint-custom-rule/index.js.map +1 -0
  220. package/lib/yfmlint/markdownlint-custom-rule/yfm001.d.ts +2 -0
  221. package/lib/yfmlint/markdownlint-custom-rule/yfm001.js +28 -0
  222. package/lib/yfmlint/markdownlint-custom-rule/yfm001.js.map +1 -0
  223. package/lib/yfmlint/markdownlint-custom-rule/yfm002.d.ts +2 -0
  224. package/lib/yfmlint/markdownlint-custom-rule/yfm002.js +33 -0
  225. package/lib/yfmlint/markdownlint-custom-rule/yfm002.js.map +1 -0
  226. package/lib/yfmlint/markdownlint-custom-rule/yfm003.d.ts +2 -0
  227. package/lib/yfmlint/markdownlint-custom-rule/yfm003.js +33 -0
  228. package/lib/yfmlint/markdownlint-custom-rule/yfm003.js.map +1 -0
  229. package/lib/yfmlint/markdownlint-custom-rule/yfm004.d.ts +2 -0
  230. package/lib/yfmlint/markdownlint-custom-rule/yfm004.js +28 -0
  231. package/lib/yfmlint/markdownlint-custom-rule/yfm004.js.map +1 -0
  232. package/lib/yfmlint/markdownlint-custom-rule/yfm005.d.ts +2 -0
  233. package/lib/yfmlint/markdownlint-custom-rule/yfm005.js +28 -0
  234. package/lib/yfmlint/markdownlint-custom-rule/yfm005.js.map +1 -0
  235. package/lib/yfmlint/markdownlint-custom-rule/yfm006.d.ts +2 -0
  236. package/lib/yfmlint/markdownlint-custom-rule/yfm006.js +28 -0
  237. package/lib/yfmlint/markdownlint-custom-rule/yfm006.js.map +1 -0
  238. package/lib/yfmlint/markdownlint-custom-rule/yfm007.d.ts +2 -0
  239. package/lib/yfmlint/markdownlint-custom-rule/yfm007.js +29 -0
  240. package/lib/yfmlint/markdownlint-custom-rule/yfm007.js.map +1 -0
  241. package/lib/yfmlint/markdownlint-custom-rule/yfm008.d.ts +2 -0
  242. package/lib/yfmlint/markdownlint-custom-rule/yfm008.js +28 -0
  243. package/lib/yfmlint/markdownlint-custom-rule/yfm008.js.map +1 -0
  244. package/lib/yfmlint/markdownlint-custom-rule/yfm009.d.ts +2 -0
  245. package/lib/yfmlint/markdownlint-custom-rule/yfm009.js +47 -0
  246. package/lib/yfmlint/markdownlint-custom-rule/yfm009.js.map +1 -0
  247. package/lib/yfmlint/typings.d.ts +12 -0
  248. package/lib/yfmlint/typings.js +3 -0
  249. package/lib/yfmlint/typings.js.map +1 -0
  250. package/lib/yfmlint/utils.d.ts +9 -0
  251. package/lib/yfmlint/utils.js +22 -0
  252. package/lib/yfmlint/utils.js.map +1 -0
  253. package/lib/yfmlint/yfmlint.d.ts +3 -0
  254. package/lib/yfmlint/yfmlint.js +69 -0
  255. package/lib/yfmlint/yfmlint.js.map +1 -0
  256. package/package.json +106 -0
  257. package/src/.eslintrc +10 -0
  258. package/src/js/code.ts +65 -0
  259. package/src/js/cut.ts +57 -0
  260. package/src/js/index.ts +6 -0
  261. package/src/js/polyfill.js +27 -0
  262. package/src/js/term/index.ts +79 -0
  263. package/src/js/term/utils.ts +151 -0
  264. package/src/js/utils.ts +9 -0
  265. package/src/scss/_anchor.scss +33 -0
  266. package/src/scss/_code.scss +23 -0
  267. package/src/scss/_common.scss +407 -0
  268. package/src/scss/_cut.scss +42 -0
  269. package/src/scss/_file.scss +35 -0
  270. package/src/scss/_highlight.scss +96 -0
  271. package/src/scss/_note.scss +73 -0
  272. package/src/scss/_print.scss +20 -0
  273. package/src/scss/_term.scss +79 -0
  274. package/src/scss/_variables.scss +16 -0
  275. package/src/scss/yfm.scss +11 -0
  276. package/src/transform/getObject.ts +10 -0
  277. package/src/transform/headings.ts +88 -0
  278. package/src/transform/highlight.ts +33 -0
  279. package/src/transform/index.ts +50 -0
  280. package/src/transform/liquid/conditions.ts +259 -0
  281. package/src/transform/liquid/cycles.ts +244 -0
  282. package/src/transform/liquid/errors.ts +10 -0
  283. package/src/transform/liquid/evaluation.ts +145 -0
  284. package/src/transform/liquid/filters.ts +19 -0
  285. package/src/transform/liquid/index.ts +141 -0
  286. package/src/transform/liquid/lexical.ts +86 -0
  287. package/src/transform/liquid/services/argv.ts +23 -0
  288. package/src/transform/liquid/sourceMap.ts +72 -0
  289. package/src/transform/liquid/substitutions.ts +40 -0
  290. package/src/transform/liquid/utils.ts +30 -0
  291. package/src/transform/log.ts +60 -0
  292. package/src/transform/md.ts +123 -0
  293. package/src/transform/plugins/anchors/collect.ts +101 -0
  294. package/src/transform/plugins/anchors/constants.ts +2 -0
  295. package/src/transform/plugins/anchors/index.ts +166 -0
  296. package/src/transform/plugins/changelog/collect.ts +66 -0
  297. package/src/transform/plugins/changelog/index.ts +164 -0
  298. package/src/transform/plugins/changelog/types.ts +10 -0
  299. package/src/transform/plugins/checkbox/checkbox.ts +107 -0
  300. package/src/transform/plugins/checkbox/index.ts +15 -0
  301. package/src/transform/plugins/code.ts +79 -0
  302. package/src/transform/plugins/cut.ts +98 -0
  303. package/src/transform/plugins/deflist.ts +5 -0
  304. package/src/transform/plugins/file/README.md +34 -0
  305. package/src/transform/plugins/file/const.ts +46 -0
  306. package/src/transform/plugins/file/file.ts +82 -0
  307. package/src/transform/plugins/file/index.ts +10 -0
  308. package/src/transform/plugins/images/collect.ts +60 -0
  309. package/src/transform/plugins/images/index.ts +119 -0
  310. package/src/transform/plugins/imsize/const.ts +7 -0
  311. package/src/transform/plugins/imsize/helpers.ts +75 -0
  312. package/src/transform/plugins/imsize/index.ts +14 -0
  313. package/src/transform/plugins/imsize/plugin.ts +214 -0
  314. package/src/transform/plugins/includes/collect.ts +73 -0
  315. package/src/transform/plugins/includes/index.ts +127 -0
  316. package/src/transform/plugins/links/collect.ts +92 -0
  317. package/src/transform/plugins/links/constants.ts +1 -0
  318. package/src/transform/plugins/links/index.ts +218 -0
  319. package/src/transform/plugins/meta.ts +5 -0
  320. package/src/transform/plugins/monospace.ts +141 -0
  321. package/src/transform/plugins/notes.ts +134 -0
  322. package/src/transform/plugins/sup.ts +5 -0
  323. package/src/transform/plugins/table/index.ts +290 -0
  324. package/src/transform/plugins/tabs.ts +3 -0
  325. package/src/transform/plugins/term/constants.ts +1 -0
  326. package/src/transform/plugins/term/index.ts +139 -0
  327. package/src/transform/plugins/term/termDefinitions.ts +177 -0
  328. package/src/transform/plugins/typings.ts +14 -0
  329. package/src/transform/plugins/utils.ts +38 -0
  330. package/src/transform/plugins/video/const.ts +20 -0
  331. package/src/transform/plugins/video/index.ts +134 -0
  332. package/src/transform/plugins/video/parsers.ts +65 -0
  333. package/src/transform/plugins/video/types.ts +27 -0
  334. package/src/transform/plugins/video/utils.ts +24 -0
  335. package/src/transform/plugins.ts +35 -0
  336. package/src/transform/sanitize.ts +596 -0
  337. package/src/transform/title.ts +22 -0
  338. package/src/transform/typings.ts +64 -0
  339. package/src/transform/utils.ts +91 -0
  340. package/src/transform/utilsFS.ts +128 -0
  341. package/src/transform/yfmlint/README.md +48 -0
  342. package/src/transform/yfmlint/index.ts +124 -0
  343. package/src/transform/yfmlint/markdownlint-custom-rule/index.ts +9 -0
  344. package/src/transform/yfmlint/markdownlint-custom-rule/yfm001.ts +36 -0
  345. package/src/transform/yfmlint/markdownlint-custom-rule/yfm002.ts +33 -0
  346. package/src/transform/yfmlint/markdownlint-custom-rule/yfm003.ts +33 -0
  347. package/src/transform/yfmlint/markdownlint-custom-rule/yfm004.ts +27 -0
  348. package/src/transform/yfmlint/markdownlint-custom-rule/yfm005.ts +27 -0
  349. package/src/transform/yfmlint/markdownlint-custom-rule/yfm006.ts +26 -0
  350. package/src/transform/yfmlint/markdownlint-custom-rule/yfm007.ts +28 -0
  351. package/src/transform/yfmlint/markdownlint-custom-rule/yfm008.ts +26 -0
  352. package/src/transform/yfmlint/markdownlint-custom-rule/yfm009.ts +54 -0
  353. package/src/transform/yfmlint/typings.ts +13 -0
  354. package/src/transform/yfmlint/utils.ts +31 -0
  355. package/src/transform/yfmlint/yfmlint.ts +73 -0
@@ -0,0 +1,290 @@
1
+ import StateBlock from 'markdown-it/lib/rules_block/state_block';
2
+ import {MarkdownItPluginCb} from '../typings';
3
+
4
+ const pluginName = 'yfm_table';
5
+ const pipeChar = 0x7c; // |
6
+ const apostropheChar = 0x60; // `
7
+ const hashChar = 0x23; // #
8
+ const backSlashChar = 0x5c; // \
9
+
10
+ const checkCharsOrder = (order: number[], src: string, pos: number) => {
11
+ const currentOrder = [...order];
12
+ const currentSrc = src.slice(pos);
13
+ for (let i = 0; i < currentOrder.length; i++) {
14
+ const rowSymbol = currentSrc.charCodeAt(i);
15
+ const orderSymbol = currentOrder[i];
16
+ if (rowSymbol !== orderSymbol) {
17
+ return false;
18
+ }
19
+ }
20
+ return true;
21
+ };
22
+
23
+ type CheckFn = (src: string, pos: number) => boolean;
24
+
25
+ const codeBlockOrder = [apostropheChar, apostropheChar, apostropheChar];
26
+ const isCodeBlockOrder: CheckFn = (src, pos) => checkCharsOrder(codeBlockOrder, src, pos);
27
+
28
+ const openTableOrder = [hashChar, pipeChar];
29
+ const isOpenTableOrder: CheckFn = (src, pos) => checkCharsOrder(openTableOrder, src, pos);
30
+
31
+ const notEscaped: CheckFn = (src, pos) => src.charCodeAt(pos - 1) !== backSlashChar;
32
+
33
+ const rowStartOrder = [pipeChar, pipeChar];
34
+ const isRowOrder: CheckFn = (src, pos) =>
35
+ checkCharsOrder(rowStartOrder, src, pos) && notEscaped(src, pos);
36
+
37
+ const cellStartOrder = [pipeChar];
38
+ const isCellOrder: CheckFn = (src, pos) =>
39
+ checkCharsOrder(cellStartOrder, src, pos) && notEscaped(src, pos) && !isRowOrder(src, pos);
40
+
41
+ const closeTableOrder = [pipeChar, hashChar];
42
+ const isCloseTableOrder: CheckFn = (src, pos) => checkCharsOrder(closeTableOrder, src, pos);
43
+
44
+ type Stats = {line: number; pos: number};
45
+
46
+ class StateIterator {
47
+ pos: number;
48
+ line: number;
49
+
50
+ private state: StateBlock;
51
+ private lineEnds: number;
52
+
53
+ constructor(state: StateBlock, pos: number, line: number) {
54
+ this.state = state;
55
+ this.line = line;
56
+ this.pos = pos;
57
+ this.lineEnds = this.state.eMarks[this.line];
58
+ }
59
+
60
+ stats(): Stats {
61
+ return {
62
+ line: this.line,
63
+ pos: this.pos,
64
+ };
65
+ }
66
+
67
+ get symbol() {
68
+ return this.state.src[this.pos];
69
+ }
70
+
71
+ next(steps = 1) {
72
+ for (let i = 0; i < steps; i++) {
73
+ this.pos++;
74
+
75
+ if (this.pos > this.lineEnds) {
76
+ this.line++;
77
+ this.pos = this.state.bMarks[this.line] + this.state.tShift[this.line];
78
+ this.lineEnds = this.state.eMarks[this.line];
79
+ }
80
+ }
81
+ }
82
+ }
83
+
84
+ function getTableRows(
85
+ state: StateBlock,
86
+ startPosition: number,
87
+ endPosition: number,
88
+ startLine: number,
89
+ ) {
90
+ let endOfTable = null;
91
+ let tableLevel = 0;
92
+ let currentRow: [Stats, Stats][] = [];
93
+ let colStart: Stats | null = null;
94
+ let rowStart: number | null = null;
95
+
96
+ const iter = new StateIterator(state, startPosition + openTableOrder.length, startLine);
97
+
98
+ const rows: [number, number, typeof currentRow][] = [];
99
+
100
+ let isInsideCode = false;
101
+ let isInsideTable = false;
102
+ const rowMap = new Map();
103
+
104
+ const addRow = () => {
105
+ if (colStart) {
106
+ currentRow.push([colStart, iter.stats()]);
107
+ }
108
+ if (currentRow.length && rowStart) {
109
+ rows.push([rowStart, iter.line, currentRow]);
110
+ }
111
+ currentRow = [];
112
+ colStart = null;
113
+ rowStart = null;
114
+ };
115
+
116
+ while (iter.pos <= endPosition) {
117
+ if (iter.symbol === undefined) {
118
+ break;
119
+ }
120
+
121
+ if (isCodeBlockOrder(state.src, iter.pos)) {
122
+ isInsideCode = !isInsideCode;
123
+ iter.next(codeBlockOrder.length);
124
+ }
125
+
126
+ if (isInsideCode) {
127
+ iter.next();
128
+ continue;
129
+ }
130
+
131
+ if (isOpenTableOrder(state.src, iter.pos)) {
132
+ isInsideTable = true;
133
+ tableLevel++;
134
+ iter.next(openTableOrder.length);
135
+ continue;
136
+ }
137
+
138
+ if (isCloseTableOrder(state.src, iter.pos)) {
139
+ if (tableLevel === 0) {
140
+ addRow();
141
+ iter.next(closeTableOrder.length);
142
+ endOfTable = iter.line + 2;
143
+ break;
144
+ } else {
145
+ isInsideTable = false;
146
+ tableLevel--;
147
+ iter.next(closeTableOrder.length);
148
+ continue;
149
+ }
150
+ }
151
+
152
+ if (isInsideTable) {
153
+ iter.next();
154
+ continue;
155
+ }
156
+
157
+ if (isRowOrder(state.src, iter.pos)) {
158
+ const insideRow = rowMap.get(tableLevel);
159
+ if (insideRow) {
160
+ addRow();
161
+ iter.next(rowStartOrder.length);
162
+ } else {
163
+ iter.next(rowStartOrder.length);
164
+ rowStart = iter.line;
165
+ colStart = iter.stats();
166
+ }
167
+
168
+ rowMap.set(tableLevel, !insideRow);
169
+
170
+ continue;
171
+ }
172
+
173
+ if (isCellOrder(state.src, iter.pos)) {
174
+ if (colStart) {
175
+ currentRow.push([colStart, iter.stats()]);
176
+ }
177
+ iter.next(cellStartOrder.length);
178
+ colStart = iter.stats();
179
+ continue;
180
+ }
181
+
182
+ iter.next();
183
+ }
184
+ return {rows, endOfTable};
185
+ }
186
+
187
+ const yfmTable: MarkdownItPluginCb = (md) => {
188
+ md.block.ruler.before(
189
+ 'code',
190
+ pluginName,
191
+ (state: StateBlock, startLine: number, endLine: number, silent: boolean) => {
192
+ let token;
193
+ const startPosition = state.bMarks[startLine] + state.tShift[startLine];
194
+ const endPosition = state.eMarks[endLine];
195
+
196
+ // #| minimum 2 symbols
197
+ if (endPosition - startPosition < 2) {
198
+ return false;
199
+ }
200
+
201
+ if (!isOpenTableOrder(state.src, startPosition)) {
202
+ return false;
203
+ }
204
+
205
+ if (silent) {
206
+ return true;
207
+ }
208
+
209
+ const {rows, endOfTable} = getTableRows(state, startPosition, endPosition, startLine);
210
+
211
+ if (!endOfTable) {
212
+ token = state.push('__yfm_lint', '', 0);
213
+ token.hidden = true;
214
+ token.map = [startLine, endLine];
215
+ token.attrSet('YFM004', 'true');
216
+ return false;
217
+ }
218
+
219
+ const oldParentLineMax = state.lineMax;
220
+
221
+ state.lineMax = endOfTable;
222
+ state.line = startLine;
223
+
224
+ token = state.push('yfm_table_open', 'table', 1);
225
+ token.map = [startLine, endOfTable];
226
+
227
+ token = state.push('yfm_tbody_open', 'tbody', 1);
228
+ token.map = [startLine + 1, endOfTable - 1];
229
+
230
+ const maxRowLength = Math.max(...rows.map(([, , cols]) => cols.length));
231
+
232
+ for (let i = 0; i < rows.length; i++) {
233
+ const [rowLineStarts, rowLineEnds, cols] = rows[i];
234
+
235
+ const rowLength = cols.length;
236
+
237
+ token = state.push('yfm_tr_open', 'tr', 1);
238
+ token.map = [rowLineStarts, rowLineEnds];
239
+
240
+ for (let j = 0; j < cols.length; j++) {
241
+ const [begin, end] = cols[j];
242
+ token = state.push('yfm_td_open', 'td', 1);
243
+ token.map = [begin.line, end.line];
244
+
245
+ const oldTshift = state.tShift[begin.line];
246
+ const oldEMark = state.eMarks[end.line];
247
+ const oldBMark = state.bMarks[begin.line];
248
+ const oldLineMax = state.lineMax;
249
+
250
+ state.tShift[begin.line] = 0;
251
+ state.bMarks[begin.line] = begin.pos;
252
+ state.eMarks[end.line] = end.pos;
253
+ state.lineMax = end.line + 1;
254
+
255
+ state.md.block.tokenize(state, begin.line, end.line + 1);
256
+
257
+ state.lineMax = oldLineMax;
258
+ state.tShift[begin.line] = oldTshift;
259
+ state.bMarks[begin.line] = oldBMark;
260
+ state.eMarks[end.line] = oldEMark;
261
+
262
+ token = state.push('yfm_td_close', 'td', -1);
263
+ state.tokens[state.tokens.length - 1].map = [end.line, end.line + 1];
264
+ }
265
+
266
+ if (rowLength < maxRowLength) {
267
+ const emptyCellsCount = maxRowLength - rowLength;
268
+ for (let k = 0; k < emptyCellsCount; k++) {
269
+ token = state.push('yfm_td_open', 'td', 1);
270
+ token = state.push('yfm_td_close', 'td', -1);
271
+ }
272
+ }
273
+
274
+ token = state.push('yfm_tr_close', 'tr', -1);
275
+ }
276
+
277
+ token = state.push('yfm_tbody_close', 'tbody', -1);
278
+
279
+ token = state.push('yfm_table_close', 'table', -1);
280
+ state.tokens[state.tokens.length - 1].map = [endOfTable, endOfTable + 1];
281
+
282
+ state.lineMax = oldParentLineMax;
283
+ state.line = endOfTable;
284
+
285
+ return true;
286
+ },
287
+ );
288
+ };
289
+
290
+ export = yfmTable;
@@ -0,0 +1,3 @@
1
+ import {transform} from '@diplodoc/tabs-extension';
2
+
3
+ export = transform({bundle: false});
@@ -0,0 +1 @@
1
+ export const BASIC_TERM_REGEXP = '\\[([^\\[]+)\\](\\(\\*(\\w+)\\))';
@@ -0,0 +1,139 @@
1
+ import StateCore from 'markdown-it/lib/rules_core/state_core';
2
+ import Token from 'markdown-it/lib/token';
3
+
4
+ import {MarkdownItPluginCb} from '../typings';
5
+ import {generateID} from '../utils';
6
+ import {termDefinitions} from './termDefinitions';
7
+ import {BASIC_TERM_REGEXP} from './constants';
8
+
9
+ const term: MarkdownItPluginCb = (md, options) => {
10
+ const escapeRE = md.utils.escapeRE;
11
+ const arrayReplaceAt = md.utils.arrayReplaceAt;
12
+
13
+ const {isLintRun} = options;
14
+ // Don't parse urls that starts with *
15
+ const defaultLinkValidation = md.validateLink;
16
+ md.validateLink = function (url) {
17
+ if (url.startsWith('*')) {
18
+ return false;
19
+ }
20
+
21
+ return defaultLinkValidation(url);
22
+ };
23
+
24
+ function termReplace(state: StateCore) {
25
+ let i, j, l, tokens, token, text, nodes, pos, term, currentToken;
26
+
27
+ const blockTokens = state.tokens;
28
+
29
+ if (!state.env.terms) {
30
+ return;
31
+ }
32
+
33
+ const regTerms = Object.keys(state.env.terms)
34
+ .map((el) => el.substr(1))
35
+ .map(escapeRE)
36
+ .join('|');
37
+ const regText = '\\[([^\\[]+)\\](\\(\\*(' + regTerms + ')\\))';
38
+ const reg = new RegExp(regText, 'g');
39
+
40
+ for (j = 0, l = blockTokens.length; j < l; j++) {
41
+ if (blockTokens[j].type === 'heading_open') {
42
+ while (blockTokens[j].type !== 'heading_close') {
43
+ j++;
44
+ }
45
+ continue;
46
+ }
47
+
48
+ if (blockTokens[j].type !== 'inline') {
49
+ continue;
50
+ }
51
+
52
+ tokens = blockTokens[j].children as Token[];
53
+
54
+ for (i = tokens.length - 1; i >= 0; i--) {
55
+ currentToken = tokens[i];
56
+ if (currentToken.type === 'link_close') {
57
+ while (tokens[i].type !== 'link_open') {
58
+ i--;
59
+ }
60
+ continue;
61
+ }
62
+
63
+ if (!(currentToken.type === 'text')) {
64
+ continue;
65
+ }
66
+
67
+ pos = 0;
68
+ text = currentToken.content;
69
+ reg.lastIndex = 0;
70
+ nodes = [];
71
+
72
+ // Find terms without definitions
73
+ const regexAllTerms = new RegExp(BASIC_TERM_REGEXP, 'gm');
74
+ const uniqueTerms = [
75
+ ...new Set([...text.matchAll(regexAllTerms)].map((el) => `:${el[3]}`)),
76
+ ];
77
+ const notDefinedTerms = uniqueTerms.filter(
78
+ (el) => !Object.keys(state.env.terms).includes(el),
79
+ );
80
+
81
+ if (notDefinedTerms.length && isLintRun) {
82
+ token = new state.Token('__yfm_lint', '', 0);
83
+ token.hidden = true;
84
+ token.map = blockTokens[j].map;
85
+ token.attrSet('YFM007', 'true');
86
+ nodes.push(token);
87
+ }
88
+
89
+ while ((term = reg.exec(text))) {
90
+ const termTitle = term[1];
91
+ const termKey = term[3];
92
+
93
+ if (term.index > 0 || term[1].length > 0) {
94
+ token = new state.Token('text', '', 0);
95
+ token.content = text.slice(pos, term.index);
96
+ nodes.push(token);
97
+ }
98
+
99
+ token = new state.Token('term_open', 'i', 1);
100
+ token.attrSet('class', 'yfm yfm-term_title');
101
+ token.attrSet('term-key', ':' + termKey);
102
+ token.attrSet('aria-describedby', ':' + termKey + '_element');
103
+ token.attrSet('id', generateID());
104
+ nodes.push(token);
105
+
106
+ token = new state.Token('text', '', 0);
107
+ token.content = termTitle;
108
+ nodes.push(token);
109
+
110
+ token = new state.Token('term_close', 'i', -1);
111
+ nodes.push(token);
112
+
113
+ pos = reg.lastIndex;
114
+ }
115
+
116
+ if (!nodes.length) {
117
+ continue;
118
+ }
119
+
120
+ if (pos < text.length) {
121
+ token = new state.Token('text', '', 0);
122
+ token.content = text.slice(pos);
123
+ nodes.push(token);
124
+ }
125
+
126
+ // replace current node
127
+ blockTokens[j].children = tokens = arrayReplaceAt(tokens, i, nodes);
128
+ }
129
+ }
130
+ }
131
+
132
+ md.block.ruler.before('reference', 'termDefinitions', termDefinitions(md, options), {
133
+ alt: ['paragraph', 'reference'],
134
+ });
135
+
136
+ md.core.ruler.after('linkify', 'termReplace', termReplace);
137
+ };
138
+
139
+ export = term;
@@ -0,0 +1,177 @@
1
+ import StateBlock from 'markdown-it/lib/rules_block/state_block';
2
+ import {MarkdownIt} from '../../typings';
3
+ import {MarkdownItPluginOpts} from '../typings';
4
+ import {BASIC_TERM_REGEXP} from './constants';
5
+
6
+ export function termDefinitions(md: MarkdownIt, options: MarkdownItPluginOpts) {
7
+ return (state: StateBlock, startLine: number, endLine: number, silent: boolean) => {
8
+ let ch;
9
+ let labelEnd;
10
+ let pos = state.bMarks[startLine] + state.tShift[startLine];
11
+ let max = state.eMarks[startLine];
12
+
13
+ if (pos + 2 >= max) {
14
+ return false;
15
+ }
16
+
17
+ if (state.src.charCodeAt(pos++) !== 0x5b /* [ */) {
18
+ return false;
19
+ }
20
+ if (state.src.charCodeAt(pos++) !== 0x2a /* * */) {
21
+ return false;
22
+ }
23
+
24
+ const labelStart = pos;
25
+
26
+ for (; pos < max; pos++) {
27
+ ch = state.src.charCodeAt(pos);
28
+ if (ch === 0x5b /* [ */) {
29
+ return false;
30
+ } else if (ch === 0x5d /* ] */) {
31
+ labelEnd = pos;
32
+ break;
33
+ } else if (ch === 0x5c /* \ */) {
34
+ pos++;
35
+ }
36
+ }
37
+
38
+ const newLineReg = new RegExp(/^(\r\n|\r|\n)/);
39
+ const termReg = new RegExp(/^\[\*(\w+)\]:/);
40
+ let currentLine = startLine;
41
+
42
+ // Allow multiline term definition
43
+ for (; currentLine < endLine; currentLine++) {
44
+ const nextLineStart = state.bMarks[currentLine + 1];
45
+ const nextLineEnd = state.eMarks[currentLine + 1];
46
+
47
+ const nextLine =
48
+ nextLineStart === nextLineEnd
49
+ ? state.src[nextLineStart]
50
+ : state.src.slice(nextLineStart, nextLineEnd);
51
+
52
+ if (newLineReg.test(nextLine) || termReg.test(nextLine)) {
53
+ break;
54
+ }
55
+
56
+ state.line = currentLine + 1;
57
+ }
58
+
59
+ max = state.eMarks[currentLine];
60
+
61
+ if (!labelEnd || labelEnd < 0 || state.src.charCodeAt(labelEnd + 1) !== 0x3a /* : */) {
62
+ return false;
63
+ }
64
+
65
+ if (silent) {
66
+ return true;
67
+ }
68
+
69
+ const label = state.src.slice(labelStart, labelEnd).replace(/\\(.)/g, '$1');
70
+ const title = state.src.slice(labelEnd + 2, max).trim();
71
+
72
+ if (label.length === 0 || title.length === 0) {
73
+ return false;
74
+ }
75
+
76
+ return processTermDefinition(
77
+ md,
78
+ options,
79
+ state,
80
+ currentLine,
81
+ startLine,
82
+ endLine,
83
+ label,
84
+ title,
85
+ );
86
+ };
87
+ }
88
+
89
+ function processTermDefinition(
90
+ md: MarkdownIt,
91
+ options: MarkdownItPluginOpts,
92
+ state: StateBlock,
93
+ currentLine: number,
94
+ startLine: number,
95
+ endLine: number,
96
+ label: string,
97
+ title: string,
98
+ ) {
99
+ let token;
100
+
101
+ if (!state.env.terms) {
102
+ state.env.terms = {};
103
+ }
104
+
105
+ const basicTermDefinitionRegexp = new RegExp(BASIC_TERM_REGEXP, 'gm');
106
+ // If term inside definition
107
+
108
+ const {isLintRun} = options;
109
+
110
+ if (basicTermDefinitionRegexp.test(title) && isLintRun) {
111
+ token = new state.Token('__yfm_lint', '', 0);
112
+ token.hidden = true;
113
+ token.map = [currentLine, endLine];
114
+ token.attrSet('YFM008', 'true');
115
+ state.tokens.push(token);
116
+ }
117
+
118
+ // If term definition duplicated
119
+ if (state.env.terms[':' + label] && isLintRun) {
120
+ token = new state.Token('__yfm_lint', '', 0);
121
+ token.hidden = true;
122
+ token.map = [currentLine, endLine];
123
+ token.attrSet('YFM006', 'true');
124
+ state.tokens.push(token);
125
+ state.line = currentLine + 1;
126
+ return true;
127
+ }
128
+
129
+ if (typeof state.env.terms[':' + label] === 'undefined') {
130
+ state.env.terms[':' + label] = title;
131
+ }
132
+
133
+ token = new state.Token('template_open', 'template', 1);
134
+ token.map = [startLine, currentLine + 1];
135
+ token.attrSet('id', ':' + label + '_template');
136
+ token.attrSet('label', label);
137
+
138
+ state.tokens.push(token);
139
+
140
+ token = new state.Token('dfn_open', 'dfn', 1);
141
+ token.attrSet('class', 'yfm yfm-term_dfn');
142
+ token.attrSet('id', ':' + label + '_element');
143
+ token.attrSet('role', 'tooltip');
144
+
145
+ state.tokens.push(token);
146
+
147
+ const titleTokens = md.parse(title, state.env);
148
+
149
+ for (const titleToken of titleTokens) {
150
+ if (titleToken.children?.length) {
151
+ titleToken.content = '';
152
+ }
153
+
154
+ if (!titleToken.map) {
155
+ state.tokens.push(titleToken);
156
+ continue;
157
+ }
158
+
159
+ const [start, end] = titleToken.map;
160
+
161
+ titleToken.map = [start + startLine, end + startLine];
162
+ state.tokens.push(titleToken);
163
+ }
164
+
165
+ token = new state.Token('dfn_close', 'dfn', -1);
166
+
167
+ state.tokens.push(token);
168
+
169
+ token = new state.Token('template_close', 'template', -1);
170
+
171
+ state.tokens.push(token);
172
+
173
+ /** current line links to end of term definition */
174
+ state.line = currentLine + 1;
175
+
176
+ return true;
177
+ }
@@ -0,0 +1,14 @@
1
+ import type {Logger} from '../log';
2
+ import type {MarkdownIt} from '../typings';
3
+
4
+ export interface MarkdownItPluginOpts {
5
+ path: string;
6
+ log: Logger;
7
+ lang: 'ru' | 'en';
8
+ root: string;
9
+ isLintRun: boolean;
10
+ }
11
+
12
+ export type MarkdownItPluginCb<T extends {} = {}> = {
13
+ (md: MarkdownIt, opts: T & MarkdownItPluginOpts): void;
14
+ };
@@ -0,0 +1,38 @@
1
+ import {bold} from 'chalk';
2
+ import {Logger} from '../log';
3
+ import {platform} from 'process';
4
+ import Token from 'markdown-it/lib/token';
5
+
6
+ export type MatchTokenFunction = (
7
+ tokens: Token[],
8
+ idx: number,
9
+ ) => boolean | null | RegExpMatchArray;
10
+
11
+ export const nestedCloseTokenIdxFactory =
12
+ (tokenName: string, matchOpenToken: MatchTokenFunction, matchCloseToken: MatchTokenFunction) =>
13
+ (tokens: Token[], idx: number, path: string, log: Logger) => {
14
+ let level = 0;
15
+ let i = idx;
16
+ while (i < tokens.length) {
17
+ if (matchOpenToken(tokens, i)) {
18
+ level++;
19
+ } else if (matchCloseToken(tokens, i)) {
20
+ if (level === 0) {
21
+ return i;
22
+ }
23
+ level--;
24
+ }
25
+
26
+ i++;
27
+ }
28
+
29
+ log.error(`${tokenName} must be closed${path ? ` in ${bold(path)}` : ''}`);
30
+
31
+ return null;
32
+ };
33
+
34
+ export const сarriage = platform === 'win32' ? '\r\n' : '\n';
35
+
36
+ export function generateID() {
37
+ return Math.random().toString(36).substr(2, 8);
38
+ }
@@ -0,0 +1,20 @@
1
+ import type {VideoFullOptions} from './types';
2
+ import {videoUrl} from './utils';
3
+
4
+ /** Supported services */
5
+ export enum VideoService {
6
+ YouTube = 'youtube',
7
+ Vimeo = 'vimeo',
8
+ Vine = 'vine',
9
+ Prezi = 'prezi',
10
+ Osf = 'osf',
11
+ }
12
+
13
+ export const defaults: VideoFullOptions = {
14
+ url: videoUrl,
15
+ youtube: {width: 640, height: 390},
16
+ vimeo: {width: 500, height: 281},
17
+ vine: {width: 600, height: 600, embed: 'simple'},
18
+ prezi: {width: 550, height: 400},
19
+ osf: {width: '100%', height: '100%'},
20
+ };