@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
package/lib/log.js ADDED
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.log = exports.LogLevels = void 0;
4
+ const chalk_1 = require("chalk");
5
+ var LogLevels;
6
+ (function (LogLevels) {
7
+ LogLevels["INFO"] = "info";
8
+ LogLevels["WARN"] = "warn";
9
+ LogLevels["ERROR"] = "error";
10
+ LogLevels["DISABLED"] = "disabled";
11
+ })(LogLevels = exports.LogLevels || (exports.LogLevels = {}));
12
+ const problems = {
13
+ [LogLevels.INFO]: [],
14
+ [LogLevels.WARN]: [],
15
+ [LogLevels.ERROR]: [],
16
+ [LogLevels.DISABLED]: [],
17
+ };
18
+ function createLogger(type) {
19
+ const formatter = {
20
+ [LogLevels.INFO]: (msg) => `${(0, chalk_1.green)('INFO')} ${msg}`,
21
+ [LogLevels.WARN]: (msg) => `${(0, chalk_1.yellow)('WARN')} ${msg}`,
22
+ [LogLevels.ERROR]: (msg) => `${(0, chalk_1.red)('ERR')} ${msg}`,
23
+ };
24
+ return function log(msg) {
25
+ const problem = formatter[type](msg);
26
+ if (!problems[type].includes(problem)) {
27
+ problems[type].push(problem);
28
+ }
29
+ };
30
+ }
31
+ exports.log = {
32
+ [LogLevels.INFO]: createLogger(LogLevels.INFO),
33
+ [LogLevels.WARN]: createLogger(LogLevels.WARN),
34
+ [LogLevels.ERROR]: createLogger(LogLevels.ERROR),
35
+ LogLevels,
36
+ get: () => problems,
37
+ add: (logs) => {
38
+ problems[LogLevels.INFO] = problems[LogLevels.INFO].concat(logs[LogLevels.INFO]);
39
+ problems[LogLevels.WARN] = problems[LogLevels.WARN].concat(logs[LogLevels.WARN]);
40
+ problems[LogLevels.ERROR] = problems[LogLevels.ERROR].concat(logs[LogLevels.ERROR]);
41
+ },
42
+ clear: () => {
43
+ problems[LogLevels.INFO] = [];
44
+ problems[LogLevels.WARN] = [];
45
+ problems[LogLevels.ERROR] = [];
46
+ },
47
+ isEmpty: () => {
48
+ return !(problems[LogLevels.INFO].length ||
49
+ problems[LogLevels.WARN].length ||
50
+ problems[LogLevels.ERROR].length);
51
+ },
52
+ };
53
+ exports.default = exports.log;
54
+ //# sourceMappingURL=log.js.map
package/lib/log.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../src/transform/log.ts"],"names":[],"mappings":";;;AAAA,iCAAyC;AAEzC,IAAY,SAKX;AALD,WAAY,SAAS;IACjB,0BAAa,CAAA;IACb,0BAAa,CAAA;IACb,4BAAe,CAAA;IACf,kCAAqB,CAAA;AACzB,CAAC,EALW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAKpB;AAED,MAAM,QAAQ,GAAgC;IAC1C,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE;IACpB,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE;IACpB,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,EAAE;IACrB,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE;CAC3B,CAAC;AAEF,SAAS,YAAY,CAAC,IAAe;IACjC,MAAM,SAAS,GAA0C;QACrD,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAA,aAAK,EAAC,MAAM,CAAC,IAAI,GAAG,EAAE;QACpD,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAA,cAAM,EAAC,MAAM,CAAC,IAAI,GAAG,EAAE;QACrD,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAA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,IAAI,CAAC,GAAG,EAAE,CAAC;QAC9B,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;QAC9B,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;IACnC,CAAC;IACD,OAAO,EAAE,GAAG,EAAE;QACV,OAAO,CAAC,CACJ,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,MAAM;YAC/B,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,MAAM;YAC/B,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,MAAM,CACnC,CAAC;IACN,CAAC;CACJ,CAAC;AAIF,kBAAe,WAAG,CAAC"}
package/lib/md.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { OptionsType } from './typings';
2
+ import type Token from 'markdown-it/lib/token';
3
+ declare function initMarkdownit(options: OptionsType): {
4
+ parse: (input: string) => Token[];
5
+ compile: (tokens: Token[]) => string;
6
+ env: {
7
+ title?: string | undefined;
8
+ headings: import("./typings").Heading[];
9
+ assets?: unknown[] | undefined;
10
+ meta?: object | undefined;
11
+ changelogs?: import("./plugins/changelog/types").ChangelogItem[] | undefined;
12
+ };
13
+ };
14
+ export = initMarkdownit;
package/lib/md.js ADDED
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ const markdown_it_1 = __importDefault(require("markdown-it"));
17
+ const plugins_1 = __importDefault(require("./plugins"));
18
+ const log_1 = require("./log");
19
+ const highlight_1 = __importDefault(require("./highlight"));
20
+ const markdown_it_attrs_1 = __importDefault(require("markdown-it-attrs"));
21
+ const title_1 = __importDefault(require("./title"));
22
+ const headings_1 = __importDefault(require("./headings"));
23
+ const sanitize_1 = __importDefault(require("./sanitize"));
24
+ function initMarkdownit(options) {
25
+ const { allowHTML = false, linkify = false, breaks = true, highlightLangs = {} } = options;
26
+ const highlight = (0, highlight_1.default)(highlightLangs);
27
+ const md = new markdown_it_1.default({ html: allowHTML, linkify, highlight, breaks });
28
+ const env = {
29
+ // TODO: move md.meta directly to env
30
+ get meta() {
31
+ return md.meta;
32
+ },
33
+ set meta(value) {
34
+ md.meta = value;
35
+ },
36
+ // TODO: move md.assets directly to env
37
+ get assets() {
38
+ return md.assets;
39
+ },
40
+ set assets(value) {
41
+ md.assets = value;
42
+ },
43
+ headings: [],
44
+ title: '',
45
+ };
46
+ initPlugins(md, options);
47
+ const parse = initParser(md, options, env);
48
+ const compile = initCompiler(md, options, env);
49
+ return { parse, compile, env };
50
+ }
51
+ function initPlugins(md, options) {
52
+ const { vars = {}, path, extractTitle, conditionsInCode = false, disableLiquid = false, linkify = false, linkifyTlds, leftDelimiter = '{', rightDelimiter = '}', plugins = plugins_1.default } = options, customOptions = __rest(options, ["vars", "path", "extractTitle", "conditionsInCode", "disableLiquid", "linkify", "linkifyTlds", "leftDelimiter", "rightDelimiter", "plugins"]);
53
+ const pluginOptions = Object.assign(Object.assign({}, customOptions), { conditionsInCode,
54
+ vars,
55
+ path,
56
+ extractTitle,
57
+ disableLiquid,
58
+ log: log_1.log });
59
+ // Need for ids of headers
60
+ md.use(markdown_it_attrs_1.default, { leftDelimiter, rightDelimiter });
61
+ plugins.forEach((plugin) => md.use(plugin, pluginOptions));
62
+ if (linkify && linkifyTlds) {
63
+ md.linkify.tlds(linkifyTlds, true);
64
+ }
65
+ }
66
+ function initParser(md, options, env) {
67
+ return (input) => {
68
+ const { extractTitle: extractTitleOption, needTitle, needFlatListHeadings = false } = options;
69
+ let tokens = md.parse(input, env);
70
+ if (extractTitleOption) {
71
+ const { title, tokens: slicedTokens, titleTokens } = (0, title_1.default)(tokens);
72
+ tokens = slicedTokens;
73
+ // title tokens include other tokens that need to be transformed
74
+ if (titleTokens.length > 1) {
75
+ env.title = md.renderer.render(titleTokens, md.options, env);
76
+ }
77
+ else {
78
+ env.title = title;
79
+ }
80
+ }
81
+ if (needTitle) {
82
+ env.title = (0, title_1.default)(tokens).title;
83
+ }
84
+ env.headings = (0, headings_1.default)(tokens, needFlatListHeadings);
85
+ return tokens;
86
+ };
87
+ }
88
+ function initCompiler(md, options, env) {
89
+ const { needToSanitizeHtml = true, sanitizeOptions } = options;
90
+ return (tokens) => {
91
+ const html = md.renderer.render(tokens, md.options, env);
92
+ return needToSanitizeHtml ? (0, sanitize_1.default)(html, sanitizeOptions) : html;
93
+ };
94
+ }
95
+ module.exports = initMarkdownit;
96
+ //# sourceMappingURL=md.js.map
package/lib/md.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"md.js","sourceRoot":"","sources":["../src/transform/md.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,8DAA4C;AAC5C,wDAAuC;AACvC,+BAA0B;AAC1B,4DAAwC;AACxC,0EAAsC;AACtC,oDAAmC;AACnC,0DAAqC;AACrC,0DAAsC;AAEtC,SAAS,cAAc,CAAC,OAAoB;IACxC,MAAM,EAAC,SAAS,GAAG,KAAK,EAAE,OAAO,GAAG,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,cAAc,GAAG,EAAE,EAAC,GAAG,OAAO,CAAC;IAEzF,MAAM,SAAS,GAAG,IAAA,mBAAa,EAAC,cAAc,CAAC,CAAC;IAChD,MAAM,EAAE,GAAG,IAAI,qBAAiB,CAAC,EAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM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EAAE,OAAoB,EAAE,GAAY;IACpE,MAAM,EAAC,kBAAkB,GAAG,IAAI,EAAE,eAAe,EAAC,GAAG,OAAO,CAAC;IAE7D,OAAO,CAAC,MAAe,EAAE,EAAE;QACvB,MAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAEzD,OAAO,kBAAkB,CAAC,CAAC,CAAC,IAAA,kBAAY,EAAC,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3E,CAAC,CAAC;AACN,CAAC;AAED,iBAAS,cAAc,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { MarkdownItPluginOpts } from '../typings';
2
+ declare const collect: (input: string, options: MarkdownItPluginOpts & {
3
+ singlePage: boolean;
4
+ }) => string | undefined;
5
+ export = collect;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const lodash_1 = __importDefault(require("lodash"));
6
+ const path_1 = require("path");
7
+ const utilsFS_1 = require("../../utilsFS");
8
+ const utils_1 = require("../../utils");
9
+ const constants_1 = require("./constants");
10
+ const utils_2 = require("../utils");
11
+ const slugify = require('slugify');
12
+ /* eslint-disable max-len */
13
+ /* If the singlePage option is passed in the options:
14
+ * - replace the default anchor and custom anchors with anchors with file at the beginning
15
+ * - increase the level of headers,
16
+ * - add page anchor to the first matched header
17
+ * Example for file index.md:
18
+ * Before: # Title {#CustomAnchor} {#custom-anchor}
19
+ * ## Subtitle
20
+ * After: ## Title {data-original-article=/index} {#_index} {#_index_title} {#_index_CustomAnchor} {#_index_custom-anchor}
21
+ * ## Subtitle {#_index_subtitle}
22
+ * */
23
+ const collect = (input, options) => {
24
+ const { root, path, singlePage } = options;
25
+ if (!singlePage || path.includes(`_includes${path_1.sep}`)) {
26
+ return;
27
+ }
28
+ const currentPath = (0, utilsFS_1.resolveRelativePath)(root, path);
29
+ const pageId = (0, utilsFS_1.getSinglePageAnchorId)({ root, currentPath });
30
+ let needToSetPageId = true;
31
+ let needToSetOriginalPathAttr = true;
32
+ const lines = input.split(utils_2.сarriage);
33
+ let i = 0;
34
+ const HEADER_LINK_REGEXP = /^(?<headerLevel>#+)\s(?<headerContent>.+)$/i;
35
+ while (i < lines.length) {
36
+ const line = lines[i];
37
+ const headerMatch = line.match(HEADER_LINK_REGEXP);
38
+ if (!headerMatch) {
39
+ i++;
40
+ continue;
41
+ }
42
+ const { headerLevel, headerContent } = headerMatch.groups;
43
+ let newHeaderContent = headerContent;
44
+ const newCustomHeaders = [];
45
+ while (constants_1.CUSTOM_ID_REGEXP.test(newHeaderContent)) {
46
+ newHeaderContent = newHeaderContent.replace(constants_1.CUSTOM_ID_REGEXP, (match, customId) => {
47
+ if (match === constants_1.CUSTOM_ID_EXCEPTION) {
48
+ return match;
49
+ }
50
+ newCustomHeaders.push(`${pageId}_${customId}`);
51
+ return '';
52
+ });
53
+ }
54
+ newHeaderContent = newHeaderContent.trim();
55
+ const slugifiedTitle = slugify(newHeaderContent, { lower: true });
56
+ newCustomHeaders.push(`${pageId}_${slugifiedTitle}`);
57
+ if (needToSetPageId) {
58
+ newCustomHeaders.push(pageId);
59
+ needToSetPageId = false;
60
+ }
61
+ const newCustomHeadersStr = lodash_1.default.chain(newCustomHeaders)
62
+ .uniq()
63
+ .map((id) => {
64
+ return `{${id}}`;
65
+ })
66
+ .value()
67
+ .join(' ');
68
+ const baseHeaderSyntax = `${headerLevel}# ${newHeaderContent}`;
69
+ lines[i] = `${baseHeaderSyntax} ${newCustomHeadersStr}`;
70
+ if (needToSetOriginalPathAttr) {
71
+ const originalArticleHref = (0, utils_1.transformLinkToOriginalArticle)({ root, currentPath });
72
+ lines[i] = `${baseHeaderSyntax} {data-original-article=${originalArticleHref}} ${newCustomHeadersStr}`;
73
+ needToSetOriginalPathAttr = false;
74
+ }
75
+ i++;
76
+ }
77
+ // eslint-disable-next-line consistent-return
78
+ return lines.join(utils_2.сarriage);
79
+ };
80
+ module.exports = collect;
81
+ //# sourceMappingURL=collect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collect.js","sourceRoot":"","sources":["../../../src/transform/plugins/anchors/collect.ts"],"names":[],"mappings":";;;;AAAA,oDAAuB;AACvB,+BAAyB;AAEzB,2CAAyE;AACzE,uCAA2D;AAC3D,2CAAkE;AAClE,oCAAkC;AAGlC,MAAM,OAAO,GAAsC,OAAO,CAAC,SAAS,CAAC,CAAC;AAEtE,4BAA4B;AAC5B;;;;;;;;;KASK;AACL,MAAM,OAAO,GAAG,CAAC,KAAa,EAAE,OAAqD,EAAE,EAAE;IACrF,MAAM,EAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAC,GAAG,OAAO,CAAC;IAEzC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,UAAG,EAAE,CAAC,EAAE;QACjD,OAAO;KACV;IAED,MAAM,WAAW,GAAG,IAAA,6BAAmB,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACpD,MAAM,MAAM,GAAG,IAAA,+BAAqB,EAAC,EAAC,IAAI,EAAE,WAAW,EAAC,CAAC,CAAC;IAC1D,IAAI,eAAe,GAAG,IAAI,CAAC;IAC3B,IAAI,yBAAyB,GAAG,IAAI,CAAC;IACrC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,gBAAQ,CAAC,CAAC;IACpC,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,MAAM,kBAAkB,GAAG,6CAA6C,CAAC;IAEzE,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE;QACrB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAEnD,IAAI,CAAC,WAAW,EAAE;YACd,CAAC,E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mB,EAAE,CAAC;QAExD,IAAI,yBAAyB,EAAE;YAC3B,MAAM,mBAAmB,GAAG,IAAA,sCAA8B,EAAC,EAAC,IAAI,EAAE,WAAW,EAAC,CAAC,CAAC;YAChF,KAAK,CACD,CAAC,CACJ,GAAG,GAAG,gBAAgB,2BAA2B,mBAAmB,KAAK,mBAAmB,EAAE,CAAC;YAEhG,yBAAyB,GAAG,KAAK,CAAC;SACrC;QAED,CAAC,EAAE,CAAC;KACP;IAED,6CAA6C;IAC7C,OAAO,KAAK,CAAC,IAAI,CAAC,gBAAQ,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,iBAAS,OAAO,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const CUSTOM_ID_REGEXP: RegExp;
2
+ export declare const CUSTOM_ID_EXCEPTION = "[{#T}]";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CUSTOM_ID_EXCEPTION = exports.CUSTOM_ID_REGEXP = void 0;
4
+ exports.CUSTOM_ID_REGEXP = /\[?{ ?#(\S+) ?}]?/g;
5
+ exports.CUSTOM_ID_EXCEPTION = '[{#T}]';
6
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/transform/plugins/anchors/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG,oBAAoB,CAAC;AACxC,QAAA,mBAAmB,GAAG,QAAQ,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { MarkdownItPluginCb } from '../typings';
2
+ interface Options {
3
+ extractTitle?: boolean;
4
+ supportGithubAnchors?: boolean;
5
+ }
6
+ declare const index: MarkdownItPluginCb<Options>;
7
+ export = index;
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const chalk_1 = require("chalk");
6
+ const github_slugger_1 = __importDefault(require("github-slugger"));
7
+ const utils_1 = require("../../utils");
8
+ const constants_1 = require("./constants");
9
+ const utils_2 = require("markdown-it/lib/common/utils");
10
+ const slugify = require('slugify');
11
+ function createLinkTokens(state, id, title, setId = false) {
12
+ const open = new state.Token('link_open', 'a', 1);
13
+ const close = new state.Token('link_close', 'a', -1);
14
+ if (setId) {
15
+ open.attrSet('id', id);
16
+ }
17
+ open.attrSet('href', '#' + id);
18
+ open.attrSet('class', 'yfm-anchor');
19
+ open.attrSet('aria-hidden', 'true');
20
+ // SEO: render invisible heading title because link must have text content.
21
+ const hiddenDesc = new state.Token('anchor_hidden_desc', '', 0);
22
+ hiddenDesc.content = title;
23
+ return [open, hiddenDesc, close];
24
+ }
25
+ const getCustomIds = (content) => {
26
+ const ids = [];
27
+ content.replace(constants_1.CUSTOM_ID_REGEXP, (match, customId) => {
28
+ if (match !== constants_1.CUSTOM_ID_EXCEPTION) {
29
+ ids.push(customId);
30
+ }
31
+ return '';
32
+ });
33
+ return ids.length ? ids : null;
34
+ };
35
+ const removeCustomId = (content) => {
36
+ if (constants_1.CUSTOM_ID_REGEXP.test(content)) {
37
+ return content
38
+ .replace(constants_1.CUSTOM_ID_REGEXP, (match) => {
39
+ if (match === constants_1.CUSTOM_ID_EXCEPTION) {
40
+ return match;
41
+ }
42
+ return '';
43
+ })
44
+ .trim();
45
+ }
46
+ return content;
47
+ };
48
+ const removeCustomIds = (token) => {
49
+ var _a;
50
+ token.content = removeCustomId(token.content);
51
+ (_a = token.children) === null || _a === void 0 ? void 0 : _a.forEach((child) => {
52
+ child.content = removeCustomId(child.content);
53
+ });
54
+ };
55
+ const index = (md, { extractTitle, path, log, supportGithubAnchors }) => {
56
+ const plugin = (state) => {
57
+ /* Do not use the plugin if it is included in the file */
58
+ if (state.env.includes && state.env.includes.length) {
59
+ return;
60
+ }
61
+ const ids = {};
62
+ const tokens = state.tokens;
63
+ let i = 0;
64
+ const slugger = new github_slugger_1.default();
65
+ while (i < tokens.length) {
66
+ const token = tokens[i];
67
+ const isHeading = token.type === 'heading_open';
68
+ if (isHeading) {
69
+ const { title, level } = (0, utils_1.headingInfo)(tokens, i);
70
+ const inlineToken = tokens[i + 1];
71
+ let id = token.attrGet('id');
72
+ let ghId;
73
+ if (!title) {
74
+ log.warn(`Header without title${path ? ` in ${(0, chalk_1.bold)(path)}` : ''}`);
75
+ }
76
+ if (level < 2 && extractTitle) {
77
+ i += 3;
78
+ continue;
79
+ }
80
+ const customIds = getCustomIds(inlineToken.content);
81
+ if (customIds) {
82
+ id = customIds[0];
83
+ removeCustomIds(tokens[i + 1]);
84
+ }
85
+ else {
86
+ id = slugify(title, {
87
+ lower: true,
88
+ remove: /[*+~.()'"!:@`ь]/g,
89
+ });
90
+ ghId = slugger.slug(title);
91
+ }
92
+ token.attrSet('id', id);
93
+ if (ids[id]) {
94
+ id = id + ids[id]++;
95
+ token.attrSet('id', id);
96
+ }
97
+ else {
98
+ ids[id] = 1;
99
+ }
100
+ const allAnchorIds = customIds ? customIds : [id];
101
+ const anchorTitle = removeCustomId(title).replace(/`/g, '');
102
+ allAnchorIds.forEach((customId) => {
103
+ var _a, _b;
104
+ const setId = id !== customId;
105
+ const linkTokens = createLinkTokens(state, customId, anchorTitle, setId);
106
+ (_a = inlineToken.children) === null || _a === void 0 ? void 0 : _a.unshift(...linkTokens);
107
+ if (supportGithubAnchors) {
108
+ const ghLinkTokens = createLinkTokens(state, ghId, anchorTitle, true);
109
+ (_b = inlineToken.children) === null || _b === void 0 ? void 0 : _b.unshift(...ghLinkTokens);
110
+ }
111
+ });
112
+ i += 3;
113
+ continue;
114
+ }
115
+ i++;
116
+ }
117
+ };
118
+ try {
119
+ md.core.ruler.after('includes', 'anchors', plugin);
120
+ }
121
+ catch (_a) {
122
+ try {
123
+ md.core.ruler.after('curly_attributes', 'anchors', plugin);
124
+ }
125
+ catch (_b) {
126
+ md.core.ruler.push('anchors', plugin);
127
+ }
128
+ }
129
+ md.renderer.rules.anchor_hidden_desc = function (tokens, index) {
130
+ return '<span class="visually-hidden">' + (0, utils_2.escapeHtml)(tokens[index].content) + '</span>';
131
+ };
132
+ };
133
+ module.exports = index;
134
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transform/plugins/anchors/index.ts"],"names":[],"mappings":";;;;AAAA,iCAA2B;AAC3B,oEAA2C;AAE3C,uCAAwC;AACxC,2CAAkE;AAGlE,wDAAwD;AAGxD,MAAM,OAAO,GAAsC,OAAO,CAAC,SAAS,CAAC,CAAC;AAEtE,SAAS,gBAAgB,CAAC,KAAgB,EAAE,EAAU,EAAE,KAAa,EAAE,KAAK,GAAG,KAAK;IAChF,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;IAClD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IAErD,IAAI,KAAK,EAAE;QACP,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;KAC1B;IACD,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,GAAG,EAAE,CAAC,CAAC;IAC/B,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACpC,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IAEpC,2EAA2E;IAC3E,MAAM,UAAU,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC,oBAAoB,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAEhE,UAAU,CAAC,OAAO,GAAG,KAAK,CAAC;IAE3B,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,YAAY,GAAG,CAAC,OAAe,EAAE,EAAE;IACrC,MAAM,GAAG,GAAa,EAAE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AAC;IAEF,IAAI;QACA,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;KACtD;IAAC,WAAM;QACJ,IAAI;YACA,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,kBAAkB,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;SAC9D;QAAC,WAAM;YACJ,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;SACzC;KACJ;IAED,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,kBAAkB,GAAG,UAAU,MAAM,EAAE,KAAK;QAC1D,OAAO,gCAAgC,GAAG,IAAA,kBAAU,EAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAC5F,CAAC,CAAC;AACN,CAAC,CAAC;AAEF,iBAAS,KAAK,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { ChangelogItem } from './types';
2
+ import { MarkdownItPluginOpts } from '../typings';
3
+ declare type Options = Pick<MarkdownItPluginOpts, 'path' | 'log'> & {
4
+ changelogs?: ChangelogItem[];
5
+ extractChangelogs?: boolean;
6
+ };
7
+ declare const collect: (input: string, { path: filepath, log, changelogs, extractChangelogs }: Options) => string;
8
+ export = collect;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const chalk_1 = require("chalk");
6
+ const md_1 = __importDefault(require("../../md"));
7
+ const index_1 = __importDefault(require("./index"));
8
+ const imsize_1 = __importDefault(require("../imsize"));
9
+ const BLOCK_START = '{% changelog %}';
10
+ const BLOCK_END = '{% endchangelog %}\n';
11
+ function parseChangelogs(str, path) {
12
+ const { parse, compile, env } = (0, md_1.default)({
13
+ plugins: [index_1.default, imsize_1.default],
14
+ extractChangelogs: true,
15
+ path,
16
+ });
17
+ compile(parse(str));
18
+ return env.changelogs || [];
19
+ }
20
+ const collect = (input, { path: filepath, log, changelogs, extractChangelogs }) => {
21
+ let result = input;
22
+ let lastPos = 0;
23
+ const rawChanges = [];
24
+ // eslint-disable-next-line no-constant-condition
25
+ while (true) {
26
+ const pos = result.indexOf(BLOCK_START, lastPos);
27
+ lastPos = pos;
28
+ if (pos === -1) {
29
+ break;
30
+ }
31
+ const endPos = result.indexOf(BLOCK_END, pos + BLOCK_START.length);
32
+ if (endPos === -1) {
33
+ log.error(`Changelog block must be closed${filepath ? ` in ${(0, chalk_1.bold)(filepath)}` : ''}`);
34
+ break;
35
+ }
36
+ const change = result.slice(pos, endPos + BLOCK_END.length);
37
+ rawChanges.push(change);
38
+ result = result.slice(0, pos) + result.slice(endPos + BLOCK_END.length);
39
+ }
40
+ if (rawChanges.length && changelogs && extractChangelogs) {
41
+ const parsedChangelogs = parseChangelogs(rawChanges.join('\n\n'), filepath);
42
+ if (parsedChangelogs.length !== rawChanges.length) {
43
+ log.error(`Parsed cahngelogs less than expected${filepath ? ` in ${(0, chalk_1.bold)(filepath)}` : ''}`);
44
+ }
45
+ changelogs.push(...parsedChangelogs);
46
+ }
47
+ return result;
48
+ };
49
+ module.exports = collect;
50
+ //# sourceMappingURL=collect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collect.js","sourceRoot":"","sources":["../../../src/transform/plugins/changelog/collect.ts"],"names":[],"mappings":";;;;AAAA,iCAA2B;AAE3B,kDAAsC;AACtC,oDAAsC;AACtC,uDAA+B;AAG/B,MAAM,WAAW,GAAG,iBAAiB,CAAC;AACtC,MAAM,SAAS,GAAG,sBAAsB,CAAC;AAEzC,SAAS,eAAe,CAAC,GAAW,EAAE,IAAa;IAC/C,MAAM,EAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAC,GAAG,IAAA,YAAc,EAAC;QACzC,OAAO,EAAE,CAAC,eAAe,EAAE,gBAAM,CAAC;QAClC,iBAAiB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I,UAAU,IAAI,iBAAiB,EAAE;QACtD,MAAM,gBAAgB,GAAG,eAAe,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC;QAC5E,IAAI,gBAAgB,CAAC,MAAM,KAAK,UAAU,CAAC,MAAM,EAAE;YAC/C,GAAG,CAAC,KAAK,CACL,uCAAuC,QAAQ,CAAC,CAAC,CAAC,OAAO,IAAA,YAAI,EAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CACnF,CAAC;SACL;QACD,UAAU,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,CAAC;KACxC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC;AAEF,iBAAS,OAAO,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { MarkdownItPluginCb } from '../typings';
2
+ interface Options {
3
+ extractChangelogs?: boolean;
4
+ }
5
+ declare const changelog: MarkdownItPluginCb<Options>;
6
+ export = changelog;
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const chalk_1 = require("chalk");
6
+ const js_yaml_1 = __importDefault(require("js-yaml"));
7
+ const CHANGELOG_OPEN_RE = /^\{% changelog %}/;
8
+ const CHANGELOG_CLOSE_RE = /^\{% endchangelog %}/;
9
+ function isOpenToken(tokens, i) {
10
+ return (tokens[i].type === 'paragraph_open' &&
11
+ tokens[i + 1].type === 'inline' &&
12
+ tokens[i + 2].type === 'paragraph_close' &&
13
+ CHANGELOG_OPEN_RE.test(tokens[i + 1].content));
14
+ }
15
+ function isCloseToken(tokens, i) {
16
+ var _a;
17
+ return (((_a = tokens[i]) === null || _a === void 0 ? void 0 : _a.type) === 'paragraph_open' &&
18
+ tokens[i + 1].type === 'inline' &&
19
+ tokens[i + 2].type === 'paragraph_close' &&
20
+ CHANGELOG_CLOSE_RE.test(tokens[i + 1].content));
21
+ }
22
+ function isTitle(tokens, i = 0) {
23
+ return (tokens[i].type === 'heading_open' &&
24
+ tokens[i + 1].type === 'inline' &&
25
+ tokens[i + 2].type === 'heading_close');
26
+ }
27
+ function isImageParagraph(tokens, i = 0) {
28
+ var _a;
29
+ return (tokens[i].type === 'paragraph_open' &&
30
+ tokens[i + 1].type === 'inline' &&
31
+ tokens[i + 2].type === 'paragraph_close' &&
32
+ ((_a = tokens[i + 1].children) === null || _a === void 0 ? void 0 : _a.some((t) => t.type === 'image')));
33
+ }
34
+ function parseBody(tokens, state) {
35
+ var _a, _b;
36
+ const { md, env } = state;
37
+ const metadataToken = tokens.shift();
38
+ if ((metadataToken === null || metadataToken === void 0 ? void 0 : metadataToken.type) !== 'fence') {
39
+ throw new Error('Metadata tag not found');
40
+ }
41
+ let metadata = {};
42
+ const rawMetadata = js_yaml_1.default.load(metadataToken.content, {
43
+ schema: js_yaml_1.default.JSON_SCHEMA,
44
+ });
45
+ if (rawMetadata && typeof rawMetadata === 'object') {
46
+ metadata = rawMetadata;
47
+ }
48
+ if (!isTitle(tokens)) {
49
+ throw new Error('Title tag not found');
50
+ }
51
+ const title = tokens.splice(0, 3)[1].content;
52
+ let image;
53
+ if (isImageParagraph(tokens)) {
54
+ const paragraphTokens = tokens.splice(0, 3);
55
+ const imageToken = (_b = (_a = paragraphTokens[1]) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b.find((token) => token.type === 'image');
56
+ if (imageToken) {
57
+ const width = Number(imageToken.attrGet('width'));
58
+ const height = Number(imageToken.attrGet('height'));
59
+ let ratio;
60
+ if (Number.isFinite(width) && Number.isFinite(height)) {
61
+ ratio = height / width;
62
+ }
63
+ let alt = imageToken.attrGet('title') || '';
64
+ if (!alt && imageToken.children) {
65
+ alt = md.renderer.renderInlineAsText(imageToken.children, md.options, env);
66
+ }
67
+ image = {
68
+ src: imageToken.attrGet('src'),
69
+ alt,
70
+ ratio,
71
+ };
72
+ }
73
+ }
74
+ const description = md.renderer.render(tokens, md.options, env);
75
+ return Object.assign(Object.assign({}, metadata), { title,
76
+ image,
77
+ description });
78
+ }
79
+ const changelog = function (md, { extractChangelogs, log, path }) {
80
+ const plugin = (state) => {
81
+ const { tokens, env } = state;
82
+ for (let i = 0, len = tokens.length; i < len; i++) {
83
+ const isOpen = isOpenToken(tokens, i);
84
+ if (!isOpen)
85
+ continue;
86
+ const openAt = i;
87
+ let isCloseFound = false;
88
+ while (i < len) {
89
+ i++;
90
+ if (isCloseToken(tokens, i)) {
91
+ isCloseFound = true;
92
+ break;
93
+ }
94
+ }
95
+ if (!isCloseFound) {
96
+ log.error(`Changelog close tag in not found: ${(0, chalk_1.bold)(path)}`);
97
+ break;
98
+ }
99
+ const closeAt = i + 2;
100
+ if (env && extractChangelogs) {
101
+ const content = tokens.slice(openAt, closeAt + 1);
102
+ // cut open
103
+ content.splice(0, 3);
104
+ // cut close
105
+ content.splice(-3);
106
+ try {
107
+ const change = parseBody(content, state);
108
+ if (!env.changelogs) {
109
+ env.changelogs = [];
110
+ }
111
+ env.changelogs.push(change);
112
+ }
113
+ catch (err) {
114
+ log.error(`Changelog error: ${err.message} in ${(0, chalk_1.bold)(path)}`);
115
+ continue;
116
+ }
117
+ }
118
+ tokens.splice(openAt, closeAt + 1 - openAt);
119
+ len = tokens.length;
120
+ i = openAt - 1;
121
+ }
122
+ };
123
+ try {
124
+ md.core.ruler.before('curly_attributes', 'changelog', plugin);
125
+ }
126
+ catch (e) {
127
+ md.core.ruler.push('changelog', plugin);
128
+ }
129
+ };
130
+ module.exports = changelog;
131
+ //# sourceMappingURL=index.js.map