@tinta-lang/syntax 0.0.0-stage → 0.1.16

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 (245) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +16 -2
  3. package/THIRD_PARTY_NOTICES.txt +13651 -0
  4. package/dist/directive.d.ts +40 -0
  5. package/dist/editing.d.ts +46 -0
  6. package/dist/enrichment.d.ts +5 -0
  7. package/dist/expression.d.ts +26 -0
  8. package/dist/image-destinations.d.ts +3 -0
  9. package/dist/index.d.ts +8 -0
  10. package/dist/index.js +10118 -0
  11. package/dist/parser.d.ts +40 -0
  12. package/dist/registry.d.ts +144 -0
  13. package/dist/source.d.ts +28 -0
  14. package/package.json +289 -3
  15. package/parser-provenance.json +1419 -0
  16. package/patches/README.md +5 -0
  17. package/patches/micromark.patch +84 -0
  18. package/vendor/@noble/hashes/LICENSE +21 -0
  19. package/vendor/@noble/hashes/_md.js +209 -0
  20. package/vendor/@noble/hashes/_u64.js +77 -0
  21. package/vendor/@noble/hashes/package.json +91 -0
  22. package/vendor/@noble/hashes/sha2.js +446 -0
  23. package/vendor/@noble/hashes/utils.js +687 -0
  24. package/vendor/character-entities/index.js +2132 -0
  25. package/vendor/character-entities/license +22 -0
  26. package/vendor/character-entities/package.json +78 -0
  27. package/vendor/decode-named-character-reference/index.js +19 -0
  28. package/vendor/decode-named-character-reference/license +22 -0
  29. package/vendor/decode-named-character-reference/package.json +90 -0
  30. package/vendor/devlop/lib/default.js +9 -0
  31. package/vendor/devlop/license +22 -0
  32. package/vendor/devlop/package.json +80 -0
  33. package/vendor/longest-streak/index.js +36 -0
  34. package/vendor/longest-streak/license +22 -0
  35. package/vendor/longest-streak/package.json +73 -0
  36. package/vendor/markdown-table/index.js +393 -0
  37. package/vendor/markdown-table/license +22 -0
  38. package/vendor/markdown-table/package.json +77 -0
  39. package/vendor/mdast-util-from-markdown/index.js +2 -0
  40. package/vendor/mdast-util-from-markdown/lib/index.js +1270 -0
  41. package/vendor/mdast-util-from-markdown/license +22 -0
  42. package/vendor/mdast-util-from-markdown/package.json +98 -0
  43. package/vendor/mdast-util-gfm-strikethrough/index.js +5 -0
  44. package/vendor/mdast-util-gfm-strikethrough/lib/index.js +133 -0
  45. package/vendor/mdast-util-gfm-strikethrough/license +22 -0
  46. package/vendor/mdast-util-gfm-strikethrough/package.json +84 -0
  47. package/vendor/mdast-util-gfm-table/index.js +2 -0
  48. package/vendor/mdast-util-gfm-table/lib/index.js +300 -0
  49. package/vendor/mdast-util-gfm-table/license +22 -0
  50. package/vendor/mdast-util-gfm-table/package.json +101 -0
  51. package/vendor/mdast-util-gfm-task-list-item/index.js +4 -0
  52. package/vendor/mdast-util-gfm-task-list-item/lib/index.js +141 -0
  53. package/vendor/mdast-util-gfm-task-list-item/license +22 -0
  54. package/vendor/mdast-util-gfm-task-list-item/package.json +90 -0
  55. package/vendor/mdast-util-phrasing/index.js +1 -0
  56. package/vendor/mdast-util-phrasing/lib/index.js +45 -0
  57. package/vendor/mdast-util-phrasing/license +23 -0
  58. package/vendor/mdast-util-phrasing/package.json +78 -0
  59. package/vendor/mdast-util-to-markdown/index.js +3 -0
  60. package/vendor/mdast-util-to-markdown/lib/configure.js +98 -0
  61. package/vendor/mdast-util-to-markdown/lib/handle/blockquote.js +40 -0
  62. package/vendor/mdast-util-to-markdown/lib/handle/break.js +41 -0
  63. package/vendor/mdast-util-to-markdown/lib/handle/code.js +86 -0
  64. package/vendor/mdast-util-to-markdown/lib/handle/definition.js +83 -0
  65. package/vendor/mdast-util-to-markdown/lib/handle/emphasis.js +67 -0
  66. package/vendor/mdast-util-to-markdown/lib/handle/heading.js +84 -0
  67. package/vendor/mdast-util-to-markdown/lib/handle/html.js +27 -0
  68. package/vendor/mdast-util-to-markdown/lib/handle/image-reference.js +78 -0
  69. package/vendor/mdast-util-to-markdown/lib/handle/image.js +92 -0
  70. package/vendor/mdast-util-to-markdown/lib/handle/index.js +45 -0
  71. package/vendor/mdast-util-to-markdown/lib/handle/inline-code.js +86 -0
  72. package/vendor/mdast-util-to-markdown/lib/handle/link-reference.js +78 -0
  73. package/vendor/mdast-util-to-markdown/lib/handle/link.js +129 -0
  74. package/vendor/mdast-util-to-markdown/lib/handle/list-item.js +73 -0
  75. package/vendor/mdast-util-to-markdown/lib/handle/list.js +107 -0
  76. package/vendor/mdast-util-to-markdown/lib/handle/paragraph.js +27 -0
  77. package/vendor/mdast-util-to-markdown/lib/handle/root.js +34 -0
  78. package/vendor/mdast-util-to-markdown/lib/handle/strong.js +67 -0
  79. package/vendor/mdast-util-to-markdown/lib/handle/text.js +30 -0
  80. package/vendor/mdast-util-to-markdown/lib/handle/thematic-break.js +27 -0
  81. package/vendor/mdast-util-to-markdown/lib/index.js +213 -0
  82. package/vendor/mdast-util-to-markdown/lib/join.js +56 -0
  83. package/vendor/mdast-util-to-markdown/lib/unsafe.js +160 -0
  84. package/vendor/mdast-util-to-markdown/lib/util/association.js +33 -0
  85. package/vendor/mdast-util-to-markdown/lib/util/character.js +32 -0
  86. package/vendor/mdast-util-to-markdown/lib/util/check-bullet-ordered.js +25 -0
  87. package/vendor/mdast-util-to-markdown/lib/util/check-bullet-other.js +42 -0
  88. package/vendor/mdast-util-to-markdown/lib/util/check-bullet.js +25 -0
  89. package/vendor/mdast-util-to-markdown/lib/util/check-emphasis.js +25 -0
  90. package/vendor/mdast-util-to-markdown/lib/util/check-fence.js +25 -0
  91. package/vendor/mdast-util-to-markdown/lib/util/check-list-item-indent.js +25 -0
  92. package/vendor/mdast-util-to-markdown/lib/util/check-quote.js +25 -0
  93. package/vendor/mdast-util-to-markdown/lib/util/check-rule-repetition.js +25 -0
  94. package/vendor/mdast-util-to-markdown/lib/util/check-rule.js +25 -0
  95. package/vendor/mdast-util-to-markdown/lib/util/check-strong.js +25 -0
  96. package/vendor/mdast-util-to-markdown/lib/util/compile-pattern.js +30 -0
  97. package/vendor/mdast-util-to-markdown/lib/util/container-flow.js +93 -0
  98. package/vendor/mdast-util-to-markdown/lib/util/container-phrasing.js +704 -0
  99. package/vendor/mdast-util-to-markdown/lib/util/encode-character-reference.js +11 -0
  100. package/vendor/mdast-util-to-markdown/lib/util/encode-info.js +82 -0
  101. package/vendor/mdast-util-to-markdown/lib/util/format-code-as-indented.js +27 -0
  102. package/vendor/mdast-util-to-markdown/lib/util/format-heading-as-setext.js +39 -0
  103. package/vendor/mdast-util-to-markdown/lib/util/format-link-as-autolink.js +39 -0
  104. package/vendor/mdast-util-to-markdown/lib/util/html-kind.js +63 -0
  105. package/vendor/mdast-util-to-markdown/lib/util/indent-lines.js +40 -0
  106. package/vendor/mdast-util-to-markdown/lib/util/pattern-in-scope.js +52 -0
  107. package/vendor/mdast-util-to-markdown/lib/util/safe.js +263 -0
  108. package/vendor/mdast-util-to-markdown/lib/util/track.js +55 -0
  109. package/vendor/mdast-util-to-markdown/license +22 -0
  110. package/vendor/mdast-util-to-markdown/package.json +88 -0
  111. package/vendor/mdast-util-to-string/index.js +5 -0
  112. package/vendor/mdast-util-to-string/lib/index.js +108 -0
  113. package/vendor/mdast-util-to-string/license +22 -0
  114. package/vendor/mdast-util-to-string/package.json +78 -0
  115. package/vendor/micromark/index.js +60 -0
  116. package/vendor/micromark/lib/compile.js +1068 -0
  117. package/vendor/micromark/lib/constructs.js +85 -0
  118. package/vendor/micromark/lib/create-tokenizer.js +615 -0
  119. package/vendor/micromark/lib/initialize/content.js +79 -0
  120. package/vendor/micromark/lib/initialize/document.js +370 -0
  121. package/vendor/micromark/lib/initialize/flow.js +58 -0
  122. package/vendor/micromark/lib/initialize/text.js +216 -0
  123. package/vendor/micromark/lib/parse.js +56 -0
  124. package/vendor/micromark/lib/postprocess.js +18 -0
  125. package/vendor/micromark/lib/preprocess.js +112 -0
  126. package/vendor/micromark/license +22 -0
  127. package/vendor/micromark/package.json +87 -0
  128. package/vendor/micromark-core-commonmark/index.js +22 -0
  129. package/vendor/micromark-core-commonmark/lib/attention.js +231 -0
  130. package/vendor/micromark-core-commonmark/lib/autolink.js +233 -0
  131. package/vendor/micromark-core-commonmark/lib/blank-line.js +61 -0
  132. package/vendor/micromark-core-commonmark/lib/block-quote.js +143 -0
  133. package/vendor/micromark-core-commonmark/lib/character-escape.js +64 -0
  134. package/vendor/micromark-core-commonmark/lib/character-reference.js +149 -0
  135. package/vendor/micromark-core-commonmark/lib/code-fenced.js +422 -0
  136. package/vendor/micromark-core-commonmark/lib/code-indented.js +159 -0
  137. package/vendor/micromark-core-commonmark/lib/code-text.js +225 -0
  138. package/vendor/micromark-core-commonmark/lib/content.js +163 -0
  139. package/vendor/micromark-core-commonmark/lib/definition.js +254 -0
  140. package/vendor/micromark-core-commonmark/lib/hard-break-escape.js +60 -0
  141. package/vendor/micromark-core-commonmark/lib/heading-atx.js +191 -0
  142. package/vendor/micromark-core-commonmark/lib/html-flow.js +827 -0
  143. package/vendor/micromark-core-commonmark/lib/html-text.js +678 -0
  144. package/vendor/micromark-core-commonmark/lib/label-end.js +561 -0
  145. package/vendor/micromark-core-commonmark/lib/label-start-image.js +110 -0
  146. package/vendor/micromark-core-commonmark/lib/label-start-link.js +63 -0
  147. package/vendor/micromark-core-commonmark/lib/line-ending.js +33 -0
  148. package/vendor/micromark-core-commonmark/lib/list.js +213 -0
  149. package/vendor/micromark-core-commonmark/lib/partial-non-lazy-continuation.js +61 -0
  150. package/vendor/micromark-core-commonmark/lib/setext-underline.js +187 -0
  151. package/vendor/micromark-core-commonmark/lib/thematic-break.js +102 -0
  152. package/vendor/micromark-core-commonmark/license +22 -0
  153. package/vendor/micromark-core-commonmark/package.json +62 -0
  154. package/vendor/micromark-extension-gfm-strikethrough/index.js +3 -0
  155. package/vendor/micromark-extension-gfm-strikethrough/lib/html.js +26 -0
  156. package/vendor/micromark-extension-gfm-strikethrough/lib/syntax.js +142 -0
  157. package/vendor/micromark-extension-gfm-strikethrough/license +22 -0
  158. package/vendor/micromark-extension-gfm-strikethrough/package.json +129 -0
  159. package/vendor/micromark-extension-gfm-table/index.js +2 -0
  160. package/vendor/micromark-extension-gfm-table/lib/edit-map.js +222 -0
  161. package/vendor/micromark-extension-gfm-table/lib/html.js +135 -0
  162. package/vendor/micromark-extension-gfm-table/lib/infer.js +52 -0
  163. package/vendor/micromark-extension-gfm-table/lib/syntax.js +846 -0
  164. package/vendor/micromark-extension-gfm-table/license +22 -0
  165. package/vendor/micromark-extension-gfm-table/package.json +86 -0
  166. package/vendor/micromark-extension-gfm-task-list-item/index.js +2 -0
  167. package/vendor/micromark-extension-gfm-task-list-item/lib/html.js +29 -0
  168. package/vendor/micromark-extension-gfm-task-list-item/lib/syntax.js +158 -0
  169. package/vendor/micromark-extension-gfm-task-list-item/license +22 -0
  170. package/vendor/micromark-extension-gfm-task-list-item/package.json +131 -0
  171. package/vendor/micromark-factory-destination/index.js +206 -0
  172. package/vendor/micromark-factory-destination/license +22 -0
  173. package/vendor/micromark-factory-destination/package.json +57 -0
  174. package/vendor/micromark-factory-label/index.js +148 -0
  175. package/vendor/micromark-factory-label/license +22 -0
  176. package/vendor/micromark-factory-label/package.json +60 -0
  177. package/vendor/micromark-factory-space/index.js +116 -0
  178. package/vendor/micromark-factory-space/license +22 -0
  179. package/vendor/micromark-factory-space/package.json +46 -0
  180. package/vendor/micromark-factory-title/index.js +158 -0
  181. package/vendor/micromark-factory-title/license +22 -0
  182. package/vendor/micromark-factory-title/package.json +58 -0
  183. package/vendor/micromark-factory-whitespace/index.js +44 -0
  184. package/vendor/micromark-factory-whitespace/license +22 -0
  185. package/vendor/micromark-factory-whitespace/package.json +57 -0
  186. package/vendor/micromark-util-character/index.js +246 -0
  187. package/vendor/micromark-util-character/license +22 -0
  188. package/vendor/micromark-util-character/package.json +57 -0
  189. package/vendor/micromark-util-chunked/index.js +81 -0
  190. package/vendor/micromark-util-chunked/license +22 -0
  191. package/vendor/micromark-util-chunked/package.json +57 -0
  192. package/vendor/micromark-util-classify-character/index.js +27 -0
  193. package/vendor/micromark-util-classify-character/license +22 -0
  194. package/vendor/micromark-util-classify-character/package.json +59 -0
  195. package/vendor/micromark-util-combine-extensions/index.js +143 -0
  196. package/vendor/micromark-util-combine-extensions/license +22 -0
  197. package/vendor/micromark-util-combine-extensions/package.json +52 -0
  198. package/vendor/micromark-util-decode-numeric-character-reference/index.js +32 -0
  199. package/vendor/micromark-util-decode-numeric-character-reference/license +22 -0
  200. package/vendor/micromark-util-decode-numeric-character-reference/package.json +59 -0
  201. package/vendor/micromark-util-decode-string/index.js +45 -0
  202. package/vendor/micromark-util-decode-string/license +22 -0
  203. package/vendor/micromark-util-decode-string/package.json +63 -0
  204. package/vendor/micromark-util-edit-map/index.js +225 -0
  205. package/vendor/micromark-util-edit-map/license +22 -0
  206. package/vendor/micromark-util-edit-map/package.json +48 -0
  207. package/vendor/micromark-util-encode/index.js +33 -0
  208. package/vendor/micromark-util-encode/license +22 -0
  209. package/vendor/micromark-util-encode/package.json +47 -0
  210. package/vendor/micromark-util-html-tag-name/index.js +93 -0
  211. package/vendor/micromark-util-html-tag-name/license +22 -0
  212. package/vendor/micromark-util-html-tag-name/package.json +47 -0
  213. package/vendor/micromark-util-normalize-identifier/index.js +33 -0
  214. package/vendor/micromark-util-normalize-identifier/license +22 -0
  215. package/vendor/micromark-util-normalize-identifier/package.json +58 -0
  216. package/vendor/micromark-util-resolve-all/index.js +32 -0
  217. package/vendor/micromark-util-resolve-all/license +22 -0
  218. package/vendor/micromark-util-resolve-all/package.json +48 -0
  219. package/vendor/micromark-util-sanitize-uri/index.js +107 -0
  220. package/vendor/micromark-util-sanitize-uri/license +22 -0
  221. package/vendor/micromark-util-sanitize-uri/package.json +59 -0
  222. package/vendor/micromark-util-subtokenize/index.js +228 -0
  223. package/vendor/micromark-util-subtokenize/lib/splice-buffer.js +251 -0
  224. package/vendor/micromark-util-subtokenize/license +22 -0
  225. package/vendor/micromark-util-subtokenize/package.json +60 -0
  226. package/vendor/unist-util-is/index.js +7 -0
  227. package/vendor/unist-util-is/lib/index.js +296 -0
  228. package/vendor/unist-util-is/license +22 -0
  229. package/vendor/unist-util-is/package.json +103 -0
  230. package/vendor/unist-util-stringify-position/index.js +1 -0
  231. package/vendor/unist-util-stringify-position/lib/index.js +84 -0
  232. package/vendor/unist-util-stringify-position/license +22 -0
  233. package/vendor/unist-util-stringify-position/package.json +80 -0
  234. package/vendor/unist-util-visit/index.js +2 -0
  235. package/vendor/unist-util-visit/lib/index.js +312 -0
  236. package/vendor/unist-util-visit/license +22 -0
  237. package/vendor/unist-util-visit/package.json +108 -0
  238. package/vendor/unist-util-visit-parents/index.js +2 -0
  239. package/vendor/unist-util-visit-parents/lib/color.js +7 -0
  240. package/vendor/unist-util-visit-parents/lib/index.js +399 -0
  241. package/vendor/unist-util-visit-parents/license +22 -0
  242. package/vendor/unist-util-visit-parents/package.json +106 -0
  243. package/vendor/zwitch/index.js +118 -0
  244. package/vendor/zwitch/license +22 -0
  245. package/vendor/zwitch/package.json +72 -0
