@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,596 @@
1
+ import sanitizeHtml from 'sanitize-html';
2
+ // @ts-ignore
3
+ import cssfilter from 'cssfilter';
4
+ import * as cheerio from 'cheerio';
5
+ import css from 'css';
6
+
7
+ const htmlTags = [
8
+ 'a',
9
+ 'abbr',
10
+ 'acronym',
11
+ 'address',
12
+ 'area',
13
+ 'article',
14
+ 'aside',
15
+ 'audio',
16
+ 'b',
17
+ 'bdi',
18
+ 'bdo',
19
+ 'big',
20
+ 'blink',
21
+ 'blockquote',
22
+ 'body',
23
+ 'br',
24
+ 'button',
25
+ 'canvas',
26
+ 'caption',
27
+ 'center',
28
+ 'cite',
29
+ 'code',
30
+ 'col',
31
+ 'colgroup',
32
+ 'content',
33
+ 'data',
34
+ 'datalist',
35
+ 'dd',
36
+ 'decorator',
37
+ 'del',
38
+ 'details',
39
+ 'dfn',
40
+ 'dialog',
41
+ 'dir',
42
+ 'div',
43
+ 'dl',
44
+ 'dt',
45
+ 'element',
46
+ 'em',
47
+ 'fieldset',
48
+ 'figcaption',
49
+ 'figure',
50
+ 'font',
51
+ 'footer',
52
+ 'h1',
53
+ 'h2',
54
+ 'h3',
55
+ 'h4',
56
+ 'h5',
57
+ 'h6',
58
+ 'head',
59
+ 'header',
60
+ 'hgroup',
61
+ 'hr',
62
+ 'html',
63
+ 'i',
64
+ 'img',
65
+ 'input',
66
+ 'ins',
67
+ 'kbd',
68
+ 'label',
69
+ 'legend',
70
+ 'li',
71
+ 'main',
72
+ 'map',
73
+ 'mark',
74
+ 'marquee',
75
+ 'menu',
76
+ 'menuitem',
77
+ 'meter',
78
+ 'nav',
79
+ 'nobr',
80
+ 'ol',
81
+ 'optgroup',
82
+ 'option',
83
+ 'output',
84
+ 'p',
85
+ 'picture',
86
+ 'pre',
87
+ 'progress',
88
+ 'q',
89
+ 'rp',
90
+ 'rt',
91
+ 'ruby',
92
+ 's',
93
+ 'samp',
94
+ 'section',
95
+ 'select',
96
+ 'shadow',
97
+ 'small',
98
+ 'source',
99
+ 'spacer',
100
+ 'span',
101
+ 'strike',
102
+ 'strong',
103
+ 'sub',
104
+ 'summary',
105
+ 'sup',
106
+ 'table',
107
+ 'tbody',
108
+ 'td',
109
+ 'template',
110
+ 'textarea',
111
+ 'tfoot',
112
+ 'th',
113
+ 'thead',
114
+ 'time',
115
+ 'tr',
116
+ 'track',
117
+ 'tt',
118
+ 'u',
119
+ 'ul',
120
+ 'var',
121
+ 'video',
122
+ 'wbr',
123
+ 'iframe',
124
+ 'style',
125
+ ];
126
+
127
+ const svgTags = [
128
+ 'svg',
129
+ 'altglyph',
130
+ 'altglyphdef',
131
+ 'altglyphitem',
132
+ 'animatecolor',
133
+ 'animatemotion',
134
+ 'animatetransform',
135
+ 'circle',
136
+ 'clippath',
137
+ 'defs',
138
+ 'desc',
139
+ 'ellipse',
140
+ 'filter',
141
+ 'font',
142
+ 'g',
143
+ 'glyph',
144
+ 'glyphref',
145
+ 'hkern',
146
+ 'image',
147
+ 'line',
148
+ 'lineargradient',
149
+ 'marker',
150
+ 'mask',
151
+ 'metadata',
152
+ 'mpath',
153
+ 'path',
154
+ 'pattern',
155
+ 'polygon',
156
+ 'polyline',
157
+ 'radialgradient',
158
+ 'rect',
159
+ 'stop',
160
+ 'switch',
161
+ 'symbol',
162
+ 'text',
163
+ 'textpath',
164
+ 'title',
165
+ 'tref',
166
+ 'tspan',
167
+ 'view',
168
+ 'vkern',
169
+ 'animate',
170
+ ];
171
+
172
+ const htmlAttrs = [
173
+ 'accept',
174
+ 'action',
175
+ 'align',
176
+ 'alt',
177
+ 'autocapitalize',
178
+ 'autocomplete',
179
+ 'autopictureinpicture',
180
+ 'autoplay',
181
+ 'background',
182
+ 'bgcolor',
183
+ 'border',
184
+ 'capture',
185
+ 'cellpadding',
186
+ 'cellspacing',
187
+ 'checked',
188
+ 'cite',
189
+ 'class',
190
+ 'clear',
191
+ 'color',
192
+ 'cols',
193
+ 'colspan',
194
+ 'controls',
195
+ 'controlslist',
196
+ 'coords',
197
+ 'crossorigin',
198
+ 'datetime',
199
+ 'decoding',
200
+ 'default',
201
+ 'dir',
202
+ 'disabled',
203
+ 'disablepictureinpicture',
204
+ 'disableremoteplayback',
205
+ 'download',
206
+ 'draggable',
207
+ 'enctype',
208
+ 'enterkeyhint',
209
+ 'face',
210
+ 'for',
211
+ 'headers',
212
+ 'height',
213
+ 'hidden',
214
+ 'high',
215
+ 'href',
216
+ 'hreflang',
217
+ 'id',
218
+ 'inputmode',
219
+ 'integrity',
220
+ 'ismap',
221
+ 'kind',
222
+ 'label',
223
+ 'lang',
224
+ 'list',
225
+ 'loading',
226
+ 'loop',
227
+ 'low',
228
+ 'max',
229
+ 'maxlength',
230
+ 'media',
231
+ 'method',
232
+ 'min',
233
+ 'minlength',
234
+ 'multiple',
235
+ 'muted',
236
+ 'name',
237
+ 'nonce',
238
+ 'noshade',
239
+ 'novalidate',
240
+ 'nowrap',
241
+ 'open',
242
+ 'optimum',
243
+ 'pattern',
244
+ 'placeholder',
245
+ 'playsinline',
246
+ 'poster',
247
+ 'preload',
248
+ 'pubdate',
249
+ 'radiogroup',
250
+ 'readonly',
251
+ 'rel',
252
+ 'required',
253
+ 'rev',
254
+ 'reversed',
255
+ 'role',
256
+ 'rows',
257
+ 'rowspan',
258
+ 'spellcheck',
259
+ 'scope',
260
+ 'selected',
261
+ 'shape',
262
+ 'size',
263
+ 'sizes',
264
+ 'span',
265
+ 'srclang',
266
+ 'start',
267
+ 'src',
268
+ 'srcset',
269
+ 'step',
270
+ 'style',
271
+ 'summary',
272
+ 'tabindex',
273
+ 'title',
274
+ 'translate',
275
+ 'type',
276
+ 'usemap',
277
+ 'valign',
278
+ 'value',
279
+ 'width',
280
+ 'xmlns',
281
+ 'slot',
282
+ 'frameborder',
283
+ 'scrolling',
284
+ 'allow',
285
+ 'target',
286
+ 'attributeName',
287
+ 'aria-hidden',
288
+ 'referrerpolicy',
289
+ 'aria-describedby',
290
+ 'data-*',
291
+ ];
292
+
293
+ const svgAttrs = [
294
+ 'viewBox',
295
+ 'accent-height',
296
+ 'accumulate',
297
+ 'additive',
298
+ 'alignment-baseline',
299
+ 'ascent',
300
+ 'attributename',
301
+ 'attributetype',
302
+ 'azimuth',
303
+ 'basefrequency',
304
+ 'baseline-shift',
305
+ 'begin',
306
+ 'bias',
307
+ 'by',
308
+ 'class',
309
+ 'clip',
310
+ 'clippathunits',
311
+ 'clip-path',
312
+ 'clip-rule',
313
+ 'color',
314
+ 'color-interpolation',
315
+ 'color-interpolation-filters',
316
+ 'color-profile',
317
+ 'color-rendering',
318
+ 'cx',
319
+ 'cy',
320
+ 'd',
321
+ 'dx',
322
+ 'dy',
323
+ 'diffuseconstant',
324
+ 'direction',
325
+ 'display',
326
+ 'divisor',
327
+ 'dur',
328
+ 'edgemode',
329
+ 'elevation',
330
+ 'end',
331
+ 'fill',
332
+ 'fill-opacity',
333
+ 'fill-rule',
334
+ 'filter',
335
+ 'filterunits',
336
+ 'flood-color',
337
+ 'flood-opacity',
338
+ 'font-family',
339
+ 'font-size',
340
+ 'font-size-adjust',
341
+ 'font-stretch',
342
+ 'font-style',
343
+ 'font-variant',
344
+ 'font-weight',
345
+ 'fx',
346
+ 'fy',
347
+ 'g1',
348
+ 'g2',
349
+ 'glyph-name',
350
+ 'glyphref',
351
+ 'gradientunits',
352
+ 'gradienttransform',
353
+ 'height',
354
+ 'href',
355
+ 'id',
356
+ 'image-rendering',
357
+ 'in',
358
+ 'in2',
359
+ 'k',
360
+ 'k1',
361
+ 'k2',
362
+ 'k3',
363
+ 'k4',
364
+ 'kerning',
365
+ 'keypoints',
366
+ 'keysplines',
367
+ 'keytimes',
368
+ 'lang',
369
+ 'lengthadjust',
370
+ 'letter-spacing',
371
+ 'kernelmatrix',
372
+ 'kernelunitlength',
373
+ 'lighting-color',
374
+ 'local',
375
+ 'marker-end',
376
+ 'marker-mid',
377
+ 'marker-start',
378
+ 'markerheight',
379
+ 'markerunits',
380
+ 'markerwidth',
381
+ 'maskcontentunits',
382
+ 'maskunits',
383
+ 'max',
384
+ 'mask',
385
+ 'media',
386
+ 'method',
387
+ 'mode',
388
+ 'min',
389
+ 'name',
390
+ 'numoctaves',
391
+ 'offset',
392
+ 'operator',
393
+ 'opacity',
394
+ 'order',
395
+ 'orient',
396
+ 'orientation',
397
+ 'origin',
398
+ 'overflow',
399
+ 'paint-order',
400
+ 'path',
401
+ 'pathlength',
402
+ 'patterncontentunits',
403
+ 'patterntransform',
404
+ 'patternunits',
405
+ 'points',
406
+ 'preservealpha',
407
+ 'preserveaspectratio',
408
+ 'primitiveunits',
409
+ 'r',
410
+ 'rx',
411
+ 'ry',
412
+ 'radius',
413
+ 'refx',
414
+ 'refy',
415
+ 'repeatcount',
416
+ 'repeatdur',
417
+ 'restart',
418
+ 'result',
419
+ 'rotate',
420
+ 'scale',
421
+ 'seed',
422
+ 'shape-rendering',
423
+ 'specularconstant',
424
+ 'specularexponent',
425
+ 'spreadmethod',
426
+ 'startoffset',
427
+ 'stddeviation',
428
+ 'stitchtiles',
429
+ 'stop-color',
430
+ 'stop-opacity',
431
+ 'stroke-dasharray',
432
+ 'stroke-dashoffset',
433
+ 'stroke-linecap',
434
+ 'stroke-linejoin',
435
+ 'stroke-miterlimit',
436
+ 'stroke-opacity',
437
+ 'stroke',
438
+ 'stroke-width',
439
+ 'style',
440
+ 'surfacescale',
441
+ 'systemlanguage',
442
+ 'tabindex',
443
+ 'targetx',
444
+ 'targety',
445
+ 'transform',
446
+ 'text-anchor',
447
+ 'text-decoration',
448
+ 'text-rendering',
449
+ 'textlength',
450
+ 'type',
451
+ 'u1',
452
+ 'u2',
453
+ 'unicode',
454
+ 'values',
455
+ 'viewbox',
456
+ 'visibility',
457
+ 'version',
458
+ 'vert-adv-y',
459
+ 'vert-origin-x',
460
+ 'vert-origin-y',
461
+ 'width',
462
+ 'word-spacing',
463
+ 'wrap',
464
+ 'writing-mode',
465
+ 'xchannelselector',
466
+ 'ychannelselector',
467
+ 'x',
468
+ 'x1',
469
+ 'x2',
470
+ 'xmlns',
471
+ 'y',
472
+ 'y1',
473
+ 'y2',
474
+ 'z',
475
+ 'zoomandpan',
476
+ 'from',
477
+ 'to',
478
+ ];
479
+
480
+ const yfmHtmlAttrs = ['note-type', 'yfm2xliff-explicit', 'term-key'];
481
+
482
+ const allowedTags = Array.from(
483
+ new Set([...htmlTags, ...svgTags, ...sanitizeHtml.defaults.allowedTags]),
484
+ );
485
+ const allowedAttributes = Array.from(new Set([...htmlAttrs, ...svgAttrs, ...yfmHtmlAttrs]));
486
+
487
+ export type CssWhiteList = {[property: string]: boolean};
488
+
489
+ export interface SanitizeOptions extends sanitizeHtml.IOptions {
490
+ cssWhiteList?: CssWhiteList;
491
+ }
492
+
493
+ export const defaultParseOptions = {
494
+ lowerCaseAttributeNames: false,
495
+ };
496
+
497
+ export const defaultOptions: SanitizeOptions = {
498
+ ...sanitizeHtml.defaults,
499
+ allowedTags,
500
+ allowedAttributes: {
501
+ ...sanitizeHtml.defaults.allowedAttributes,
502
+ '*': allowedAttributes,
503
+ },
504
+ allowVulnerableTags: true,
505
+ parser: defaultParseOptions,
506
+ cssWhiteList: cssfilter.whiteList,
507
+ };
508
+
509
+ function sanitizeStyleTags(dom: cheerio.CheerioAPI, cssWhiteList: CssWhiteList) {
510
+ const styleTags = dom('style');
511
+
512
+ styleTags.each((_index: number, element: cheerio.Element) => {
513
+ const styleText = dom(element).text();
514
+
515
+ try {
516
+ const parsedCSS = css.parse(styleText);
517
+
518
+ if (!parsedCSS.stylesheet) {
519
+ return;
520
+ }
521
+
522
+ parsedCSS.stylesheet.rules = parsedCSS.stylesheet.rules.filter(
523
+ (rule: css.Rule) => rule.type === 'rule',
524
+ );
525
+
526
+ parsedCSS.stylesheet.rules.forEach((rule: css.Rule) => {
527
+ if (!rule.declarations) {
528
+ return;
529
+ }
530
+
531
+ rule.declarations = rule.declarations.filter((declaration: css.Declaration) => {
532
+ if (!declaration.property || !declaration.value) {
533
+ return false;
534
+ }
535
+
536
+ const isWhiteListed = cssWhiteList[declaration.property];
537
+
538
+ if (isWhiteListed) {
539
+ declaration.value = cssfilter.safeAttrValue(
540
+ declaration.property,
541
+ declaration.value,
542
+ );
543
+ }
544
+
545
+ if (!declaration.value) {
546
+ return false;
547
+ }
548
+
549
+ return isWhiteListed;
550
+ });
551
+ });
552
+
553
+ dom(element).text(css.stringify(parsedCSS));
554
+ } catch {}
555
+ });
556
+ }
557
+
558
+ function sanitizeStyleAttrs(dom: cheerio.CheerioAPI, cssWhiteList: CssWhiteList) {
559
+ const options = {
560
+ whiteList: cssWhiteList,
561
+ };
562
+ const cssSanitizer = new cssfilter.FilterCSS(options);
563
+
564
+ dom('*').each((_index, element) => {
565
+ const styleAttrValue = dom(element).attr('style');
566
+
567
+ if (!styleAttrValue) {
568
+ return;
569
+ }
570
+
571
+ dom(element).attr('style', cssSanitizer.process(styleAttrValue));
572
+ });
573
+ }
574
+
575
+ function sanitizeStyles(html: string, options: SanitizeOptions) {
576
+ const cssWhiteList = options.cssWhiteList || {};
577
+
578
+ const $ = cheerio.load(html);
579
+
580
+ sanitizeStyleTags($, cssWhiteList);
581
+
582
+ sanitizeStyleAttrs($, cssWhiteList);
583
+
584
+ const styles = $('head').html() || '';
585
+ const content = $('body').html() || '';
586
+
587
+ return styles + content;
588
+ }
589
+
590
+ export default function sanitize(html: string, options?: SanitizeOptions) {
591
+ const sanitizeOptions = options || defaultOptions;
592
+
593
+ const modifiedHtml = sanitizeStyles(html, sanitizeOptions);
594
+
595
+ return sanitizeHtml(modifiedHtml, sanitizeOptions);
596
+ }
@@ -0,0 +1,22 @@
1
+ import Token from 'markdown-it/lib/token';
2
+
3
+ export = function extractTitle(tokens: Token[]) {
4
+ let title = '',
5
+ contentTokens = tokens,
6
+ titleTokens: Token[] = [];
7
+
8
+ if (Array.isArray(tokens) && tokens.length > 0) {
9
+ if (tokens[0].type === 'heading_open' && tokens[0].tag === 'h1') {
10
+ titleTokens = tokens[1].children || [];
11
+ title = tokens[1].content;
12
+ // cut out "heading_open", "inline" and "heading_close" tokens
13
+ contentTokens = tokens.slice(3);
14
+ }
15
+ }
16
+
17
+ return {
18
+ titleTokens,
19
+ title,
20
+ tokens: contentTokens,
21
+ };
22
+ };
@@ -0,0 +1,64 @@
1
+ import {LanguageFn} from 'highlight.js';
2
+ import DefaultMarkdownIt from 'markdown-it';
3
+ import DefaultStateCore from 'markdown-it/lib/rules_core/state_core';
4
+ import {SanitizeOptions} from './sanitize';
5
+ import {MarkdownItPluginCb} from './plugins/typings';
6
+ import {LogLevels} from './log';
7
+ import {ChangelogItem} from './plugins/changelog/types';
8
+
9
+ export interface MarkdownIt extends DefaultMarkdownIt {
10
+ assets?: string[];
11
+ meta?: string[];
12
+ }
13
+ export interface StateCore extends DefaultStateCore {
14
+ md: MarkdownIt;
15
+ }
16
+
17
+ export type HighlightLangMap = Record<string, LanguageFn>;
18
+
19
+ export type Heading = {
20
+ title: string;
21
+ href: string;
22
+ level: number;
23
+ items?: Heading[];
24
+ };
25
+
26
+ export interface OptionsType {
27
+ vars?: Record<string, string>;
28
+ path?: string;
29
+ extractTitle?: boolean;
30
+ needTitle?: boolean;
31
+ allowHTML?: boolean;
32
+ linkify?: boolean;
33
+ linkifyTlds?: string | string[];
34
+ breaks?: boolean;
35
+ conditionsInCode?: boolean;
36
+ disableLiquid?: boolean;
37
+ leftDelimiter?: string;
38
+ rightDelimiter?: string;
39
+ isLiquided?: boolean;
40
+ needToSanitizeHtml?: boolean;
41
+ sanitizeOptions?: SanitizeOptions;
42
+ needFlatListHeadings?: boolean;
43
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
+ plugins?: MarkdownItPluginCb<any>[];
45
+ highlightLangs?: HighlightLangMap;
46
+ root?: string;
47
+ extractChangelogs?: boolean;
48
+ [x: string]: unknown;
49
+ }
50
+
51
+ export interface OutputType {
52
+ result: {
53
+ html: string;
54
+ } & EnvType;
55
+ logs: Record<LogLevels, string[]>;
56
+ }
57
+
58
+ export type EnvType<Extras extends {} = {}> = {
59
+ title?: string;
60
+ headings: Heading[];
61
+ assets?: unknown[];
62
+ meta?: object;
63
+ changelogs?: ChangelogItem[];
64
+ } & Extras;