@alexlit/lint-kit 107.1.0 → 107.2.1

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 (187) hide show
  1. package/package.json +1 -1
  2. package/packages/config-eslint/package.json +4 -4
  3. package/packages/config-markdownlint/node_modules/markdown-it/LICENSE +22 -0
  4. package/packages/config-markdownlint/node_modules/markdown-it/README.md +309 -0
  5. package/packages/config-markdownlint/node_modules/markdown-it/bin/markdown-it.js +117 -0
  6. package/packages/config-markdownlint/node_modules/markdown-it/dist/markdown-it.js +8441 -0
  7. package/packages/config-markdownlint/node_modules/markdown-it/dist/markdown-it.min.js +3 -0
  8. package/packages/config-markdownlint/node_modules/markdown-it/index.js +4 -0
  9. package/packages/config-markdownlint/node_modules/markdown-it/lib/common/entities.js +6 -0
  10. package/packages/config-markdownlint/node_modules/markdown-it/lib/common/html_blocks.js +70 -0
  11. package/packages/config-markdownlint/node_modules/markdown-it/lib/common/html_re.js +28 -0
  12. package/packages/config-markdownlint/node_modules/markdown-it/lib/common/utils.js +317 -0
  13. package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/index.js +7 -0
  14. package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/parse_link_destination.js +80 -0
  15. package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/parse_link_label.js +48 -0
  16. package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/parse_link_title.js +55 -0
  17. package/packages/config-markdownlint/node_modules/markdown-it/lib/index.js +582 -0
  18. package/packages/config-markdownlint/node_modules/markdown-it/lib/parser_block.js +131 -0
  19. package/packages/config-markdownlint/node_modules/markdown-it/lib/parser_core.js +61 -0
  20. package/packages/config-markdownlint/node_modules/markdown-it/lib/parser_inline.js +192 -0
  21. package/packages/config-markdownlint/node_modules/markdown-it/lib/presets/commonmark.js +81 -0
  22. package/packages/config-markdownlint/node_modules/markdown-it/lib/presets/default.js +41 -0
  23. package/packages/config-markdownlint/node_modules/markdown-it/lib/presets/zero.js +63 -0
  24. package/packages/config-markdownlint/node_modules/markdown-it/lib/renderer.js +341 -0
  25. package/packages/config-markdownlint/node_modules/markdown-it/lib/ruler.js +352 -0
  26. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/blockquote.js +226 -0
  27. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/code.js +34 -0
  28. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/fence.js +98 -0
  29. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/heading.js +55 -0
  30. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/hr.js +45 -0
  31. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/html_block.js +74 -0
  32. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/lheading.js +83 -0
  33. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/list.js +362 -0
  34. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/paragraph.js +51 -0
  35. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/reference.js +198 -0
  36. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/state_block.js +231 -0
  37. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/table.js +221 -0
  38. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/block.js +16 -0
  39. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/inline.js +13 -0
  40. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/linkify.js +142 -0
  41. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/normalize.js +21 -0
  42. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/replacements.js +105 -0
  43. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/smartquotes.js +201 -0
  44. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/state_core.js +20 -0
  45. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/text_join.js +45 -0
  46. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/autolink.js +76 -0
  47. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/backticks.js +63 -0
  48. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/balance_pairs.js +130 -0
  49. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/emphasis.js +130 -0
  50. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/entity.js +55 -0
  51. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/escape.js +71 -0
  52. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/fragments_join.js +41 -0
  53. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/html_inline.js +58 -0
  54. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/image.js +152 -0
  55. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/link.js +150 -0
  56. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/linkify.js +62 -0
  57. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/newline.js +46 -0
  58. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/state_inline.js +158 -0
  59. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/strikethrough.js +130 -0
  60. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/text.js +89 -0
  61. package/packages/config-markdownlint/node_modules/markdown-it/lib/token.js +201 -0
  62. package/packages/config-markdownlint/node_modules/markdown-it/package.json +87 -0
  63. package/packages/config-markdownlint/node_modules/markdownlint/CHANGELOG.md +428 -0
  64. package/packages/config-markdownlint/node_modules/markdownlint/CONTRIBUTING.md +92 -0
  65. package/packages/config-markdownlint/node_modules/markdownlint/LICENSE +21 -0
  66. package/packages/config-markdownlint/node_modules/markdownlint/README.md +1026 -0
  67. package/packages/config-markdownlint/node_modules/markdownlint/demo/markdownlint-browser.js +6814 -0
  68. package/packages/config-markdownlint/node_modules/markdownlint/doc/CustomRules.md +376 -0
  69. package/packages/config-markdownlint/node_modules/markdownlint/doc/Prettier.md +27 -0
  70. package/packages/config-markdownlint/node_modules/markdownlint/doc/ReleaseProcess.md +20 -0
  71. package/packages/config-markdownlint/node_modules/markdownlint/doc/Rules.md +2335 -0
  72. package/packages/config-markdownlint/node_modules/markdownlint/doc/md001.md +37 -0
  73. package/packages/config-markdownlint/node_modules/markdownlint/doc/md003.md +59 -0
  74. package/packages/config-markdownlint/node_modules/markdownlint/doc/md004.md +49 -0
  75. package/packages/config-markdownlint/node_modules/markdownlint/doc/md005.md +53 -0
  76. package/packages/config-markdownlint/node_modules/markdownlint/doc/md007.md +52 -0
  77. package/packages/config-markdownlint/node_modules/markdownlint/doc/md009.md +51 -0
  78. package/packages/config-markdownlint/node_modules/markdownlint/doc/md010.md +56 -0
  79. package/packages/config-markdownlint/node_modules/markdownlint/doc/md011.md +30 -0
  80. package/packages/config-markdownlint/node_modules/markdownlint/doc/md012.md +38 -0
  81. package/packages/config-markdownlint/node_modules/markdownlint/doc/md013.md +57 -0
  82. package/packages/config-markdownlint/node_modules/markdownlint/doc/md014.md +54 -0
  83. package/packages/config-markdownlint/node_modules/markdownlint/doc/md018.md +27 -0
  84. package/packages/config-markdownlint/node_modules/markdownlint/doc/md019.md +28 -0
  85. package/packages/config-markdownlint/node_modules/markdownlint/doc/md020.md +29 -0
  86. package/packages/config-markdownlint/node_modules/markdownlint/doc/md021.md +31 -0
  87. package/packages/config-markdownlint/node_modules/markdownlint/doc/md022.md +52 -0
  88. package/packages/config-markdownlint/node_modules/markdownlint/doc/md023.md +33 -0
  89. package/packages/config-markdownlint/node_modules/markdownlint/doc/md024.md +47 -0
  90. package/packages/config-markdownlint/node_modules/markdownlint/doc/md025.md +49 -0
  91. package/packages/config-markdownlint/node_modules/markdownlint/doc/md026.md +40 -0
  92. package/packages/config-markdownlint/node_modules/markdownlint/doc/md027.md +24 -0
  93. package/packages/config-markdownlint/node_modules/markdownlint/doc/md028.md +40 -0
  94. package/packages/config-markdownlint/node_modules/markdownlint/doc/md029.md +98 -0
  95. package/packages/config-markdownlint/node_modules/markdownlint/doc/md030.md +82 -0
  96. package/packages/config-markdownlint/node_modules/markdownlint/doc/md031.md +50 -0
  97. package/packages/config-markdownlint/node_modules/markdownlint/doc/md032.md +55 -0
  98. package/packages/config-markdownlint/node_modules/markdownlint/doc/md033.md +27 -0
  99. package/packages/config-markdownlint/node_modules/markdownlint/doc/md034.md +50 -0
  100. package/packages/config-markdownlint/node_modules/markdownlint/doc/md035.md +42 -0
  101. package/packages/config-markdownlint/node_modules/markdownlint/doc/md036.md +45 -0
  102. package/packages/config-markdownlint/node_modules/markdownlint/doc/md037.md +37 -0
  103. package/packages/config-markdownlint/node_modules/markdownlint/doc/md038.md +40 -0
  104. package/packages/config-markdownlint/node_modules/markdownlint/doc/md039.md +21 -0
  105. package/packages/config-markdownlint/node_modules/markdownlint/doc/md040.md +52 -0
  106. package/packages/config-markdownlint/node_modules/markdownlint/doc/md041.md +49 -0
  107. package/packages/config-markdownlint/node_modules/markdownlint/doc/md042.md +32 -0
  108. package/packages/config-markdownlint/node_modules/markdownlint/doc/md043.md +69 -0
  109. package/packages/config-markdownlint/node_modules/markdownlint/doc/md044.md +35 -0
  110. package/packages/config-markdownlint/node_modules/markdownlint/doc/md045.md +40 -0
  111. package/packages/config-markdownlint/node_modules/markdownlint/doc/md046.md +40 -0
  112. package/packages/config-markdownlint/node_modules/markdownlint/doc/md047.md +34 -0
  113. package/packages/config-markdownlint/node_modules/markdownlint/doc/md048.md +41 -0
  114. package/packages/config-markdownlint/node_modules/markdownlint/doc/md049.md +32 -0
  115. package/packages/config-markdownlint/node_modules/markdownlint/doc/md050.md +32 -0
  116. package/packages/config-markdownlint/node_modules/markdownlint/doc/md051.md +61 -0
  117. package/packages/config-markdownlint/node_modules/markdownlint/doc/md052.md +40 -0
  118. package/packages/config-markdownlint/node_modules/markdownlint/doc/md053.md +38 -0
  119. package/packages/config-markdownlint/node_modules/markdownlint/doc/md054.md +100 -0
  120. package/packages/config-markdownlint/node_modules/markdownlint/helpers/LICENSE +21 -0
  121. package/packages/config-markdownlint/node_modules/markdownlint/helpers/README.md +70 -0
  122. package/packages/config-markdownlint/node_modules/markdownlint/helpers/helpers.js +1025 -0
  123. package/packages/config-markdownlint/node_modules/markdownlint/helpers/micromark.cjs +426 -0
  124. package/packages/config-markdownlint/node_modules/markdownlint/helpers/package.json +26 -0
  125. package/packages/config-markdownlint/node_modules/markdownlint/helpers/shared.js +10 -0
  126. package/packages/config-markdownlint/node_modules/markdownlint/lib/cache.js +21 -0
  127. package/packages/config-markdownlint/node_modules/markdownlint/lib/configuration.d.ts +1152 -0
  128. package/packages/config-markdownlint/node_modules/markdownlint/lib/constants.js +14 -0
  129. package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.d.ts +406 -0
  130. package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.js +1476 -0
  131. package/packages/config-markdownlint/node_modules/markdownlint/lib/md001.js +22 -0
  132. package/packages/config-markdownlint/node_modules/markdownlint/lib/md003.js +42 -0
  133. package/packages/config-markdownlint/node_modules/markdownlint/lib/md004.js +76 -0
  134. package/packages/config-markdownlint/node_modules/markdownlint/lib/md005.js +73 -0
  135. package/packages/config-markdownlint/node_modules/markdownlint/lib/md007.js +86 -0
  136. package/packages/config-markdownlint/node_modules/markdownlint/lib/md009.js +86 -0
  137. package/packages/config-markdownlint/node_modules/markdownlint/lib/md010.js +60 -0
  138. package/packages/config-markdownlint/node_modules/markdownlint/lib/md011.js +46 -0
  139. package/packages/config-markdownlint/node_modules/markdownlint/lib/md012.js +32 -0
  140. package/packages/config-markdownlint/node_modules/markdownlint/lib/md013.js +96 -0
  141. package/packages/config-markdownlint/node_modules/markdownlint/lib/md014.js +53 -0
  142. package/packages/config-markdownlint/node_modules/markdownlint/lib/md018.js +34 -0
  143. package/packages/config-markdownlint/node_modules/markdownlint/lib/md019.js +39 -0
  144. package/packages/config-markdownlint/node_modules/markdownlint/lib/md020.js +62 -0
  145. package/packages/config-markdownlint/node_modules/markdownlint/lib/md021.js +62 -0
  146. package/packages/config-markdownlint/node_modules/markdownlint/lib/md022.js +108 -0
  147. package/packages/config-markdownlint/node_modules/markdownlint/lib/md023.js +38 -0
  148. package/packages/config-markdownlint/node_modules/markdownlint/lib/md024.js +38 -0
  149. package/packages/config-markdownlint/node_modules/markdownlint/lib/md025.js +32 -0
  150. package/packages/config-markdownlint/node_modules/markdownlint/lib/md026.js +50 -0
  151. package/packages/config-markdownlint/node_modules/markdownlint/lib/md027.js +56 -0
  152. package/packages/config-markdownlint/node_modules/markdownlint/lib/md028.js +30 -0
  153. package/packages/config-markdownlint/node_modules/markdownlint/lib/md029.js +67 -0
  154. package/packages/config-markdownlint/node_modules/markdownlint/lib/md030.js +61 -0
  155. package/packages/config-markdownlint/node_modules/markdownlint/lib/md031.js +40 -0
  156. package/packages/config-markdownlint/node_modules/markdownlint/lib/md032.js +78 -0
  157. package/packages/config-markdownlint/node_modules/markdownlint/lib/md033.js +39 -0
  158. package/packages/config-markdownlint/node_modules/markdownlint/lib/md034.js +79 -0
  159. package/packages/config-markdownlint/node_modules/markdownlint/lib/md035.js +24 -0
  160. package/packages/config-markdownlint/node_modules/markdownlint/lib/md036.js +56 -0
  161. package/packages/config-markdownlint/node_modules/markdownlint/lib/md037.js +91 -0
  162. package/packages/config-markdownlint/node_modules/markdownlint/lib/md038.js +97 -0
  163. package/packages/config-markdownlint/node_modules/markdownlint/lib/md039.js +67 -0
  164. package/packages/config-markdownlint/node_modules/markdownlint/lib/md040.js +37 -0
  165. package/packages/config-markdownlint/node_modules/markdownlint/lib/md041.js +42 -0
  166. package/packages/config-markdownlint/node_modules/markdownlint/lib/md042.js +49 -0
  167. package/packages/config-markdownlint/node_modules/markdownlint/lib/md043.js +64 -0
  168. package/packages/config-markdownlint/node_modules/markdownlint/lib/md044.js +107 -0
  169. package/packages/config-markdownlint/node_modules/markdownlint/lib/md045.js +60 -0
  170. package/packages/config-markdownlint/node_modules/markdownlint/lib/md046.js +33 -0
  171. package/packages/config-markdownlint/node_modules/markdownlint/lib/md047.js +28 -0
  172. package/packages/config-markdownlint/node_modules/markdownlint/lib/md048.js +30 -0
  173. package/packages/config-markdownlint/node_modules/markdownlint/lib/md049-md050.js +89 -0
  174. package/packages/config-markdownlint/node_modules/markdownlint/lib/md051.js +172 -0
  175. package/packages/config-markdownlint/node_modules/markdownlint/lib/md052.js +39 -0
  176. package/packages/config-markdownlint/node_modules/markdownlint/lib/md053.js +59 -0
  177. package/packages/config-markdownlint/node_modules/markdownlint/lib/md054.js +125 -0
  178. package/packages/config-markdownlint/node_modules/markdownlint/lib/rules.js +65 -0
  179. package/packages/config-markdownlint/node_modules/markdownlint/package.json +109 -0
  180. package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.jsonc +297 -0
  181. package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.yaml +266 -0
  182. package/packages/config-markdownlint/node_modules/markdownlint/schema/markdownlint-config-schema.json +1762 -0
  183. package/packages/config-markdownlint/node_modules/markdownlint/style/all.json +5 -0
  184. package/packages/config-markdownlint/node_modules/markdownlint/style/cirosantilli.json +22 -0
  185. package/packages/config-markdownlint/node_modules/markdownlint/style/prettier.json +26 -0
  186. package/packages/config-markdownlint/node_modules/markdownlint/style/relaxed.json +12 -0
  187. package/packages/config-markdownlint/package.json +3 -3