@@ -0,0 +1,827 @@
1
+ /**
2
+ * @import {
3
+ * Code,
4
+ * Construct,
5
+ * Resolver,
6
+ * State,
7
+ * TokenizeContext,
8
+ * Tokenizer
9
+ * } from 'micromark-util-types'
10
+ */
11
+
12
+ import { asciiAlphanumeric, asciiAlpha, markdownLineEndingOrSpace, markdownLineEnding, markdownSpace } from 'micromark-util-character';
13
+ import { htmlBlockNames, htmlRawNames } from 'micromark-util-html-tag-name';
14
+ import { blankLine } from './blank-line.js';
15
+ import { nonLazyContinuation } from './partial-non-lazy-continuation.js';
16
+
17
+ /** @type {Construct} */
18
+ export const htmlFlow = {
19
+ concrete: true,
20
+ name: 'htmlFlow',
21
+ resolveTo: resolveToHtmlFlow,
22
+ tokenize: tokenizeHtmlFlow
23
+ };
24
+
25
+ /** @type {Construct} */
26
+ const blankLineBefore = {
27
+ partial: true,
28
+ tokenize: tokenizeBlankLineBefore
29
+ };
30
+
31
+ /** @type {Resolver} */
32
+ function resolveToHtmlFlow(events) {
33
+ let index = events.length;
34
+ while (index--) {
35
+ if (events[index][0] === 'enter' && events[index][1].type === "htmlFlow") {
36
+ break;
37
+ }
38
+ }
39
+ if (index > 1 && events[index - 2][1].type === "linePrefix") {
40
+ // Add the prefix start to the HTML token.
41
+ events[index][1].start = events[index - 2][1].start;
42
+ // Add the prefix start to the HTML line token.
43
+ events[index + 1][1].start = events[index - 2][1].start;
44
+ // Remove the line prefix.
45
+ events.splice(index - 2, 2);
46
+ }
47
+ return events;
48
+ }
49
+
50
+ /**
51
+ * @this {TokenizeContext}
52
+ * Context.
53
+ * @type {Tokenizer}
54
+ */
55
+ function tokenizeHtmlFlow(effects, ok, nok) {
56
+ const self = this;
57
+ /** @type {number} */
58
+ let marker;
59
+ /** @type {boolean} */
60
+ let closingTag;
61
+ /** @type {string} */
62
+ let buffer;
63
+ /** @type {number} */
64
+ let index;
65
+ /** @type {Code} */
66
+ let markerB;
67
+ return start;
68
+
69
+ /**
70
+ * Start of HTML (flow).
71
+ *
72
+ * ```markdown
73
+ * > | <x />
74
+ * ^
75
+ * ```
76
+ *
77
+ * @type {State}
78
+ */
79
+ function start(code) {
80
+ // To do: parse indent like `markdown-rs`.
81
+ return before(code);
82
+ }
83
+
84
+ /**
85
+ * At `<`, after optional whitespace.
86
+ *
87
+ * ```markdown
88
+ * > | <x />
89
+ * ^
90
+ * ```
91
+ *
92
+ * @type {State}
93
+ */
94
+ function before(code) {
95
+ effects.enter("htmlFlow");
96
+ effects.enter("htmlFlowData");
97
+ effects.consume(code);
98
+ return open;
99
+ }
100
+
101
+ /**
102
+ * After `<`, at tag name or other stuff.
103
+ *
104
+ * ```markdown
105
+ * > | <x />
106
+ * ^
107
+ * > | <!doctype>
108
+ * ^
109
+ * > | <!--xxx-->
110
+ * ^
111
+ * ```
112
+ *
113
+ * @type {State}
114
+ */
115
+ function open(code) {
116
+ if (code === 33) {
117
+ effects.consume(code);
118
+ return declarationOpen;
119
+ }
120
+ if (code === 47) {
121
+ effects.consume(code);
122
+ closingTag = true;
123
+ return tagCloseStart;
124
+ }
125
+ if (code === 63) {
126
+ effects.consume(code);
127
+ marker = 3;
128
+ // To do:
129
+ // tokenizer.concrete = true
130
+ // To do: use `markdown-rs` style interrupt.
131
+ // While we’re in an instruction instead of a declaration, we’re on a `?`
132
+ // right now, so we do need to search for `>`, similar to declarations.
133
+ return self.interrupt ? ok : continuationDeclarationInside;
134
+ }
135
+
136
+ // ASCII alphabetical.
137
+ if (asciiAlpha(code)) {
138
+ // Always the case.
139
+ effects.consume(code);
140
+ buffer = String.fromCharCode(code);
141
+ return tagName;
142
+ }
143
+ return nok(code);
144
+ }
145
+
146
+ /**
147
+ * After `<!`, at declaration, comment, or CDATA.
148
+ *
149
+ * ```markdown
150
+ * > | <!doctype>
151
+ * ^
152
+ * > | <!--xxx-->
153
+ * ^
154
+ * > | <![CDATA[>&<]]>
155
+ * ^
156
+ * ```
157
+ *
158
+ * @type {State}
159
+ */
160
+ function declarationOpen(code) {
161
+ if (code === 45) {
162
+ effects.consume(code);
163
+ marker = 2;
164
+ return commentOpenInside;
165
+ }
166
+ if (code === 91) {
167
+ effects.consume(code);
168
+ marker = 5;
169
+ index = 0;
170
+ return cdataOpenInside;
171
+ }
172
+
173
+ // ASCII alphabetical.
174
+ if (asciiAlpha(code)) {
175
+ effects.consume(code);
176
+ marker = 4;
177
+ // // Do not form containers.
178
+ // tokenizer.concrete = true
179
+ return self.interrupt ? ok : continuationDeclarationInside;
180
+ }
181
+ return nok(code);
182
+ }
183
+
184
+ /**
185
+ * After `<!-`, inside a comment, at another `-`.
186
+ *
187
+ * ```markdown
188
+ * > | <!--xxx-->
189
+ * ^
190
+ * ```
191
+ *
192
+ * @type {State}
193
+ */
194
+ function commentOpenInside(code) {
195
+ if (code === 45) {
196
+ effects.consume(code);
197
+ // // Do not form containers.
198
+ // tokenizer.concrete = true
199
+ return self.interrupt ? ok : continuationDeclarationInside;
200
+ }
201
+ return nok(code);
202
+ }
203
+
204
+ /**
205
+ * After `<![`, inside CDATA, expecting `CDATA[`.
206
+ *
207
+ * ```markdown
208
+ * > | <![CDATA[>&<]]>
209
+ * ^^^^^^
210
+ * ```
211
+ *
212
+ * @type {State}
213
+ */
214
+ function cdataOpenInside(code) {
215
+ const value = "CDATA[";
216
+ if (code === value.charCodeAt(index++)) {
217
+ effects.consume(code);
218
+ if (index === value.length) {
219
+ // // Do not form containers.
220
+ // tokenizer.concrete = true
221
+ return self.interrupt ? ok : continuation;
222
+ }
223
+ return cdataOpenInside;
224
+ }
225
+ return nok(code);
226
+ }
227
+
228
+ /**
229
+ * After `</`, in closing tag, at tag name.
230
+ *
231
+ * ```markdown
232
+ * > | </x>
233
+ * ^
234
+ * ```
235
+ *
236
+ * @type {State}
237
+ */
238
+ function tagCloseStart(code) {
239
+ if (asciiAlpha(code)) {
240
+ // Always the case.
241
+ effects.consume(code);
242
+ buffer = String.fromCharCode(code);
243
+ return tagName;
244
+ }
245
+ return nok(code);
246
+ }
247
+
248
+ /**
249
+ * In tag name.
250
+ *
251
+ * ```markdown
252
+ * > | <ab>
253
+ * ^^
254
+ * > | </ab>
255
+ * ^^
256
+ * ```
257
+ *
258
+ * @type {State}
259
+ */
260
+ function tagName(code) {
261
+ if (code === null || code === 47 || code === 62 || markdownLineEndingOrSpace(code)) {
262
+ const slash = code === 47;
263
+ const name = buffer.toLowerCase();
264
+ if (!slash && !closingTag && htmlRawNames.includes(name)) {
265
+ marker = 1;
266
+ // // Do not form containers.
267
+ // tokenizer.concrete = true
268
+ return self.interrupt ? ok(code) : continuation(code);
269
+ }
270
+ if (htmlBlockNames.includes(buffer.toLowerCase())) {
271
+ marker = 6;
272
+ if (slash) {
273
+ effects.consume(code);
274
+ return basicSelfClosing;
275
+ }
276
+
277
+ // // Do not form containers.
278
+ // tokenizer.concrete = true
279
+ return self.interrupt ? ok(code) : continuation(code);
280
+ }
281
+ marker = 7;
282
+ // Do not support complete HTML when interrupting.
283
+ return self.interrupt && !self.parser.lazy[self.now().line] ? nok(code) : closingTag ? completeClosingTagAfter(code) : completeAttributeNameBefore(code);
284
+ }
285
+
286
+ // ASCII alphanumerical and `-`.
287
+ if (code === 45 || asciiAlphanumeric(code)) {
288
+ effects.consume(code);
289
+ buffer += String.fromCharCode(code);
290
+ return tagName;
291
+ }
292
+ return nok(code);
293
+ }
294
+
295
+ /**
296
+ * After closing slash of a basic tag name.
297
+ *
298
+ * ```markdown
299
+ * > | <div/>
300
+ * ^
301
+ * ```
302
+ *
303
+ * @type {State}
304
+ */
305
+ function basicSelfClosing(code) {
306
+ if (code === 62) {
307
+ effects.consume(code);
308
+ // // Do not form containers.
309
+ // tokenizer.concrete = true
310
+ return self.interrupt ? ok : continuation;
311
+ }
312
+ return nok(code);
313
+ }
314
+
315
+ /**
316
+ * After closing slash of a complete tag name.
317
+ *
318
+ * ```markdown
319
+ * > | <x/>
320
+ * ^
321
+ * ```
322
+ *
323
+ * @type {State}
324
+ */
325
+ function completeClosingTagAfter(code) {
326
+ if (markdownSpace(code)) {
327
+ effects.consume(code);
328
+ return completeClosingTagAfter;
329
+ }
330
+ return completeEnd(code);
331
+ }
332
+
333
+ /**
334
+ * At an attribute name.
335
+ *
336
+ * At first, this state is used after a complete tag name, after whitespace,
337
+ * where it expects optional attributes or the end of the tag.
338
+ * It is also reused after attributes, when expecting more optional
339
+ * attributes.
340
+ *
341
+ * ```markdown
342
+ * > | <a />
343
+ * ^
344
+ * > | <a :b>
345
+ * ^
346
+ * > | <a _b>
347
+ * ^
348
+ * > | <a b>
349
+ * ^
350
+ * > | <a >
351
+ * ^
352
+ * ```
353
+ *
354
+ * @type {State}
355
+ */
356
+ function completeAttributeNameBefore(code) {
357
+ if (code === 47) {
358
+ effects.consume(code);
359
+ return completeEnd;
360
+ }
361
+
362
+ // ASCII alphanumerical and `:` and `_`.
363
+ if (code === 58 || code === 95 || asciiAlpha(code)) {
364
+ effects.consume(code);
365
+ return completeAttributeName;
366
+ }
367
+ if (markdownSpace(code)) {
368
+ effects.consume(code);
369
+ return completeAttributeNameBefore;
370
+ }
371
+ return completeEnd(code);
372
+ }
373
+
374
+ /**
375
+ * In attribute name.
376
+ *
377
+ * ```markdown
378
+ * > | <a :b>
379
+ * ^
380
+ * > | <a _b>
381
+ * ^
382
+ * > | <a b>
383
+ * ^
384
+ * ```
385
+ *
386
+ * @type {State}
387
+ */
388
+ function completeAttributeName(code) {
389
+ // ASCII alphanumerical and `-`, `.`, `:`, and `_`.
390
+ if (code === 45 || code === 46 || code === 58 || code === 95 || asciiAlphanumeric(code)) {
391
+ effects.consume(code);
392
+ return completeAttributeName;
393
+ }
394
+ return completeAttributeNameAfter(code);
395
+ }
396
+
397
+ /**
398
+ * After attribute name, at an optional initializer, the end of the tag, or
399
+ * whitespace.
400
+ *
401
+ * ```markdown
402
+ * > | <a b>
403
+ * ^
404
+ * > | <a b=c>
405
+ * ^
406
+ * ```
407
+ *
408
+ * @type {State}
409
+ */
410
+ function completeAttributeNameAfter(code) {
411
+ if (code === 61) {
412
+ effects.consume(code);
413
+ return completeAttributeValueBefore;
414
+ }
415
+ if (markdownSpace(code)) {
416
+ effects.consume(code);
417
+ return completeAttributeNameAfter;
418
+ }
419
+ return completeAttributeNameBefore(code);
420
+ }
421
+
422
+ /**
423
+ * Before unquoted, double quoted, or single quoted attribute value, allowing
424
+ * whitespace.
425
+ *
426
+ * ```markdown
427
+ * > | <a b=c>
428
+ * ^
429
+ * > | <a b="c">
430
+ * ^
431
+ * ```
432
+ *
433
+ * @type {State}
434
+ */
435
+ function completeAttributeValueBefore(code) {
436
+ if (code === null || code === 60 || code === 61 || code === 62 || code === 96) {
437
+ return nok(code);
438
+ }
439
+ if (code === 34 || code === 39) {
440
+ effects.consume(code);
441
+ markerB = code;
442
+ return completeAttributeValueQuoted;
443
+ }
444
+ if (markdownSpace(code)) {
445
+ effects.consume(code);
446
+ return completeAttributeValueBefore;
447
+ }
448
+ return completeAttributeValueUnquoted(code);
449
+ }
450
+
451
+ /**
452
+ * In double or single quoted attribute value.
453
+ *
454
+ * ```markdown
455
+ * > | <a b="c">
456
+ * ^
457
+ * > | <a b='c'>
458
+ * ^
459
+ * ```
460
+ *
461
+ * @type {State}
462
+ */
463
+ function completeAttributeValueQuoted(code) {
464
+ if (code === markerB) {
465
+ effects.consume(code);
466
+ markerB = null;
467
+ return completeAttributeValueQuotedAfter;
468
+ }
469
+ if (code === null || markdownLineEnding(code)) {
470
+ return nok(code);
471
+ }
472
+ effects.consume(code);
473
+ return completeAttributeValueQuoted;
474
+ }
475
+
476
+ /**
477
+ * In unquoted attribute value.
478
+ *
479
+ * ```markdown
480
+ * > | <a b=c>
481
+ * ^
482
+ * ```
483
+ *
484
+ * @type {State}
485
+ */
486
+ function completeAttributeValueUnquoted(code) {
487
+ if (code === null || code === 34 || code === 39 || code === 47 || code === 60 || code === 61 || code === 62 || code === 96 || markdownLineEndingOrSpace(code)) {
488
+ return completeAttributeNameAfter(code);
489
+ }
490
+ effects.consume(code);
491
+ return completeAttributeValueUnquoted;
492
+ }
493
+
494
+ /**
495
+ * After double or single quoted attribute value, before whitespace or the
496
+ * end of the tag.
497
+ *
498
+ * ```markdown
499
+ * > | <a b="c">
500
+ * ^
501
+ * ```
502
+ *
503
+ * @type {State}
504
+ */
505
+ function completeAttributeValueQuotedAfter(code) {
506
+ if (code === 47 || code === 62 || markdownSpace(code)) {
507
+ return completeAttributeNameBefore(code);
508
+ }
509
+ return nok(code);
510
+ }
511
+
512
+ /**
513
+ * In certain circumstances of a complete tag where only an `>` is allowed.
514
+ *
515
+ * ```markdown
516
+ * > | <a b="c">
517
+ * ^
518
+ * ```
519
+ *
520
+ * @type {State}
521
+ */
522
+ function completeEnd(code) {
523
+ if (code === 62) {
524
+ effects.consume(code);
525
+ return completeAfter;
526
+ }
527
+ return nok(code);
528
+ }
529
+
530
+ /**
531
+ * After `>` in a complete tag.
532
+ *
533
+ * ```markdown
534
+ * > | <x>
535
+ * ^
536
+ * ```
537
+ *
538
+ * @type {State}
539
+ */
540
+ function completeAfter(code) {
541
+ if (code === null || markdownLineEnding(code)) {
542
+ // // Do not form containers.
543
+ // tokenizer.concrete = true
544
+ return continuation(code);
545
+ }
546
+ if (markdownSpace(code)) {
547
+ effects.consume(code);
548
+ return completeAfter;
549
+ }
550
+ return nok(code);
551
+ }
552
+
553
+ /**
554
+ * In continuation of any HTML kind.
555
+ *
556
+ * ```markdown
557
+ * > | <!--xxx-->
558
+ * ^
559
+ * ```
560
+ *
561
+ * @type {State}
562
+ */
563
+ function continuation(code) {
564
+ if (code === 45 && marker === 2) {
565
+ effects.consume(code);
566
+ return continuationCommentInside;
567
+ }
568
+ if (code === 60 && marker === 1) {
569
+ effects.consume(code);
570
+ return continuationRawTagOpen;
571
+ }
572
+ if (code === 62 && marker === 4) {
573
+ effects.consume(code);
574
+ return continuationClose;
575
+ }
576
+ if (code === 63 && marker === 3) {
577
+ effects.consume(code);
578
+ return continuationDeclarationInside;
579
+ }
580
+ if (code === 93 && marker === 5) {
581
+ effects.consume(code);
582
+ return continuationCdataInside;
583
+ }
584
+ if (markdownLineEnding(code) && (marker === 6 || marker === 7)) {
585
+ effects.exit("htmlFlowData");
586
+ return effects.check(blankLineBefore, continuationAfter, continuationStart)(code);
587
+ }
588
+ if (code === null || markdownLineEnding(code)) {
589
+ effects.exit("htmlFlowData");
590
+ return continuationStart(code);
591
+ }
592
+ effects.consume(code);
593
+ return continuation;
594
+ }
595
+
596
+ /**
597
+ * In continuation, at eol.
598
+ *
599
+ * ```markdown
600
+ * > | <x>
601
+ * ^
602
+ * | asd
603
+ * ```
604
+ *
605
+ * @type {State}
606
+ */
607
+ function continuationStart(code) {
608
+ return effects.check(nonLazyContinuation, continuationStartNonLazy, continuationAfter)(code);
609
+ }
610
+
611
+ /**
612
+ * In continuation, at eol, before non-lazy content.
613
+ *
614
+ * ```markdown
615
+ * > | <x>
616
+ * ^
617
+ * | asd
618
+ * ```
619
+ *
620
+ * @type {State}
621
+ */
622
+ function continuationStartNonLazy(code) {
623
+ effects.enter("lineEnding");
624
+ effects.consume(code);
625
+ effects.exit("lineEnding");
626
+ return continuationBefore;
627
+ }
628
+
629
+ /**
630
+ * In continuation, before non-lazy content.
631
+ *
632
+ * ```markdown
633
+ * | <x>
634
+ * > | asd
635
+ * ^
636
+ * ```
637
+ *
638
+ * @type {State}
639
+ */
640
+ function continuationBefore(code) {
641
+ if (code === null || markdownLineEnding(code)) {
642
+ return continuationStart(code);
643
+ }
644
+ effects.enter("htmlFlowData");
645
+ return continuation(code);
646
+ }
647
+
648
+ /**
649
+ * In comment continuation, after one `-`, expecting another.
650
+ *
651
+ * ```markdown
652
+ * > | <!--xxx-->
653
+ * ^
654
+ * ```
655
+ *
656
+ * @type {State}
657
+ */
658
+ function continuationCommentInside(code) {
659
+ if (code === 45) {
660
+ effects.consume(code);
661
+ return continuationDeclarationInside;
662
+ }
663
+ return continuation(code);
664
+ }
665
+
666
+ /**
667
+ * In raw continuation, after `<`, at `/`.
668
+ *
669
+ * ```markdown
670
+ * > | <script>console.log(1)</script>
671
+ * ^
672
+ * ```
673
+ *
674
+ * @type {State}
675
+ */
676
+ function continuationRawTagOpen(code) {
677
+ if (code === 47) {
678
+ effects.consume(code);
679
+ buffer = '';
680
+ return continuationRawEndTag;
681
+ }
682
+ return continuation(code);
683
+ }
684
+
685
+ /**
686
+ * In raw continuation, after `</`, in a raw tag name.
687
+ *
688
+ * ```markdown
689
+ * > | <script>console.log(1)</script>
690
+ * ^^^^^^
691
+ * ```
692
+ *
693
+ * @type {State}
694
+ */
695
+ function continuationRawEndTag(code) {
696
+ if (code === 62) {
697
+ const name = buffer.toLowerCase();
698
+ if (htmlRawNames.includes(name)) {
699
+ effects.consume(code);
700
+ return continuationClose;
701
+ }
702
+ return continuation(code);
703
+ }
704
+ if (asciiAlpha(code) && buffer.length < 8) {
705
+ // Always the case.
706
+ effects.consume(code);
707
+ buffer += String.fromCharCode(code);
708
+ return continuationRawEndTag;
709
+ }
710
+ return continuation(code);
711
+ }
712
+
713
+ /**
714
+ * In cdata continuation, after `]`, expecting `]>`.
715
+ *
716
+ * ```markdown
717
+ * > | <![CDATA[>&<]]>
718
+ * ^
719
+ * ```
720
+ *
721
+ * @type {State}
722
+ */
723
+ function continuationCdataInside(code) {
724
+ if (code === 93) {
725
+ effects.consume(code);
726
+ return continuationDeclarationInside;
727
+ }
728
+ return continuation(code);
729
+ }
730
+
731
+ /**
732
+ * In declaration or instruction continuation, at `>`.
733
+ *
734
+ * ```markdown
735
+ * > | <!-->
736
+ * ^
737
+ * > | <?>
738
+ * ^
739
+ * > | <!q>
740
+ * ^
741
+ * > | <!--ab-->
742
+ * ^
743
+ * > | <![CDATA[>&<]]>
744
+ * ^
745
+ * ```
746
+ *
747
+ * @type {State}
748
+ */
749
+ function continuationDeclarationInside(code) {
750
+ if (code === 62) {
751
+ effects.consume(code);
752
+ return continuationClose;
753
+ }
754
+
755
+ // More dashes.
756
+ if (code === 45 && marker === 2) {
757
+ effects.consume(code);
758
+ return continuationDeclarationInside;
759
+ }
760
+ return continuation(code);
761
+ }
762
+
763
+ /**
764
+ * In closed continuation: everything we get until the eol/eof is part of it.
765
+ *
766
+ * ```markdown
767
+ * > | <!doctype>
768
+ * ^
769
+ * ```
770
+ *
771
+ * @type {State}
772
+ */
773
+ function continuationClose(code) {
774
+ if (code === null || markdownLineEnding(code)) {
775
+ effects.exit("htmlFlowData");
776
+ return continuationAfter(code);
777
+ }
778
+ effects.consume(code);
779
+ return continuationClose;
780
+ }
781
+
782
+ /**
783
+ * Done.
784
+ *
785
+ * ```markdown
786
+ * > | <!doctype>
787
+ * ^
788
+ * ```
789
+ *
790
+ * @type {State}
791
+ */
792
+ function continuationAfter(code) {
793
+ effects.exit("htmlFlow");
794
+ // // Feel free to interrupt.
795
+ // tokenizer.interrupt = false
796
+ // // No longer concrete.
797
+ // tokenizer.concrete = false
798
+ return ok(code);
799
+ }
800
+ }
801
+
802
+ /**
803
+ * @this {TokenizeContext}
804
+ * Context.
805
+ * @type {Tokenizer}
806
+ */
807
+ function tokenizeBlankLineBefore(effects, ok, nok) {
808
+ return start;
809
+
810
+ /**
811
+ * Before eol, expecting blank line.
812
+ *
813
+ * ```markdown
814
+ * > | <div>
815
+ * ^
816
+ * |
817
+ * ```
818
+ *
819
+ * @type {State}
820
+ */
821
+ function start(code) {
822
+ effects.enter("lineEnding");
823
+ effects.consume(code);
824
+ effects.exit("lineEnding");
825
+ return effects.attempt(blankLine, ok, nok);
826
+ }
827
+ }