@alexlit/lint-kit 107.0.0 → 107.2.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 (193) hide show
  1. package/package.json +1 -11
  2. package/packages/config-commitlint/package.json +2 -2
  3. package/packages/config-eslint/package.json +4 -4
  4. package/packages/config-hooks/package.json +3 -3
  5. package/packages/config-markdownlint/node_modules/markdown-it/LICENSE +22 -0
  6. package/packages/config-markdownlint/node_modules/markdown-it/README.md +309 -0
  7. package/packages/config-markdownlint/node_modules/markdown-it/bin/markdown-it.js +117 -0
  8. package/packages/config-markdownlint/node_modules/markdown-it/dist/markdown-it.js +8441 -0
  9. package/packages/config-markdownlint/node_modules/markdown-it/dist/markdown-it.min.js +3 -0
  10. package/packages/config-markdownlint/node_modules/markdown-it/index.js +4 -0
  11. package/packages/config-markdownlint/node_modules/markdown-it/lib/common/entities.js +6 -0
  12. package/packages/config-markdownlint/node_modules/markdown-it/lib/common/html_blocks.js +70 -0
  13. package/packages/config-markdownlint/node_modules/markdown-it/lib/common/html_re.js +28 -0
  14. package/packages/config-markdownlint/node_modules/markdown-it/lib/common/utils.js +317 -0
  15. package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/index.js +7 -0
  16. package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/parse_link_destination.js +80 -0
  17. package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/parse_link_label.js +48 -0
  18. package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/parse_link_title.js +55 -0
  19. package/packages/config-markdownlint/node_modules/markdown-it/lib/index.js +582 -0
  20. package/packages/config-markdownlint/node_modules/markdown-it/lib/parser_block.js +131 -0
  21. package/packages/config-markdownlint/node_modules/markdown-it/lib/parser_core.js +61 -0
  22. package/packages/config-markdownlint/node_modules/markdown-it/lib/parser_inline.js +192 -0
  23. package/packages/config-markdownlint/node_modules/markdown-it/lib/presets/commonmark.js +81 -0
  24. package/packages/config-markdownlint/node_modules/markdown-it/lib/presets/default.js +41 -0
  25. package/packages/config-markdownlint/node_modules/markdown-it/lib/presets/zero.js +63 -0
  26. package/packages/config-markdownlint/node_modules/markdown-it/lib/renderer.js +341 -0
  27. package/packages/config-markdownlint/node_modules/markdown-it/lib/ruler.js +352 -0
  28. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/blockquote.js +226 -0
  29. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/code.js +34 -0
  30. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/fence.js +98 -0
  31. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/heading.js +55 -0
  32. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/hr.js +45 -0
  33. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/html_block.js +74 -0
  34. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/lheading.js +83 -0
  35. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/list.js +362 -0
  36. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/paragraph.js +51 -0
  37. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/reference.js +198 -0
  38. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/state_block.js +231 -0
  39. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/table.js +221 -0
  40. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/block.js +16 -0
  41. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/inline.js +13 -0
  42. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/linkify.js +142 -0
  43. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/normalize.js +21 -0
  44. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/replacements.js +105 -0
  45. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/smartquotes.js +201 -0
  46. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/state_core.js +20 -0
  47. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/text_join.js +45 -0
  48. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/autolink.js +76 -0
  49. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/backticks.js +63 -0
  50. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/balance_pairs.js +130 -0
  51. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/emphasis.js +130 -0
  52. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/entity.js +55 -0
  53. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/escape.js +71 -0
  54. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/fragments_join.js +41 -0
  55. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/html_inline.js +58 -0
  56. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/image.js +152 -0
  57. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/link.js +150 -0
  58. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/linkify.js +62 -0
  59. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/newline.js +46 -0
  60. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/state_inline.js +158 -0
  61. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/strikethrough.js +130 -0
  62. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/text.js +89 -0
  63. package/packages/config-markdownlint/node_modules/markdown-it/lib/token.js +201 -0
  64. package/packages/config-markdownlint/node_modules/markdown-it/package.json +87 -0
  65. package/packages/config-markdownlint/node_modules/markdownlint/CHANGELOG.md +428 -0
  66. package/packages/config-markdownlint/node_modules/markdownlint/CONTRIBUTING.md +92 -0
  67. package/packages/config-markdownlint/node_modules/markdownlint/LICENSE +21 -0
  68. package/packages/config-markdownlint/node_modules/markdownlint/README.md +1026 -0
  69. package/packages/config-markdownlint/node_modules/markdownlint/demo/markdownlint-browser.js +6814 -0
  70. package/packages/config-markdownlint/node_modules/markdownlint/doc/CustomRules.md +376 -0
  71. package/packages/config-markdownlint/node_modules/markdownlint/doc/Prettier.md +27 -0
  72. package/packages/config-markdownlint/node_modules/markdownlint/doc/ReleaseProcess.md +20 -0
  73. package/packages/config-markdownlint/node_modules/markdownlint/doc/Rules.md +2335 -0
  74. package/packages/config-markdownlint/node_modules/markdownlint/doc/md001.md +37 -0
  75. package/packages/config-markdownlint/node_modules/markdownlint/doc/md003.md +59 -0
  76. package/packages/config-markdownlint/node_modules/markdownlint/doc/md004.md +49 -0
  77. package/packages/config-markdownlint/node_modules/markdownlint/doc/md005.md +53 -0
  78. package/packages/config-markdownlint/node_modules/markdownlint/doc/md007.md +52 -0
  79. package/packages/config-markdownlint/node_modules/markdownlint/doc/md009.md +51 -0
  80. package/packages/config-markdownlint/node_modules/markdownlint/doc/md010.md +56 -0
  81. package/packages/config-markdownlint/node_modules/markdownlint/doc/md011.md +30 -0
  82. package/packages/config-markdownlint/node_modules/markdownlint/doc/md012.md +38 -0
  83. package/packages/config-markdownlint/node_modules/markdownlint/doc/md013.md +57 -0
  84. package/packages/config-markdownlint/node_modules/markdownlint/doc/md014.md +54 -0
  85. package/packages/config-markdownlint/node_modules/markdownlint/doc/md018.md +27 -0
  86. package/packages/config-markdownlint/node_modules/markdownlint/doc/md019.md +28 -0
  87. package/packages/config-markdownlint/node_modules/markdownlint/doc/md020.md +29 -0
  88. package/packages/config-markdownlint/node_modules/markdownlint/doc/md021.md +31 -0
  89. package/packages/config-markdownlint/node_modules/markdownlint/doc/md022.md +52 -0
  90. package/packages/config-markdownlint/node_modules/markdownlint/doc/md023.md +33 -0
  91. package/packages/config-markdownlint/node_modules/markdownlint/doc/md024.md +47 -0
  92. package/packages/config-markdownlint/node_modules/markdownlint/doc/md025.md +49 -0
  93. package/packages/config-markdownlint/node_modules/markdownlint/doc/md026.md +40 -0
  94. package/packages/config-markdownlint/node_modules/markdownlint/doc/md027.md +24 -0
  95. package/packages/config-markdownlint/node_modules/markdownlint/doc/md028.md +40 -0
  96. package/packages/config-markdownlint/node_modules/markdownlint/doc/md029.md +98 -0
  97. package/packages/config-markdownlint/node_modules/markdownlint/doc/md030.md +82 -0
  98. package/packages/config-markdownlint/node_modules/markdownlint/doc/md031.md +50 -0
  99. package/packages/config-markdownlint/node_modules/markdownlint/doc/md032.md +55 -0
  100. package/packages/config-markdownlint/node_modules/markdownlint/doc/md033.md +27 -0
  101. package/packages/config-markdownlint/node_modules/markdownlint/doc/md034.md +50 -0
  102. package/packages/config-markdownlint/node_modules/markdownlint/doc/md035.md +42 -0
  103. package/packages/config-markdownlint/node_modules/markdownlint/doc/md036.md +45 -0
  104. package/packages/config-markdownlint/node_modules/markdownlint/doc/md037.md +37 -0
  105. package/packages/config-markdownlint/node_modules/markdownlint/doc/md038.md +40 -0
  106. package/packages/config-markdownlint/node_modules/markdownlint/doc/md039.md +21 -0
  107. package/packages/config-markdownlint/node_modules/markdownlint/doc/md040.md +52 -0
  108. package/packages/config-markdownlint/node_modules/markdownlint/doc/md041.md +49 -0
  109. package/packages/config-markdownlint/node_modules/markdownlint/doc/md042.md +32 -0
  110. package/packages/config-markdownlint/node_modules/markdownlint/doc/md043.md +69 -0
  111. package/packages/config-markdownlint/node_modules/markdownlint/doc/md044.md +35 -0
  112. package/packages/config-markdownlint/node_modules/markdownlint/doc/md045.md +40 -0
  113. package/packages/config-markdownlint/node_modules/markdownlint/doc/md046.md +40 -0
  114. package/packages/config-markdownlint/node_modules/markdownlint/doc/md047.md +34 -0
  115. package/packages/config-markdownlint/node_modules/markdownlint/doc/md048.md +41 -0
  116. package/packages/config-markdownlint/node_modules/markdownlint/doc/md049.md +32 -0
  117. package/packages/config-markdownlint/node_modules/markdownlint/doc/md050.md +32 -0
  118. package/packages/config-markdownlint/node_modules/markdownlint/doc/md051.md +61 -0
  119. package/packages/config-markdownlint/node_modules/markdownlint/doc/md052.md +40 -0
  120. package/packages/config-markdownlint/node_modules/markdownlint/doc/md053.md +38 -0
  121. package/packages/config-markdownlint/node_modules/markdownlint/doc/md054.md +100 -0
  122. package/packages/config-markdownlint/node_modules/markdownlint/helpers/LICENSE +21 -0
  123. package/packages/config-markdownlint/node_modules/markdownlint/helpers/README.md +70 -0
  124. package/packages/config-markdownlint/node_modules/markdownlint/helpers/helpers.js +1025 -0
  125. package/packages/config-markdownlint/node_modules/markdownlint/helpers/micromark.cjs +426 -0
  126. package/packages/config-markdownlint/node_modules/markdownlint/helpers/package.json +26 -0
  127. package/packages/config-markdownlint/node_modules/markdownlint/helpers/shared.js +10 -0
  128. package/packages/config-markdownlint/node_modules/markdownlint/lib/cache.js +21 -0
  129. package/packages/config-markdownlint/node_modules/markdownlint/lib/configuration.d.ts +1152 -0
  130. package/packages/config-markdownlint/node_modules/markdownlint/lib/constants.js +14 -0
  131. package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.d.ts +406 -0
  132. package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.js +1476 -0
  133. package/packages/config-markdownlint/node_modules/markdownlint/lib/md001.js +22 -0
  134. package/packages/config-markdownlint/node_modules/markdownlint/lib/md003.js +42 -0
  135. package/packages/config-markdownlint/node_modules/markdownlint/lib/md004.js +76 -0
  136. package/packages/config-markdownlint/node_modules/markdownlint/lib/md005.js +73 -0
  137. package/packages/config-markdownlint/node_modules/markdownlint/lib/md007.js +86 -0
  138. package/packages/config-markdownlint/node_modules/markdownlint/lib/md009.js +86 -0
  139. package/packages/config-markdownlint/node_modules/markdownlint/lib/md010.js +60 -0
  140. package/packages/config-markdownlint/node_modules/markdownlint/lib/md011.js +46 -0
  141. package/packages/config-markdownlint/node_modules/markdownlint/lib/md012.js +32 -0
  142. package/packages/config-markdownlint/node_modules/markdownlint/lib/md013.js +96 -0
  143. package/packages/config-markdownlint/node_modules/markdownlint/lib/md014.js +53 -0
  144. package/packages/config-markdownlint/node_modules/markdownlint/lib/md018.js +34 -0
  145. package/packages/config-markdownlint/node_modules/markdownlint/lib/md019.js +39 -0
  146. package/packages/config-markdownlint/node_modules/markdownlint/lib/md020.js +62 -0
  147. package/packages/config-markdownlint/node_modules/markdownlint/lib/md021.js +62 -0
  148. package/packages/config-markdownlint/node_modules/markdownlint/lib/md022.js +108 -0
  149. package/packages/config-markdownlint/node_modules/markdownlint/lib/md023.js +38 -0
  150. package/packages/config-markdownlint/node_modules/markdownlint/lib/md024.js +38 -0
  151. package/packages/config-markdownlint/node_modules/markdownlint/lib/md025.js +32 -0
  152. package/packages/config-markdownlint/node_modules/markdownlint/lib/md026.js +50 -0
  153. package/packages/config-markdownlint/node_modules/markdownlint/lib/md027.js +56 -0
  154. package/packages/config-markdownlint/node_modules/markdownlint/lib/md028.js +30 -0
  155. package/packages/config-markdownlint/node_modules/markdownlint/lib/md029.js +67 -0
  156. package/packages/config-markdownlint/node_modules/markdownlint/lib/md030.js +61 -0
  157. package/packages/config-markdownlint/node_modules/markdownlint/lib/md031.js +40 -0
  158. package/packages/config-markdownlint/node_modules/markdownlint/lib/md032.js +78 -0
  159. package/packages/config-markdownlint/node_modules/markdownlint/lib/md033.js +39 -0
  160. package/packages/config-markdownlint/node_modules/markdownlint/lib/md034.js +79 -0
  161. package/packages/config-markdownlint/node_modules/markdownlint/lib/md035.js +24 -0
  162. package/packages/config-markdownlint/node_modules/markdownlint/lib/md036.js +56 -0
  163. package/packages/config-markdownlint/node_modules/markdownlint/lib/md037.js +91 -0
  164. package/packages/config-markdownlint/node_modules/markdownlint/lib/md038.js +97 -0
  165. package/packages/config-markdownlint/node_modules/markdownlint/lib/md039.js +67 -0
  166. package/packages/config-markdownlint/node_modules/markdownlint/lib/md040.js +37 -0
  167. package/packages/config-markdownlint/node_modules/markdownlint/lib/md041.js +42 -0
  168. package/packages/config-markdownlint/node_modules/markdownlint/lib/md042.js +49 -0
  169. package/packages/config-markdownlint/node_modules/markdownlint/lib/md043.js +64 -0
  170. package/packages/config-markdownlint/node_modules/markdownlint/lib/md044.js +107 -0
  171. package/packages/config-markdownlint/node_modules/markdownlint/lib/md045.js +60 -0
  172. package/packages/config-markdownlint/node_modules/markdownlint/lib/md046.js +33 -0
  173. package/packages/config-markdownlint/node_modules/markdownlint/lib/md047.js +28 -0
  174. package/packages/config-markdownlint/node_modules/markdownlint/lib/md048.js +30 -0
  175. package/packages/config-markdownlint/node_modules/markdownlint/lib/md049-md050.js +89 -0
  176. package/packages/config-markdownlint/node_modules/markdownlint/lib/md051.js +172 -0
  177. package/packages/config-markdownlint/node_modules/markdownlint/lib/md052.js +39 -0
  178. package/packages/config-markdownlint/node_modules/markdownlint/lib/md053.js +59 -0
  179. package/packages/config-markdownlint/node_modules/markdownlint/lib/md054.js +125 -0
  180. package/packages/config-markdownlint/node_modules/markdownlint/lib/rules.js +65 -0
  181. package/packages/config-markdownlint/node_modules/markdownlint/package.json +109 -0
  182. package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.jsonc +297 -0
  183. package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.yaml +266 -0
  184. package/packages/config-markdownlint/node_modules/markdownlint/schema/markdownlint-config-schema.json +1762 -0
  185. package/packages/config-markdownlint/node_modules/markdownlint/style/all.json +5 -0
  186. package/packages/config-markdownlint/node_modules/markdownlint/style/cirosantilli.json +22 -0
  187. package/packages/config-markdownlint/node_modules/markdownlint/style/prettier.json +26 -0
  188. package/packages/config-markdownlint/node_modules/markdownlint/style/relaxed.json +12 -0
  189. package/packages/config-markdownlint/package.json +3 -3
  190. package/packages/config-prettier/README.md +16 -0
  191. package/packages/config-prettier/package.json +4 -4
  192. package/packages/config-stylelint/package.json +2 -2
  193. package/scripts/semver.sh +6 -5