@@ -0,0 +1,582 @@
1
+ // Main parser class
2
+
3
+ 'use strict';
4
+
5
+
6
+ var utils = require('./common/utils');
7
+ var helpers = require('./helpers');
8
+ var Renderer = require('./renderer');
9
+ var ParserCore = require('./parser_core');
10
+ var ParserBlock = require('./parser_block');
11
+ var ParserInline = require('./parser_inline');
12
+ var LinkifyIt = require('linkify-it');
13
+ var mdurl = require('mdurl');
14
+ var punycode = require('punycode');
15
+
16
+
17
+ var config = {
18
+ default: require('./presets/default'),
19
+ zero: require('./presets/zero'),
20
+ commonmark: require('./presets/commonmark')
21
+ };
22
+
23
+ ////////////////////////////////////////////////////////////////////////////////
24
+ //
25
+ // This validator can prohibit more than really needed to prevent XSS. It's a
26
+ // tradeoff to keep code simple and to be secure by default.
27
+ //
28
+ // If you need different setup - override validator method as you wish. Or
29
+ // replace it with dummy function and use external sanitizer.
30
+ //
31
+
32
+ var BAD_PROTO_RE = /^(vbscript|javascript|file|data):/;
33
+ var GOOD_DATA_RE = /^data:image\/(gif|png|jpeg|webp);/;
34
+
35
+ function validateLink(url) {
36
+ // url should be normalized at this point, and existing entities are decoded
37
+ var str = url.trim().toLowerCase();
38
+
39
+ return BAD_PROTO_RE.test(str) ? (GOOD_DATA_RE.test(str) ? true : false) : true;
40
+ }
41
+
42
+ ////////////////////////////////////////////////////////////////////////////////
43
+
44
+
45
+ var RECODE_HOSTNAME_FOR = [ 'http:', 'https:', 'mailto:' ];
46
+
47
+ function normalizeLink(url) {
48
+ var parsed = mdurl.parse(url, true);
49
+
50
+ if (parsed.hostname) {
51
+ // Encode hostnames in urls like:
52
+ // `http://host/`, `https://host/`, `mailto:user@host`, `//host/`
53
+ //
54
+ // We don't encode unknown schemas, because it's likely that we encode
55
+ // something we shouldn't (e.g. `skype:name` treated as `skype:host`)
56
+ //
57
+ if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) {
58
+ try {
59
+ parsed.hostname = punycode.toASCII(parsed.hostname);
60
+ } catch (er) { /**/ }
61
+ }
62
+ }
63
+
64
+ return mdurl.encode(mdurl.format(parsed));
65
+ }
66
+
67
+ function normalizeLinkText(url) {
68
+ var parsed = mdurl.parse(url, true);
69
+
70
+ if (parsed.hostname) {
71
+ // Encode hostnames in urls like:
72
+ // `http://host/`, `https://host/`, `mailto:user@host`, `//host/`
73
+ //
74
+ // We don't encode unknown schemas, because it's likely that we encode
75
+ // something we shouldn't (e.g. `skype:name` treated as `skype:host`)
76
+ //
77
+ if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) {
78
+ try {
79
+ parsed.hostname = punycode.toUnicode(parsed.hostname);
80
+ } catch (er) { /**/ }
81
+ }
82
+ }
83
+
84
+ // add '%' to exclude list because of https://github.com/markdown-it/markdown-it/issues/720
85
+ return mdurl.decode(mdurl.format(parsed), mdurl.decode.defaultChars + '%');
86
+ }
87
+
88
+
89
+ /**
90
+ * class MarkdownIt
91
+ *
92
+ * Main parser/renderer class.
93
+ *
94
+ * ##### Usage
95
+ *
96
+ * ```javascript
97
+ * // node.js, "classic" way:
98
+ * var MarkdownIt = require('markdown-it'),
99
+ * md = new MarkdownIt();
100
+ * var result = md.render('# markdown-it rulezz!');
101
+ *
102
+ * // node.js, the same, but with sugar:
103
+ * var md = require('markdown-it')();
104
+ * var result = md.render('# markdown-it rulezz!');
105
+ *
106
+ * // browser without AMD, added to "window" on script load
107
+ * // Note, there are no dash.
108
+ * var md = window.markdownit();
109
+ * var result = md.render('# markdown-it rulezz!');
110
+ * ```
111
+ *
112
+ * Single line rendering, without paragraph wrap:
113
+ *
114
+ * ```javascript
115
+ * var md = require('markdown-it')();
116
+ * var result = md.renderInline('__markdown-it__ rulezz!');
117
+ * ```
118
+ **/
119
+
120
+ /**
121
+ * new MarkdownIt([presetName, options])
122
+ * - presetName (String): optional, `commonmark` / `zero`
123
+ * - options (Object)
124
+ *
125
+ * Creates parser instanse with given config. Can be called without `new`.
126
+ *
127
+ * ##### presetName
128
+ *
129
+ * MarkdownIt provides named presets as a convenience to quickly
130
+ * enable/disable active syntax rules and options for common use cases.
131
+ *
132
+ * - ["commonmark"](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/commonmark.js) -
133
+ * configures parser to strict [CommonMark](http://commonmark.org/) mode.
134
+ * - [default](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/default.js) -
135
+ * similar to GFM, used when no preset name given. Enables all available rules,
136
+ * but still without html, typographer & autolinker.
137
+ * - ["zero"](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/zero.js) -
138
+ * all rules disabled. Useful to quickly setup your config via `.enable()`.
139
+ * For example, when you need only `bold` and `italic` markup and nothing else.
140
+ *
141
+ * ##### options:
142
+ *
143
+ * - __html__ - `false`. Set `true` to enable HTML tags in source. Be careful!
144
+ * That's not safe! You may need external sanitizer to protect output from XSS.
145
+ * It's better to extend features via plugins, instead of enabling HTML.
146
+ * - __xhtmlOut__ - `false`. Set `true` to add '/' when closing single tags
147
+ * (`<br />`). This is needed only for full CommonMark compatibility. In real
148
+ * world you will need HTML output.
149
+ * - __breaks__ - `false`. Set `true` to convert `\n` in paragraphs into `<br>`.
150
+ * - __langPrefix__ - `language-`. CSS language class prefix for fenced blocks.
151
+ * Can be useful for external highlighters.
152
+ * - __linkify__ - `false`. Set `true` to autoconvert URL-like text to links.
153
+ * - __typographer__ - `false`. Set `true` to enable [some language-neutral
154
+ * replacement](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/replacements.js) +
155
+ * quotes beautification (smartquotes).
156
+ * - __quotes__ - `“”‘’`, String or Array. Double + single quotes replacement
157
+ * pairs, when typographer enabled and smartquotes on. For example, you can
158
+ * use `'«»„“'` for Russian, `'„“‚‘'` for German, and
159
+ * `['«\xA0', '\xA0»', '‹\xA0', '\xA0›']` for French (including nbsp).
160
+ * - __highlight__ - `null`. Highlighter function for fenced code blocks.
161
+ * Highlighter `function (str, lang)` should return escaped HTML. It can also
162
+ * return empty string if the source was not changed and should be escaped
163
+ * externaly. If result starts with <pre... internal wrapper is skipped.
164
+ *
165
+ * ##### Example
166
+ *
167
+ * ```javascript
168
+ * // commonmark mode
169
+ * var md = require('markdown-it')('commonmark');
170
+ *
171
+ * // default mode
172
+ * var md = require('markdown-it')();
173
+ *
174
+ * // enable everything
175
+ * var md = require('markdown-it')({
176
+ * html: true,
177
+ * linkify: true,
178
+ * typographer: true
179
+ * });
180
+ * ```
181
+ *
182
+ * ##### Syntax highlighting
183
+ *
184
+ * ```js
185
+ * var hljs = require('highlight.js') // https://highlightjs.org/
186
+ *
187
+ * var md = require('markdown-it')({
188
+ * highlight: function (str, lang) {
189
+ * if (lang && hljs.getLanguage(lang)) {
190
+ * try {
191
+ * return hljs.highlight(str, { language: lang, ignoreIllegals: true }).value;
192
+ * } catch (__) {}
193
+ * }
194
+ *
195
+ * return ''; // use external default escaping
196
+ * }
197
+ * });
198
+ * ```
199
+ *
200
+ * Or with full wrapper override (if you need assign class to `<pre>`):
201
+ *
202
+ * ```javascript
203
+ * var hljs = require('highlight.js') // https://highlightjs.org/
204
+ *
205
+ * // Actual default values
206
+ * var md = require('markdown-it')({
207
+ * highlight: function (str, lang) {
208
+ * if (lang && hljs.getLanguage(lang)) {
209
+ * try {
210
+ * return '<pre class="hljs"><code>' +
211
+ * hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
212
+ * '</code></pre>';
213
+ * } catch (__) {}
214
+ * }
215
+ *
216
+ * return '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
217
+ * }
218
+ * });
219
+ * ```
220
+ *
221
+ **/
222
+ function MarkdownIt(presetName, options) {
223
+ if (!(this instanceof MarkdownIt)) {
224
+ return new MarkdownIt(presetName, options);
225
+ }
226
+
227
+ if (!options) {
228
+ if (!utils.isString(presetName)) {
229
+ options = presetName || {};
230
+ presetName = 'default';
231
+ }
232
+ }
233
+
234
+ /**
235
+ * MarkdownIt#inline -> ParserInline
236
+ *
237
+ * Instance of [[ParserInline]]. You may need it to add new rules when
238
+ * writing plugins. For simple rules control use [[MarkdownIt.disable]] and
239
+ * [[MarkdownIt.enable]].
240
+ **/
241
+ this.inline = new ParserInline();
242
+
243
+ /**
244
+ * MarkdownIt#block -> ParserBlock
245
+ *
246
+ * Instance of [[ParserBlock]]. You may need it to add new rules when
247
+ * writing plugins. For simple rules control use [[MarkdownIt.disable]] and
248
+ * [[MarkdownIt.enable]].
249
+ **/
250
+ this.block = new ParserBlock();
251
+
252
+ /**
253
+ * MarkdownIt#core -> Core
254
+ *
255
+ * Instance of [[Core]] chain executor. You may need it to add new rules when
256
+ * writing plugins. For simple rules control use [[MarkdownIt.disable]] and
257
+ * [[MarkdownIt.enable]].
258
+ **/
259
+ this.core = new ParserCore();
260
+
261
+ /**
262
+ * MarkdownIt#renderer -> Renderer
263
+ *
264
+ * Instance of [[Renderer]]. Use it to modify output look. Or to add rendering
265
+ * rules for new token types, generated by plugins.
266
+ *
267
+ * ##### Example
268
+ *
269
+ * ```javascript
270
+ * var md = require('markdown-it')();
271
+ *
272
+ * function myToken(tokens, idx, options, env, self) {
273
+ * //...
274
+ * return result;
275
+ * };
276
+ *
277
+ * md.renderer.rules['my_token'] = myToken
278
+ * ```
279
+ *
280
+ * See [[Renderer]] docs and [source code](https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.js).
281
+ **/
282
+ this.renderer = new Renderer();
283
+
284
+ /**
285
+ * MarkdownIt#linkify -> LinkifyIt
286
+ *
287
+ * [linkify-it](https://github.com/markdown-it/linkify-it) instance.
288
+ * Used by [linkify](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/linkify.js)
289
+ * rule.
290
+ **/
291
+ this.linkify = new LinkifyIt();
292
+
293
+ /**
294
+ * MarkdownIt#validateLink(url) -> Boolean
295
+ *
296
+ * Link validation function. CommonMark allows too much in links. By default
297
+ * we disable `javascript:`, `vbscript:`, `file:` schemas, and almost all `data:...` schemas
298
+ * except some embedded image types.
299
+ *
300
+ * You can change this behaviour:
301
+ *
302
+ * ```javascript
303
+ * var md = require('markdown-it')();
304
+ * // enable everything
305
+ * md.validateLink = function () { return true; }
306
+ * ```
307
+ **/
308
+ this.validateLink = validateLink;
309
+
310
+ /**
311
+ * MarkdownIt#normalizeLink(url) -> String
312
+ *
313
+ * Function used to encode link url to a machine-readable format,
314
+ * which includes url-encoding, punycode, etc.
315
+ **/
316
+ this.normalizeLink = normalizeLink;
317
+
318
+ /**
319
+ * MarkdownIt#normalizeLinkText(url) -> String
320
+ *
321
+ * Function used to decode link url to a human-readable format`
322
+ **/
323
+ this.normalizeLinkText = normalizeLinkText;
324
+
325
+
326
+ // Expose utils & helpers for easy acces from plugins
327
+
328
+ /**
329
+ * MarkdownIt#utils -> utils
330
+ *
331
+ * Assorted utility functions, useful to write plugins. See details
332
+ * [here](https://github.com/markdown-it/markdown-it/blob/master/lib/common/utils.js).
333
+ **/
334
+ this.utils = utils;
335
+
336
+ /**
337
+ * MarkdownIt#helpers -> helpers
338
+ *
339
+ * Link components parser functions, useful to write plugins. See details
340
+ * [here](https://github.com/markdown-it/markdown-it/blob/master/lib/helpers).
341
+ **/
342
+ this.helpers = utils.assign({}, helpers);
343
+
344
+
345
+ this.options = {};
346
+ this.configure(presetName);
347
+
348
+ if (options) { this.set(options); }
349
+ }
350
+
351
+
352
+ /** chainable
353
+ * MarkdownIt.set(options)
354
+ *
355
+ * Set parser options (in the same format as in constructor). Probably, you
356
+ * will never need it, but you can change options after constructor call.
357
+ *
358
+ * ##### Example
359
+ *
360
+ * ```javascript
361
+ * var md = require('markdown-it')()
362
+ * .set({ html: true, breaks: true })
363
+ * .set({ typographer, true });
364
+ * ```
365
+ *
366
+ * __Note:__ To achieve the best possible performance, don't modify a
367
+ * `markdown-it` instance options on the fly. If you need multiple configurations
368
+ * it's best to create multiple instances and initialize each with separate
369
+ * config.
370
+ **/
371
+ MarkdownIt.prototype.set = function (options) {
372
+ utils.assign(this.options, options);
373
+ return this;
374
+ };
375
+
376
+
377
+ /** chainable, internal
378
+ * MarkdownIt.configure(presets)
379
+ *
380
+ * Batch load of all options and compenent settings. This is internal method,
381
+ * and you probably will not need it. But if you will - see available presets
382
+ * and data structure [here](https://github.com/markdown-it/markdown-it/tree/master/lib/presets)
383
+ *
384
+ * We strongly recommend to use presets instead of direct config loads. That
385
+ * will give better compatibility with next versions.
386
+ **/
387
+ MarkdownIt.prototype.configure = function (presets) {
388
+ var self = this, presetName;
389
+
390
+ if (utils.isString(presets)) {
391
+ presetName = presets;
392
+ presets = config[presetName];
393
+ if (!presets) { throw new Error('Wrong `markdown-it` preset "' + presetName + '", check name'); }
394
+ }
395
+
396
+ if (!presets) { throw new Error('Wrong `markdown-it` preset, can\'t be empty'); }
397
+
398
+ if (presets.options) { self.set(presets.options); }
399
+
400
+ if (presets.components) {
401
+ Object.keys(presets.components).forEach(function (name) {
402
+ if (presets.components[name].rules) {
403
+ self[name].ruler.enableOnly(presets.components[name].rules);
404
+ }
405
+ if (presets.components[name].rules2) {
406
+ self[name].ruler2.enableOnly(presets.components[name].rules2);
407
+ }
408
+ });
409
+ }
410
+ return this;
411
+ };
412
+
413
+
414
+ /** chainable
415
+ * MarkdownIt.enable(list, ignoreInvalid)
416
+ * - list (String|Array): rule name or list of rule names to enable
417
+ * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found.
418
+ *
419
+ * Enable list or rules. It will automatically find appropriate components,
420
+ * containing rules with given names. If rule not found, and `ignoreInvalid`
421
+ * not set - throws exception.
422
+ *
423
+ * ##### Example
424
+ *
425
+ * ```javascript
426
+ * var md = require('markdown-it')()
427
+ * .enable(['sub', 'sup'])
428
+ * .disable('smartquotes');
429
+ * ```
430
+ **/
431
+ MarkdownIt.prototype.enable = function (list, ignoreInvalid) {
432
+ var result = [];
433
+
434
+ if (!Array.isArray(list)) { list = [ list ]; }
435
+
436
+ [ 'core', 'block', 'inline' ].forEach(function (chain) {
437
+ result = result.concat(this[chain].ruler.enable(list, true));
438
+ }, this);
439
+
440
+ result = result.concat(this.inline.ruler2.enable(list, true));
441
+
442
+ var missed = list.filter(function (name) { return result.indexOf(name) < 0; });
443
+
444
+ if (missed.length && !ignoreInvalid) {
445
+ throw new Error('MarkdownIt. Failed to enable unknown rule(s): ' + missed);
446
+ }
447
+
448
+ return this;
449
+ };
450
+
451
+
452
+ /** chainable
453
+ * MarkdownIt.disable(list, ignoreInvalid)
454
+ * - list (String|Array): rule name or list of rule names to disable.
455
+ * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found.
456
+ *
457
+ * The same as [[MarkdownIt.enable]], but turn specified rules off.
458
+ **/
459
+ MarkdownIt.prototype.disable = function (list, ignoreInvalid) {
460
+ var result = [];
461
+
462
+ if (!Array.isArray(list)) { list = [ list ]; }
463
+
464
+ [ 'core', 'block', 'inline' ].forEach(function (chain) {
465
+ result = result.concat(this[chain].ruler.disable(list, true));
466
+ }, this);
467
+
468
+ result = result.concat(this.inline.ruler2.disable(list, true));
469
+
470
+ var missed = list.filter(function (name) { return result.indexOf(name) < 0; });
471
+
472
+ if (missed.length && !ignoreInvalid) {
473
+ throw new Error('MarkdownIt. Failed to disable unknown rule(s): ' + missed);
474
+ }
475
+ return this;
476
+ };
477
+
478
+
479
+ /** chainable
480
+ * MarkdownIt.use(plugin, params)
481
+ *
482
+ * Load specified plugin with given params into current parser instance.
483
+ * It's just a sugar to call `plugin(md, params)` with curring.
484
+ *
485
+ * ##### Example
486
+ *
487
+ * ```javascript
488
+ * var iterator = require('markdown-it-for-inline');
489
+ * var md = require('markdown-it')()
490
+ * .use(iterator, 'foo_replace', 'text', function (tokens, idx) {
491
+ * tokens[idx].content = tokens[idx].content.replace(/foo/g, 'bar');
492
+ * });
493
+ * ```
494
+ **/
495
+ MarkdownIt.prototype.use = function (plugin /*, params, ... */) {
496
+ var args = [ this ].concat(Array.prototype.slice.call(arguments, 1));
497
+ plugin.apply(plugin, args);
498
+ return this;
499
+ };
500
+
501
+
502
+ /** internal
503
+ * MarkdownIt.parse(src, env) -> Array
504
+ * - src (String): source string
505
+ * - env (Object): environment sandbox
506
+ *
507
+ * Parse input string and return list of block tokens (special token type
508
+ * "inline" will contain list of inline tokens). You should not call this
509
+ * method directly, until you write custom renderer (for example, to produce
510
+ * AST).
511
+ *
512
+ * `env` is used to pass data between "distributed" rules and return additional
513
+ * metadata like reference info, needed for the renderer. It also can be used to
514
+ * inject data in specific cases. Usually, you will be ok to pass `{}`,
515
+ * and then pass updated object to renderer.
516
+ **/
517
+ MarkdownIt.prototype.parse = function (src, env) {
518
+ if (typeof src !== 'string') {
519
+ throw new Error('Input data should be a String');
520
+ }
521
+
522
+ var state = new this.core.State(src, this, env);
523
+
524
+ this.core.process(state);
525
+
526
+ return state.tokens;
527
+ };
528
+
529
+
530
+ /**
531
+ * MarkdownIt.render(src [, env]) -> String
532
+ * - src (String): source string
533
+ * - env (Object): environment sandbox
534
+ *
535
+ * Render markdown string into html. It does all magic for you :).
536
+ *
537
+ * `env` can be used to inject additional metadata (`{}` by default).
538
+ * But you will not need it with high probability. See also comment
539
+ * in [[MarkdownIt.parse]].
540
+ **/
541
+ MarkdownIt.prototype.render = function (src, env) {
542
+ env = env || {};
543
+
544
+ return this.renderer.render(this.parse(src, env), this.options, env);
545
+ };
546
+
547
+
548
+ /** internal
549
+ * MarkdownIt.parseInline(src, env) -> Array
550
+ * - src (String): source string
551
+ * - env (Object): environment sandbox
552
+ *
553
+ * The same as [[MarkdownIt.parse]] but skip all block rules. It returns the
554
+ * block tokens list with the single `inline` element, containing parsed inline
555
+ * tokens in `children` property. Also updates `env` object.
556
+ **/
557
+ MarkdownIt.prototype.parseInline = function (src, env) {
558
+ var state = new this.core.State(src, this, env);
559
+
560
+ state.inlineMode = true;
561
+ this.core.process(state);
562
+
563
+ return state.tokens;
564
+ };
565
+
566
+
567
+ /**
568
+ * MarkdownIt.renderInline(src [, env]) -> String
569
+ * - src (String): source string
570
+ * - env (Object): environment sandbox
571
+ *
572
+ * Similar to [[MarkdownIt.render]] but for single paragraph content. Result
573
+ * will NOT be wrapped into `<p>` tags.
574
+ **/
575
+ MarkdownIt.prototype.renderInline = function (src, env) {
576
+ env = env || {};
577
+
578
+ return this.renderer.render(this.parseInline(src, env), this.options, env);
579
+ };
580
+
581
+
582
+ module.exports = MarkdownIt;
@@ -0,0 +1,131 @@
1
+ /** internal
2
+ * class ParserBlock
3
+ *
4
+ * Block-level tokenizer.
5
+ **/
6
+ 'use strict';
7
+
8
+
9
+ var Ruler = require('./ruler');
10
+
11
+
12
+ var _rules = [
13
+ // First 2 params - rule name & source. Secondary array - list of rules,
14
+ // which can be terminated by this one.
15
+ [ 'table', require('./rules_block/table'), [ 'paragraph', 'reference' ] ],
16
+ [ 'code', require('./rules_block/code') ],
17
+ [ 'fence', require('./rules_block/fence'), [ 'paragraph', 'reference', 'blockquote', 'list' ] ],
18
+ [ 'blockquote', require('./rules_block/blockquote'), [ 'paragraph', 'reference', 'blockquote', 'list' ] ],
19
+ [ 'hr', require('./rules_block/hr'), [ 'paragraph', 'reference', 'blockquote', 'list' ] ],
20
+ [ 'list', require('./rules_block/list'), [ 'paragraph', 'reference', 'blockquote' ] ],
21
+ [ 'reference', require('./rules_block/reference') ],
22
+ [ 'html_block', require('./rules_block/html_block'), [ 'paragraph', 'reference', 'blockquote' ] ],
23
+ [ 'heading', require('./rules_block/heading'), [ 'paragraph', 'reference', 'blockquote' ] ],
24
+ [ 'lheading', require('./rules_block/lheading') ],
25
+ [ 'paragraph', require('./rules_block/paragraph') ]
26
+ ];
27
+
28
+
29
+ /**
30
+ * new ParserBlock()
31
+ **/
32
+ function ParserBlock() {
33
+ /**
34
+ * ParserBlock#ruler -> Ruler
35
+ *
36
+ * [[Ruler]] instance. Keep configuration of block rules.
37
+ **/
38
+ this.ruler = new Ruler();
39
+
40
+ for (var i = 0; i < _rules.length; i++) {
41
+ this.ruler.push(_rules[i][0], _rules[i][1], { alt: (_rules[i][2] || []).slice() });
42
+ }
43
+ }
44
+
45
+
46
+ // Generate tokens for input range
47
+ //
48
+ ParserBlock.prototype.tokenize = function (state, startLine, endLine) {
49
+ var ok, i, prevLine,
50
+ rules = this.ruler.getRules(''),
51
+ len = rules.length,
52
+ line = startLine,
53
+ hasEmptyLines = false,
54
+ maxNesting = state.md.options.maxNesting;
55
+
56
+ while (line < endLine) {
57
+ state.line = line = state.skipEmptyLines(line);
58
+ if (line >= endLine) { break; }
59
+
60
+ // Termination condition for nested calls.
61
+ // Nested calls currently used for blockquotes & lists
62
+ if (state.sCount[line] < state.blkIndent) { break; }
63
+
64
+ // If nesting level exceeded - skip tail to the end. That's not ordinary
65
+ // situation and we should not care about content.
66
+ if (state.level >= maxNesting) {
67
+ state.line = endLine;
68
+ break;
69
+ }
70
+
71
+ // Try all possible rules.
72
+ // On success, rule should:
73
+ //
74
+ // - update `state.line`
75
+ // - update `state.tokens`
76
+ // - return true
77
+ prevLine = state.line;
78
+
79
+ for (i = 0; i < len; i++) {
80
+ ok = rules[i](state, line, endLine, false);
81
+ if (ok) {
82
+ if (prevLine >= state.line) {
83
+ throw new Error("block rule didn't increment state.line");
84
+ }
85
+ break;
86
+ }
87
+ }
88
+
89
+ // this can only happen if user disables paragraph rule
90
+ if (!ok) throw new Error('none of the block rules matched');
91
+
92
+ // set state.tight if we had an empty line before current tag
93
+ // i.e. latest empty line should not count
94
+ state.tight = !hasEmptyLines;
95
+
96
+ // paragraph might "eat" one newline after it in nested lists
97
+ if (state.isEmpty(state.line - 1)) {
98
+ hasEmptyLines = true;
99
+ }
100
+
101
+ line = state.line;
102
+
103
+ if (line < endLine && state.isEmpty(line)) {
104
+ hasEmptyLines = true;
105
+ line++;
106
+ state.line = line;
107
+ }
108
+ }
109
+ };
110
+
111
+
112
+ /**
113
+ * ParserBlock.parse(str, md, env, outTokens)
114
+ *
115
+ * Process input string and push block tokens into `outTokens`
116
+ **/
117
+ ParserBlock.prototype.parse = function (src, md, env, outTokens) {
118
+ var state;
119
+
120
+ if (!src) { return; }
121
+
122
+ state = new this.State(src, md, env, outTokens);
123
+
124
+ this.tokenize(state, state.line, state.lineMax);
125
+ };
126
+
127
+
128
+ ParserBlock.prototype.State = require('./rules_block/state_block');
129
+
130
+
131
+ module.exports = ParserBlock;