@@ -0,0 +1,341 @@
1
+ /**
2
+ * class Renderer
3
+ *
4
+ * Generates HTML from parsed token stream. Each instance has independent
5
+ * copy of rules. Those can be rewritten with ease. Also, you can add new
6
+ * rules if you create plugin and adds new token types.
7
+ **/
8
+ 'use strict';
9
+
10
+
11
+ var assign = require('./common/utils').assign;
12
+ var unescapeAll = require('./common/utils').unescapeAll;
13
+ var escapeHtml = require('./common/utils').escapeHtml;
14
+
15
+
16
+ ////////////////////////////////////////////////////////////////////////////////
17
+
18
+ var default_rules = {};
19
+
20
+
21
+ default_rules.code_inline = function (tokens, idx, options, env, slf) {
22
+ var token = tokens[idx];
23
+
24
+ return '<code' + slf.renderAttrs(token) + '>' +
25
+ escapeHtml(token.content) +
26
+ '</code>';
27
+ };
28
+
29
+
30
+ default_rules.code_block = function (tokens, idx, options, env, slf) {
31
+ var token = tokens[idx];
32
+
33
+ return '<pre' + slf.renderAttrs(token) + '><code>' +
34
+ escapeHtml(tokens[idx].content) +
35
+ '</code></pre>\n';
36
+ };
37
+
38
+
39
+ default_rules.fence = function (tokens, idx, options, env, slf) {
40
+ var token = tokens[idx],
41
+ info = token.info ? unescapeAll(token.info).trim() : '',
42
+ langName = '',
43
+ langAttrs = '',
44
+ highlighted, i, arr, tmpAttrs, tmpToken;
45
+
46
+ if (info) {
47
+ arr = info.split(/(\s+)/g);
48
+ langName = arr[0];
49
+ langAttrs = arr.slice(2).join('');
50
+ }
51
+
52
+ if (options.highlight) {
53
+ highlighted = options.highlight(token.content, langName, langAttrs) || escapeHtml(token.content);
54
+ } else {
55
+ highlighted = escapeHtml(token.content);
56
+ }
57
+
58
+ if (highlighted.indexOf('<pre') === 0) {
59
+ return highlighted + '\n';
60
+ }
61
+
62
+ // If language exists, inject class gently, without modifying original token.
63
+ // May be, one day we will add .deepClone() for token and simplify this part, but
64
+ // now we prefer to keep things local.
65
+ if (info) {
66
+ i = token.attrIndex('class');
67
+ tmpAttrs = token.attrs ? token.attrs.slice() : [];
68
+
69
+ if (i < 0) {
70
+ tmpAttrs.push([ 'class', options.langPrefix + langName ]);
71
+ } else {
72
+ tmpAttrs[i] = tmpAttrs[i].slice();
73
+ tmpAttrs[i][1] += ' ' + options.langPrefix + langName;
74
+ }
75
+
76
+ // Fake token just to render attributes
77
+ tmpToken = {
78
+ attrs: tmpAttrs
79
+ };
80
+
81
+ return '<pre><code' + slf.renderAttrs(tmpToken) + '>'
82
+ + highlighted
83
+ + '</code></pre>\n';
84
+ }
85
+
86
+
87
+ return '<pre><code' + slf.renderAttrs(token) + '>'
88
+ + highlighted
89
+ + '</code></pre>\n';
90
+ };
91
+
92
+
93
+ default_rules.image = function (tokens, idx, options, env, slf) {
94
+ var token = tokens[idx];
95
+
96
+ // "alt" attr MUST be set, even if empty. Because it's mandatory and
97
+ // should be placed on proper position for tests.
98
+ //
99
+ // Replace content with actual value
100
+
101
+ token.attrs[token.attrIndex('alt')][1] =
102
+ slf.renderInlineAsText(token.children, options, env);
103
+
104
+ return slf.renderToken(tokens, idx, options);
105
+ };
106
+
107
+
108
+ default_rules.hardbreak = function (tokens, idx, options /*, env */) {
109
+ return options.xhtmlOut ? '<br />\n' : '<br>\n';
110
+ };
111
+ default_rules.softbreak = function (tokens, idx, options /*, env */) {
112
+ return options.breaks ? (options.xhtmlOut ? '<br />\n' : '<br>\n') : '\n';
113
+ };
114
+
115
+
116
+ default_rules.text = function (tokens, idx /*, options, env */) {
117
+ return escapeHtml(tokens[idx].content);
118
+ };
119
+
120
+
121
+ default_rules.html_block = function (tokens, idx /*, options, env */) {
122
+ return tokens[idx].content;
123
+ };
124
+ default_rules.html_inline = function (tokens, idx /*, options, env */) {
125
+ return tokens[idx].content;
126
+ };
127
+
128
+
129
+ /**
130
+ * new Renderer()
131
+ *
132
+ * Creates new [[Renderer]] instance and fill [[Renderer#rules]] with defaults.
133
+ **/
134
+ function Renderer() {
135
+
136
+ /**
137
+ * Renderer#rules -> Object
138
+ *
139
+ * Contains render rules for tokens. Can be updated and extended.
140
+ *
141
+ * ##### Example
142
+ *
143
+ * ```javascript
144
+ * var md = require('markdown-it')();
145
+ *
146
+ * md.renderer.rules.strong_open = function () { return '<b>'; };
147
+ * md.renderer.rules.strong_close = function () { return '</b>'; };
148
+ *
149
+ * var result = md.renderInline(...);
150
+ * ```
151
+ *
152
+ * Each rule is called as independent static function with fixed signature:
153
+ *
154
+ * ```javascript
155
+ * function my_token_render(tokens, idx, options, env, renderer) {
156
+ * // ...
157
+ * return renderedHTML;
158
+ * }
159
+ * ```
160
+ *
161
+ * See [source code](https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.js)
162
+ * for more details and examples.
163
+ **/
164
+ this.rules = assign({}, default_rules);
165
+ }
166
+
167
+
168
+ /**
169
+ * Renderer.renderAttrs(token) -> String
170
+ *
171
+ * Render token attributes to string.
172
+ **/
173
+ Renderer.prototype.renderAttrs = function renderAttrs(token) {
174
+ var i, l, result;
175
+
176
+ if (!token.attrs) { return ''; }
177
+
178
+ result = '';
179
+
180
+ for (i = 0, l = token.attrs.length; i < l; i++) {
181
+ result += ' ' + escapeHtml(token.attrs[i][0]) + '="' + escapeHtml(token.attrs[i][1]) + '"';
182
+ }
183
+
184
+ return result;
185
+ };
186
+
187
+
188
+ /**
189
+ * Renderer.renderToken(tokens, idx, options) -> String
190
+ * - tokens (Array): list of tokens
191
+ * - idx (Numbed): token index to render
192
+ * - options (Object): params of parser instance
193
+ *
194
+ * Default token renderer. Can be overriden by custom function
195
+ * in [[Renderer#rules]].
196
+ **/
197
+ Renderer.prototype.renderToken = function renderToken(tokens, idx, options) {
198
+ var nextToken,
199
+ result = '',
200
+ needLf = false,
201
+ token = tokens[idx];
202
+
203
+ // Tight list paragraphs
204
+ if (token.hidden) {
205
+ return '';
206
+ }
207
+
208
+ // Insert a newline between hidden paragraph and subsequent opening
209
+ // block-level tag.
210
+ //
211
+ // For example, here we should insert a newline before blockquote:
212
+ // - a
213
+ // >
214
+ //
215
+ if (token.block && token.nesting !== -1 && idx && tokens[idx - 1].hidden) {
216
+ result += '\n';
217
+ }
218
+
219
+ // Add token name, e.g. `<img`
220
+ result += (token.nesting === -1 ? '</' : '<') + token.tag;
221
+
222
+ // Encode attributes, e.g. `<img src="foo"`
223
+ result += this.renderAttrs(token);
224
+
225
+ // Add a slash for self-closing tags, e.g. `<img src="foo" /`
226
+ if (token.nesting === 0 && options.xhtmlOut) {
227
+ result += ' /';
228
+ }
229
+
230
+ // Check if we need to add a newline after this tag
231
+ if (token.block) {
232
+ needLf = true;
233
+
234
+ if (token.nesting === 1) {
235
+ if (idx + 1 < tokens.length) {
236
+ nextToken = tokens[idx + 1];
237
+
238
+ if (nextToken.type === 'inline' || nextToken.hidden) {
239
+ // Block-level tag containing an inline tag.
240
+ //
241
+ needLf = false;
242
+
243
+ } else if (nextToken.nesting === -1 && nextToken.tag === token.tag) {
244
+ // Opening tag + closing tag of the same type. E.g. `<li></li>`.
245
+ //
246
+ needLf = false;
247
+ }
248
+ }
249
+ }
250
+ }
251
+
252
+ result += needLf ? '>\n' : '>';
253
+
254
+ return result;
255
+ };
256
+
257
+
258
+ /**
259
+ * Renderer.renderInline(tokens, options, env) -> String
260
+ * - tokens (Array): list on block tokens to render
261
+ * - options (Object): params of parser instance
262
+ * - env (Object): additional data from parsed input (references, for example)
263
+ *
264
+ * The same as [[Renderer.render]], but for single token of `inline` type.
265
+ **/
266
+ Renderer.prototype.renderInline = function (tokens, options, env) {
267
+ var type,
268
+ result = '',
269
+ rules = this.rules;
270
+
271
+ for (var i = 0, len = tokens.length; i < len; i++) {
272
+ type = tokens[i].type;
273
+
274
+ if (typeof rules[type] !== 'undefined') {
275
+ result += rules[type](tokens, i, options, env, this);
276
+ } else {
277
+ result += this.renderToken(tokens, i, options);
278
+ }
279
+ }
280
+
281
+ return result;
282
+ };
283
+
284
+
285
+ /** internal
286
+ * Renderer.renderInlineAsText(tokens, options, env) -> String
287
+ * - tokens (Array): list on block tokens to render
288
+ * - options (Object): params of parser instance
289
+ * - env (Object): additional data from parsed input (references, for example)
290
+ *
291
+ * Special kludge for image `alt` attributes to conform CommonMark spec.
292
+ * Don't try to use it! Spec requires to show `alt` content with stripped markup,
293
+ * instead of simple escaping.
294
+ **/
295
+ Renderer.prototype.renderInlineAsText = function (tokens, options, env) {
296
+ var result = '';
297
+
298
+ for (var i = 0, len = tokens.length; i < len; i++) {
299
+ if (tokens[i].type === 'text') {
300
+ result += tokens[i].content;
301
+ } else if (tokens[i].type === 'image') {
302
+ result += this.renderInlineAsText(tokens[i].children, options, env);
303
+ } else if (tokens[i].type === 'softbreak') {
304
+ result += '\n';
305
+ }
306
+ }
307
+
308
+ return result;
309
+ };
310
+
311
+
312
+ /**
313
+ * Renderer.render(tokens, options, env) -> String
314
+ * - tokens (Array): list on block tokens to render
315
+ * - options (Object): params of parser instance
316
+ * - env (Object): additional data from parsed input (references, for example)
317
+ *
318
+ * Takes token stream and generates HTML. Probably, you will never need to call
319
+ * this method directly.
320
+ **/
321
+ Renderer.prototype.render = function (tokens, options, env) {
322
+ var i, len, type,
323
+ result = '',
324
+ rules = this.rules;
325
+
326
+ for (i = 0, len = tokens.length; i < len; i++) {
327
+ type = tokens[i].type;
328
+
329
+ if (type === 'inline') {
330
+ result += this.renderInline(tokens[i].children, options, env);
331
+ } else if (typeof rules[type] !== 'undefined') {
332
+ result += rules[type](tokens, i, options, env, this);
333
+ } else {
334
+ result += this.renderToken(tokens, i, options, env);
335
+ }
336
+ }
337
+
338
+ return result;
339
+ };
340
+
341
+ module.exports = Renderer;
@@ -0,0 +1,352 @@
1
+ /**
2
+ * class Ruler
3
+ *
4
+ * Helper class, used by [[MarkdownIt#core]], [[MarkdownIt#block]] and
5
+ * [[MarkdownIt#inline]] to manage sequences of functions (rules):
6
+ *
7
+ * - keep rules in defined order
8
+ * - assign the name to each rule
9
+ * - enable/disable rules
10
+ * - add/replace rules
11
+ * - allow assign rules to additional named chains (in the same)
12
+ * - cacheing lists of active rules
13
+ *
14
+ * You will not need use this class directly until write plugins. For simple
15
+ * rules control use [[MarkdownIt.disable]], [[MarkdownIt.enable]] and
16
+ * [[MarkdownIt.use]].
17
+ **/
18
+ 'use strict';
19
+
20
+
21
+ /**
22
+ * new Ruler()
23
+ **/
24
+ function Ruler() {
25
+ // List of added rules. Each element is:
26
+ //
27
+ // {
28
+ // name: XXX,
29
+ // enabled: Boolean,
30
+ // fn: Function(),
31
+ // alt: [ name2, name3 ]
32
+ // }
33
+ //
34
+ this.__rules__ = [];
35
+
36
+ // Cached rule chains.
37
+ //
38
+ // First level - chain name, '' for default.
39
+ // Second level - diginal anchor for fast filtering by charcodes.
40
+ //
41
+ this.__cache__ = null;
42
+ }
43
+
44
+ ////////////////////////////////////////////////////////////////////////////////
45
+ // Helper methods, should not be used directly
46
+
47
+
48
+ // Find rule index by name
49
+ //
50
+ Ruler.prototype.__find__ = function (name) {
51
+ for (var i = 0; i < this.__rules__.length; i++) {
52
+ if (this.__rules__[i].name === name) {
53
+ return i;
54
+ }
55
+ }
56
+ return -1;
57
+ };
58
+
59
+
60
+ // Build rules lookup cache
61
+ //
62
+ Ruler.prototype.__compile__ = function () {
63
+ var self = this;
64
+ var chains = [ '' ];
65
+
66
+ // collect unique names
67
+ self.__rules__.forEach(function (rule) {
68
+ if (!rule.enabled) { return; }
69
+
70
+ rule.alt.forEach(function (altName) {
71
+ if (chains.indexOf(altName) < 0) {
72
+ chains.push(altName);
73
+ }
74
+ });
75
+ });
76
+
77
+ self.__cache__ = {};
78
+
79
+ chains.forEach(function (chain) {
80
+ self.__cache__[chain] = [];
81
+ self.__rules__.forEach(function (rule) {
82
+ if (!rule.enabled) { return; }
83
+
84
+ if (chain && rule.alt.indexOf(chain) < 0) { return; }
85
+
86
+ self.__cache__[chain].push(rule.fn);
87
+ });
88
+ });
89
+ };
90
+
91
+
92
+ /**
93
+ * Ruler.at(name, fn [, options])
94
+ * - name (String): rule name to replace.
95
+ * - fn (Function): new rule function.
96
+ * - options (Object): new rule options (not mandatory).
97
+ *
98
+ * Replace rule by name with new function & options. Throws error if name not
99
+ * found.
100
+ *
101
+ * ##### Options:
102
+ *
103
+ * - __alt__ - array with names of "alternate" chains.
104
+ *
105
+ * ##### Example
106
+ *
107
+ * Replace existing typographer replacement rule with new one:
108
+ *
109
+ * ```javascript
110
+ * var md = require('markdown-it')();
111
+ *
112
+ * md.core.ruler.at('replacements', function replace(state) {
113
+ * //...
114
+ * });
115
+ * ```
116
+ **/
117
+ Ruler.prototype.at = function (name, fn, options) {
118
+ var index = this.__find__(name);
119
+ var opt = options || {};
120
+
121
+ if (index === -1) { throw new Error('Parser rule not found: ' + name); }
122
+
123
+ this.__rules__[index].fn = fn;
124
+ this.__rules__[index].alt = opt.alt || [];
125
+ this.__cache__ = null;
126
+ };
127
+
128
+
129
+ /**
130
+ * Ruler.before(beforeName, ruleName, fn [, options])
131
+ * - beforeName (String): new rule will be added before this one.
132
+ * - ruleName (String): name of added rule.
133
+ * - fn (Function): rule function.
134
+ * - options (Object): rule options (not mandatory).
135
+ *
136
+ * Add new rule to chain before one with given name. See also
137
+ * [[Ruler.after]], [[Ruler.push]].
138
+ *
139
+ * ##### Options:
140
+ *
141
+ * - __alt__ - array with names of "alternate" chains.
142
+ *
143
+ * ##### Example
144
+ *
145
+ * ```javascript
146
+ * var md = require('markdown-it')();
147
+ *
148
+ * md.block.ruler.before('paragraph', 'my_rule', function replace(state) {
149
+ * //...
150
+ * });
151
+ * ```
152
+ **/
153
+ Ruler.prototype.before = function (beforeName, ruleName, fn, options) {
154
+ var index = this.__find__(beforeName);
155
+ var opt = options || {};
156
+
157
+ if (index === -1) { throw new Error('Parser rule not found: ' + beforeName); }
158
+
159
+ this.__rules__.splice(index, 0, {
160
+ name: ruleName,
161
+ enabled: true,
162
+ fn: fn,
163
+ alt: opt.alt || []
164
+ });
165
+
166
+ this.__cache__ = null;
167
+ };
168
+
169
+
170
+ /**
171
+ * Ruler.after(afterName, ruleName, fn [, options])
172
+ * - afterName (String): new rule will be added after this one.
173
+ * - ruleName (String): name of added rule.
174
+ * - fn (Function): rule function.
175
+ * - options (Object): rule options (not mandatory).
176
+ *
177
+ * Add new rule to chain after one with given name. See also
178
+ * [[Ruler.before]], [[Ruler.push]].
179
+ *
180
+ * ##### Options:
181
+ *
182
+ * - __alt__ - array with names of "alternate" chains.
183
+ *
184
+ * ##### Example
185
+ *
186
+ * ```javascript
187
+ * var md = require('markdown-it')();
188
+ *
189
+ * md.inline.ruler.after('text', 'my_rule', function replace(state) {
190
+ * //...
191
+ * });
192
+ * ```
193
+ **/
194
+ Ruler.prototype.after = function (afterName, ruleName, fn, options) {
195
+ var index = this.__find__(afterName);
196
+ var opt = options || {};
197
+
198
+ if (index === -1) { throw new Error('Parser rule not found: ' + afterName); }
199
+
200
+ this.__rules__.splice(index + 1, 0, {
201
+ name: ruleName,
202
+ enabled: true,
203
+ fn: fn,
204
+ alt: opt.alt || []
205
+ });
206
+
207
+ this.__cache__ = null;
208
+ };
209
+
210
+ /**
211
+ * Ruler.push(ruleName, fn [, options])
212
+ * - ruleName (String): name of added rule.
213
+ * - fn (Function): rule function.
214
+ * - options (Object): rule options (not mandatory).
215
+ *
216
+ * Push new rule to the end of chain. See also
217
+ * [[Ruler.before]], [[Ruler.after]].
218
+ *
219
+ * ##### Options:
220
+ *
221
+ * - __alt__ - array with names of "alternate" chains.
222
+ *
223
+ * ##### Example
224
+ *
225
+ * ```javascript
226
+ * var md = require('markdown-it')();
227
+ *
228
+ * md.core.ruler.push('my_rule', function replace(state) {
229
+ * //...
230
+ * });
231
+ * ```
232
+ **/
233
+ Ruler.prototype.push = function (ruleName, fn, options) {
234
+ var opt = options || {};
235
+
236
+ this.__rules__.push({
237
+ name: ruleName,
238
+ enabled: true,
239
+ fn: fn,
240
+ alt: opt.alt || []
241
+ });
242
+
243
+ this.__cache__ = null;
244
+ };
245
+
246
+
247
+ /**
248
+ * Ruler.enable(list [, ignoreInvalid]) -> Array
249
+ * - list (String|Array): list of rule names to enable.
250
+ * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found.
251
+ *
252
+ * Enable rules with given names. If any rule name not found - throw Error.
253
+ * Errors can be disabled by second param.
254
+ *
255
+ * Returns list of found rule names (if no exception happened).
256
+ *
257
+ * See also [[Ruler.disable]], [[Ruler.enableOnly]].
258
+ **/
259
+ Ruler.prototype.enable = function (list, ignoreInvalid) {
260
+ if (!Array.isArray(list)) { list = [ list ]; }
261
+
262
+ var result = [];
263
+
264
+ // Search by name and enable
265
+ list.forEach(function (name) {
266
+ var idx = this.__find__(name);
267
+
268
+ if (idx < 0) {
269
+ if (ignoreInvalid) { return; }
270
+ throw new Error('Rules manager: invalid rule name ' + name);
271
+ }
272
+ this.__rules__[idx].enabled = true;
273
+ result.push(name);
274
+ }, this);
275
+
276
+ this.__cache__ = null;
277
+ return result;
278
+ };
279
+
280
+
281
+ /**
282
+ * Ruler.enableOnly(list [, ignoreInvalid])
283
+ * - list (String|Array): list of rule names to enable (whitelist).
284
+ * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found.
285
+ *
286
+ * Enable rules with given names, and disable everything else. If any rule name
287
+ * not found - throw Error. Errors can be disabled by second param.
288
+ *
289
+ * See also [[Ruler.disable]], [[Ruler.enable]].
290
+ **/
291
+ Ruler.prototype.enableOnly = function (list, ignoreInvalid) {
292
+ if (!Array.isArray(list)) { list = [ list ]; }
293
+
294
+ this.__rules__.forEach(function (rule) { rule.enabled = false; });
295
+
296
+ this.enable(list, ignoreInvalid);
297
+ };
298
+
299
+
300
+ /**
301
+ * Ruler.disable(list [, ignoreInvalid]) -> Array
302
+ * - list (String|Array): list of rule names to disable.
303
+ * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found.
304
+ *
305
+ * Disable rules with given names. If any rule name not found - throw Error.
306
+ * Errors can be disabled by second param.
307
+ *
308
+ * Returns list of found rule names (if no exception happened).
309
+ *
310
+ * See also [[Ruler.enable]], [[Ruler.enableOnly]].
311
+ **/
312
+ Ruler.prototype.disable = function (list, ignoreInvalid) {
313
+ if (!Array.isArray(list)) { list = [ list ]; }
314
+
315
+ var result = [];
316
+
317
+ // Search by name and disable
318
+ list.forEach(function (name) {
319
+ var idx = this.__find__(name);
320
+
321
+ if (idx < 0) {
322
+ if (ignoreInvalid) { return; }
323
+ throw new Error('Rules manager: invalid rule name ' + name);
324
+ }
325
+ this.__rules__[idx].enabled = false;
326
+ result.push(name);
327
+ }, this);
328
+
329
+ this.__cache__ = null;
330
+ return result;
331
+ };
332
+
333
+
334
+ /**
335
+ * Ruler.getRules(chainName) -> Array
336
+ *
337
+ * Return array of active functions (rules) for given chain name. It analyzes
338
+ * rules configuration, compiles caches if not exists and returns result.
339
+ *
340
+ * Default chain name is `''` (empty string). It can't be skipped. That's
341
+ * done intentionally, to keep signature monomorphic for high speed.
342
+ **/
343
+ Ruler.prototype.getRules = function (chainName) {
344
+ if (this.__cache__ === null) {
345
+ this.__compile__();
346
+ }
347
+
348
+ // Chain can be empty, if rules disabled. But we still have to return Array.
349
+ return this.__cache__[chainName] || [];
350
+ };
351
+
352
+ module.exports = Ruler;