@tinta-lang/syntax 0.0.0-stage → 0.1.0-dev.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 (245) hide show
  1. package/LICENSE +21 -0
  2. package/THIRD_PARTY_NOTICES.txt +13651 -0
  3. package/dist/directive.d.ts +40 -0
  4. package/dist/editing.d.ts +46 -0
  5. package/dist/enrichment.d.ts +5 -0
  6. package/dist/expression.d.ts +26 -0
  7. package/dist/image-destinations.d.ts +3 -0
  8. package/dist/index.d.ts +8 -0
  9. package/dist/index.js +10118 -0
  10. package/dist/parser.d.ts +40 -0
  11. package/dist/registry.d.ts +144 -0
  12. package/dist/source.d.ts +28 -0
  13. package/package.json +280 -3
  14. package/parser-provenance.json +1419 -0
  15. package/patches/README.md +5 -0
  16. package/patches/micromark.patch +84 -0
  17. package/vendor/@noble/hashes/LICENSE +21 -0
  18. package/vendor/@noble/hashes/_md.js +209 -0
  19. package/vendor/@noble/hashes/_u64.js +77 -0
  20. package/vendor/@noble/hashes/package.json +91 -0
  21. package/vendor/@noble/hashes/sha2.js +446 -0
  22. package/vendor/@noble/hashes/utils.js +687 -0
  23. package/vendor/character-entities/index.js +2132 -0
  24. package/vendor/character-entities/license +22 -0
  25. package/vendor/character-entities/package.json +78 -0
  26. package/vendor/decode-named-character-reference/index.js +19 -0
  27. package/vendor/decode-named-character-reference/license +22 -0
  28. package/vendor/decode-named-character-reference/package.json +90 -0
  29. package/vendor/devlop/lib/default.js +9 -0
  30. package/vendor/devlop/license +22 -0
  31. package/vendor/devlop/package.json +80 -0
  32. package/vendor/longest-streak/index.js +36 -0
  33. package/vendor/longest-streak/license +22 -0
  34. package/vendor/longest-streak/package.json +73 -0
  35. package/vendor/markdown-table/index.js +393 -0
  36. package/vendor/markdown-table/license +22 -0
  37. package/vendor/markdown-table/package.json +77 -0
  38. package/vendor/mdast-util-from-markdown/index.js +2 -0
  39. package/vendor/mdast-util-from-markdown/lib/index.js +1270 -0
  40. package/vendor/mdast-util-from-markdown/license +22 -0
  41. package/vendor/mdast-util-from-markdown/package.json +98 -0
  42. package/vendor/mdast-util-gfm-strikethrough/index.js +5 -0
  43. package/vendor/mdast-util-gfm-strikethrough/lib/index.js +133 -0
  44. package/vendor/mdast-util-gfm-strikethrough/license +22 -0
  45. package/vendor/mdast-util-gfm-strikethrough/package.json +84 -0
  46. package/vendor/mdast-util-gfm-table/index.js +2 -0
  47. package/vendor/mdast-util-gfm-table/lib/index.js +300 -0
  48. package/vendor/mdast-util-gfm-table/license +22 -0
  49. package/vendor/mdast-util-gfm-table/package.json +101 -0
  50. package/vendor/mdast-util-gfm-task-list-item/index.js +4 -0
  51. package/vendor/mdast-util-gfm-task-list-item/lib/index.js +141 -0
  52. package/vendor/mdast-util-gfm-task-list-item/license +22 -0
  53. package/vendor/mdast-util-gfm-task-list-item/package.json +90 -0
  54. package/vendor/mdast-util-phrasing/index.js +1 -0
  55. package/vendor/mdast-util-phrasing/lib/index.js +45 -0
  56. package/vendor/mdast-util-phrasing/license +23 -0
  57. package/vendor/mdast-util-phrasing/package.json +78 -0
  58. package/vendor/mdast-util-to-markdown/index.js +3 -0
  59. package/vendor/mdast-util-to-markdown/lib/configure.js +98 -0
  60. package/vendor/mdast-util-to-markdown/lib/handle/blockquote.js +40 -0
  61. package/vendor/mdast-util-to-markdown/lib/handle/break.js +41 -0
  62. package/vendor/mdast-util-to-markdown/lib/handle/code.js +86 -0
  63. package/vendor/mdast-util-to-markdown/lib/handle/definition.js +83 -0
  64. package/vendor/mdast-util-to-markdown/lib/handle/emphasis.js +67 -0
  65. package/vendor/mdast-util-to-markdown/lib/handle/heading.js +84 -0
  66. package/vendor/mdast-util-to-markdown/lib/handle/html.js +27 -0
  67. package/vendor/mdast-util-to-markdown/lib/handle/image-reference.js +78 -0
  68. package/vendor/mdast-util-to-markdown/lib/handle/image.js +92 -0
  69. package/vendor/mdast-util-to-markdown/lib/handle/index.js +45 -0
  70. package/vendor/mdast-util-to-markdown/lib/handle/inline-code.js +86 -0
  71. package/vendor/mdast-util-to-markdown/lib/handle/link-reference.js +78 -0
  72. package/vendor/mdast-util-to-markdown/lib/handle/link.js +129 -0
  73. package/vendor/mdast-util-to-markdown/lib/handle/list-item.js +73 -0
  74. package/vendor/mdast-util-to-markdown/lib/handle/list.js +107 -0
  75. package/vendor/mdast-util-to-markdown/lib/handle/paragraph.js +27 -0
  76. package/vendor/mdast-util-to-markdown/lib/handle/root.js +34 -0
  77. package/vendor/mdast-util-to-markdown/lib/handle/strong.js +67 -0
  78. package/vendor/mdast-util-to-markdown/lib/handle/text.js +30 -0
  79. package/vendor/mdast-util-to-markdown/lib/handle/thematic-break.js +27 -0
  80. package/vendor/mdast-util-to-markdown/lib/index.js +213 -0
  81. package/vendor/mdast-util-to-markdown/lib/join.js +56 -0
  82. package/vendor/mdast-util-to-markdown/lib/unsafe.js +160 -0
  83. package/vendor/mdast-util-to-markdown/lib/util/association.js +33 -0
  84. package/vendor/mdast-util-to-markdown/lib/util/character.js +32 -0
  85. package/vendor/mdast-util-to-markdown/lib/util/check-bullet-ordered.js +25 -0
  86. package/vendor/mdast-util-to-markdown/lib/util/check-bullet-other.js +42 -0
  87. package/vendor/mdast-util-to-markdown/lib/util/check-bullet.js +25 -0
  88. package/vendor/mdast-util-to-markdown/lib/util/check-emphasis.js +25 -0
  89. package/vendor/mdast-util-to-markdown/lib/util/check-fence.js +25 -0
  90. package/vendor/mdast-util-to-markdown/lib/util/check-list-item-indent.js +25 -0
  91. package/vendor/mdast-util-to-markdown/lib/util/check-quote.js +25 -0
  92. package/vendor/mdast-util-to-markdown/lib/util/check-rule-repetition.js +25 -0
  93. package/vendor/mdast-util-to-markdown/lib/util/check-rule.js +25 -0
  94. package/vendor/mdast-util-to-markdown/lib/util/check-strong.js +25 -0
  95. package/vendor/mdast-util-to-markdown/lib/util/compile-pattern.js +30 -0
  96. package/vendor/mdast-util-to-markdown/lib/util/container-flow.js +93 -0
  97. package/vendor/mdast-util-to-markdown/lib/util/container-phrasing.js +704 -0
  98. package/vendor/mdast-util-to-markdown/lib/util/encode-character-reference.js +11 -0
  99. package/vendor/mdast-util-to-markdown/lib/util/encode-info.js +82 -0
  100. package/vendor/mdast-util-to-markdown/lib/util/format-code-as-indented.js +27 -0
  101. package/vendor/mdast-util-to-markdown/lib/util/format-heading-as-setext.js +39 -0
  102. package/vendor/mdast-util-to-markdown/lib/util/format-link-as-autolink.js +39 -0
  103. package/vendor/mdast-util-to-markdown/lib/util/html-kind.js +63 -0
  104. package/vendor/mdast-util-to-markdown/lib/util/indent-lines.js +40 -0
  105. package/vendor/mdast-util-to-markdown/lib/util/pattern-in-scope.js +52 -0
  106. package/vendor/mdast-util-to-markdown/lib/util/safe.js +263 -0
  107. package/vendor/mdast-util-to-markdown/lib/util/track.js +55 -0
  108. package/vendor/mdast-util-to-markdown/license +22 -0
  109. package/vendor/mdast-util-to-markdown/package.json +88 -0
  110. package/vendor/mdast-util-to-string/index.js +5 -0
  111. package/vendor/mdast-util-to-string/lib/index.js +108 -0
  112. package/vendor/mdast-util-to-string/license +22 -0
  113. package/vendor/mdast-util-to-string/package.json +78 -0
  114. package/vendor/micromark/index.js +60 -0
  115. package/vendor/micromark/lib/compile.js +1068 -0
  116. package/vendor/micromark/lib/constructs.js +85 -0
  117. package/vendor/micromark/lib/create-tokenizer.js +615 -0
  118. package/vendor/micromark/lib/initialize/content.js +79 -0
  119. package/vendor/micromark/lib/initialize/document.js +370 -0
  120. package/vendor/micromark/lib/initialize/flow.js +58 -0
  121. package/vendor/micromark/lib/initialize/text.js +216 -0
  122. package/vendor/micromark/lib/parse.js +56 -0
  123. package/vendor/micromark/lib/postprocess.js +18 -0
  124. package/vendor/micromark/lib/preprocess.js +112 -0
  125. package/vendor/micromark/license +22 -0
  126. package/vendor/micromark/package.json +87 -0
  127. package/vendor/micromark-core-commonmark/index.js +22 -0
  128. package/vendor/micromark-core-commonmark/lib/attention.js +231 -0
  129. package/vendor/micromark-core-commonmark/lib/autolink.js +233 -0
  130. package/vendor/micromark-core-commonmark/lib/blank-line.js +61 -0
  131. package/vendor/micromark-core-commonmark/lib/block-quote.js +143 -0
  132. package/vendor/micromark-core-commonmark/lib/character-escape.js +64 -0
  133. package/vendor/micromark-core-commonmark/lib/character-reference.js +149 -0
  134. package/vendor/micromark-core-commonmark/lib/code-fenced.js +422 -0
  135. package/vendor/micromark-core-commonmark/lib/code-indented.js +159 -0
  136. package/vendor/micromark-core-commonmark/lib/code-text.js +225 -0
  137. package/vendor/micromark-core-commonmark/lib/content.js +163 -0
  138. package/vendor/micromark-core-commonmark/lib/definition.js +254 -0
  139. package/vendor/micromark-core-commonmark/lib/hard-break-escape.js +60 -0
  140. package/vendor/micromark-core-commonmark/lib/heading-atx.js +191 -0
  141. package/vendor/micromark-core-commonmark/lib/html-flow.js +827 -0
  142. package/vendor/micromark-core-commonmark/lib/html-text.js +678 -0
  143. package/vendor/micromark-core-commonmark/lib/label-end.js +561 -0
  144. package/vendor/micromark-core-commonmark/lib/label-start-image.js +110 -0
  145. package/vendor/micromark-core-commonmark/lib/label-start-link.js +63 -0
  146. package/vendor/micromark-core-commonmark/lib/line-ending.js +33 -0
  147. package/vendor/micromark-core-commonmark/lib/list.js +213 -0
  148. package/vendor/micromark-core-commonmark/lib/partial-non-lazy-continuation.js +61 -0
  149. package/vendor/micromark-core-commonmark/lib/setext-underline.js +187 -0
  150. package/vendor/micromark-core-commonmark/lib/thematic-break.js +102 -0
  151. package/vendor/micromark-core-commonmark/license +22 -0
  152. package/vendor/micromark-core-commonmark/package.json +62 -0
  153. package/vendor/micromark-extension-gfm-strikethrough/index.js +3 -0
  154. package/vendor/micromark-extension-gfm-strikethrough/lib/html.js +26 -0
  155. package/vendor/micromark-extension-gfm-strikethrough/lib/syntax.js +142 -0
  156. package/vendor/micromark-extension-gfm-strikethrough/license +22 -0
  157. package/vendor/micromark-extension-gfm-strikethrough/package.json +129 -0
  158. package/vendor/micromark-extension-gfm-table/index.js +2 -0
  159. package/vendor/micromark-extension-gfm-table/lib/edit-map.js +222 -0
  160. package/vendor/micromark-extension-gfm-table/lib/html.js +135 -0
  161. package/vendor/micromark-extension-gfm-table/lib/infer.js +52 -0
  162. package/vendor/micromark-extension-gfm-table/lib/syntax.js +846 -0
  163. package/vendor/micromark-extension-gfm-table/license +22 -0
  164. package/vendor/micromark-extension-gfm-table/package.json +86 -0
  165. package/vendor/micromark-extension-gfm-task-list-item/index.js +2 -0
  166. package/vendor/micromark-extension-gfm-task-list-item/lib/html.js +29 -0
  167. package/vendor/micromark-extension-gfm-task-list-item/lib/syntax.js +158 -0
  168. package/vendor/micromark-extension-gfm-task-list-item/license +22 -0
  169. package/vendor/micromark-extension-gfm-task-list-item/package.json +131 -0
  170. package/vendor/micromark-factory-destination/index.js +206 -0
  171. package/vendor/micromark-factory-destination/license +22 -0
  172. package/vendor/micromark-factory-destination/package.json +57 -0
  173. package/vendor/micromark-factory-label/index.js +148 -0
  174. package/vendor/micromark-factory-label/license +22 -0
  175. package/vendor/micromark-factory-label/package.json +60 -0
  176. package/vendor/micromark-factory-space/index.js +116 -0
  177. package/vendor/micromark-factory-space/license +22 -0
  178. package/vendor/micromark-factory-space/package.json +46 -0
  179. package/vendor/micromark-factory-title/index.js +158 -0
  180. package/vendor/micromark-factory-title/license +22 -0
  181. package/vendor/micromark-factory-title/package.json +58 -0
  182. package/vendor/micromark-factory-whitespace/index.js +44 -0
  183. package/vendor/micromark-factory-whitespace/license +22 -0
  184. package/vendor/micromark-factory-whitespace/package.json +57 -0
  185. package/vendor/micromark-util-character/index.js +246 -0
  186. package/vendor/micromark-util-character/license +22 -0
  187. package/vendor/micromark-util-character/package.json +57 -0
  188. package/vendor/micromark-util-chunked/index.js +81 -0
  189. package/vendor/micromark-util-chunked/license +22 -0
  190. package/vendor/micromark-util-chunked/package.json +57 -0
  191. package/vendor/micromark-util-classify-character/index.js +27 -0
  192. package/vendor/micromark-util-classify-character/license +22 -0
  193. package/vendor/micromark-util-classify-character/package.json +59 -0
  194. package/vendor/micromark-util-combine-extensions/index.js +143 -0
  195. package/vendor/micromark-util-combine-extensions/license +22 -0
  196. package/vendor/micromark-util-combine-extensions/package.json +52 -0
  197. package/vendor/micromark-util-decode-numeric-character-reference/index.js +32 -0
  198. package/vendor/micromark-util-decode-numeric-character-reference/license +22 -0
  199. package/vendor/micromark-util-decode-numeric-character-reference/package.json +59 -0
  200. package/vendor/micromark-util-decode-string/index.js +45 -0
  201. package/vendor/micromark-util-decode-string/license +22 -0
  202. package/vendor/micromark-util-decode-string/package.json +63 -0
  203. package/vendor/micromark-util-edit-map/index.js +225 -0
  204. package/vendor/micromark-util-edit-map/license +22 -0
  205. package/vendor/micromark-util-edit-map/package.json +48 -0
  206. package/vendor/micromark-util-encode/index.js +33 -0
  207. package/vendor/micromark-util-encode/license +22 -0
  208. package/vendor/micromark-util-encode/package.json +47 -0
  209. package/vendor/micromark-util-html-tag-name/index.js +93 -0
  210. package/vendor/micromark-util-html-tag-name/license +22 -0
  211. package/vendor/micromark-util-html-tag-name/package.json +47 -0
  212. package/vendor/micromark-util-normalize-identifier/index.js +33 -0
  213. package/vendor/micromark-util-normalize-identifier/license +22 -0
  214. package/vendor/micromark-util-normalize-identifier/package.json +58 -0
  215. package/vendor/micromark-util-resolve-all/index.js +32 -0
  216. package/vendor/micromark-util-resolve-all/license +22 -0
  217. package/vendor/micromark-util-resolve-all/package.json +48 -0
  218. package/vendor/micromark-util-sanitize-uri/index.js +107 -0
  219. package/vendor/micromark-util-sanitize-uri/license +22 -0
  220. package/vendor/micromark-util-sanitize-uri/package.json +59 -0
  221. package/vendor/micromark-util-subtokenize/index.js +228 -0
  222. package/vendor/micromark-util-subtokenize/lib/splice-buffer.js +251 -0
  223. package/vendor/micromark-util-subtokenize/license +22 -0
  224. package/vendor/micromark-util-subtokenize/package.json +60 -0
  225. package/vendor/unist-util-is/index.js +7 -0
  226. package/vendor/unist-util-is/lib/index.js +296 -0
  227. package/vendor/unist-util-is/license +22 -0
  228. package/vendor/unist-util-is/package.json +103 -0
  229. package/vendor/unist-util-stringify-position/index.js +1 -0
  230. package/vendor/unist-util-stringify-position/lib/index.js +84 -0
  231. package/vendor/unist-util-stringify-position/license +22 -0
  232. package/vendor/unist-util-stringify-position/package.json +80 -0
  233. package/vendor/unist-util-visit/index.js +2 -0
  234. package/vendor/unist-util-visit/lib/index.js +312 -0
  235. package/vendor/unist-util-visit/license +22 -0
  236. package/vendor/unist-util-visit/package.json +108 -0
  237. package/vendor/unist-util-visit-parents/index.js +2 -0
  238. package/vendor/unist-util-visit-parents/lib/color.js +7 -0
  239. package/vendor/unist-util-visit-parents/lib/index.js +399 -0
  240. package/vendor/unist-util-visit-parents/license +22 -0
  241. package/vendor/unist-util-visit-parents/package.json +106 -0
  242. package/vendor/zwitch/index.js +118 -0
  243. package/vendor/zwitch/license +22 -0
  244. package/vendor/zwitch/package.json +72 -0
  245. package/README.md +0 -3
@@ -0,0 +1,216 @@
1
+ /**
2
+ * @import {
3
+ * Code,
4
+ * InitialConstruct,
5
+ * Initializer,
6
+ * Resolver,
7
+ * State,
8
+ * TokenizeContext
9
+ * } from 'micromark-util-types'
10
+ */
11
+
12
+ import { EditMap } from 'micromark-util-edit-map';
13
+ export const resolver = {
14
+ resolveAll: createResolver()
15
+ };
16
+ export const string = initializeFactory('string');
17
+ export const text = initializeFactory('text');
18
+
19
+ /**
20
+ * @param {'string' | 'text'} field
21
+ * Field.
22
+ * @returns {InitialConstruct}
23
+ * Construct.
24
+ */
25
+ function initializeFactory(field) {
26
+ return {
27
+ resolveAll: createResolver(field === 'text' ? resolveAllLineSuffixes : undefined),
28
+ tokenize: initializeText
29
+ };
30
+
31
+ /**
32
+ * @this {TokenizeContext}
33
+ * Context.
34
+ * @type {Initializer}
35
+ */
36
+ function initializeText(effects) {
37
+ const self = this;
38
+ const constructs = this.parser.constructs[field];
39
+ const text = effects.attempt(constructs, start, notText);
40
+ return start;
41
+
42
+ /** @type {State} */
43
+ function start(code) {
44
+ return atBreak(code) ? text(code) : notText(code);
45
+ }
46
+
47
+ /** @type {State} */
48
+ function notText(code) {
49
+ if (code === null) {
50
+ effects.consume(code);
51
+ return;
52
+ }
53
+ effects.enter("data");
54
+ effects.consume(code);
55
+ return data;
56
+ }
57
+
58
+ /** @type {State} */
59
+ function data(code) {
60
+ if (atBreak(code)) {
61
+ effects.exit("data");
62
+ return text(code);
63
+ }
64
+
65
+ // Data.
66
+ effects.consume(code);
67
+ return data;
68
+ }
69
+
70
+ /**
71
+ * @param {Code} code
72
+ * Code.
73
+ * @returns {boolean}
74
+ * Whether the code is a break.
75
+ */
76
+ function atBreak(code) {
77
+ if (code === null) {
78
+ return true;
79
+ }
80
+ const list = constructs[code];
81
+ let index = -1;
82
+ if (list) {
83
+ // Always populated by defaults.
84
+
85
+ while (++index < list.length) {
86
+ const item = list[index];
87
+ if (!item.previous || item.previous.call(self, self.previous)) {
88
+ return true;
89
+ }
90
+ }
91
+ }
92
+ return false;
93
+ }
94
+ }
95
+ }
96
+
97
+ /**
98
+ * @param {Resolver | undefined} [extraResolver]
99
+ * Resolver.
100
+ * @returns {Resolver}
101
+ * Resolver.
102
+ */
103
+ function createResolver(extraResolver) {
104
+ return resolveAllText;
105
+
106
+ /** @type {Resolver} */
107
+ function resolveAllText(events, context) {
108
+ let index = -1;
109
+ /** @type {number | undefined} */
110
+ let enter;
111
+
112
+ // A rather boring computation (to merge adjacent `data` events) which
113
+ // improves mm performance by 29%.
114
+ while (++index <= events.length) {
115
+ if (enter === undefined) {
116
+ if (events[index] && events[index][1].type === "data") {
117
+ enter = index;
118
+ index++;
119
+ }
120
+ } else if (!events[index] || events[index][1].type !== "data") {
121
+ // Don’t do anything if there is one data token.
122
+ if (index !== enter + 2) {
123
+ events[enter][1].end = events[index - 1][1].end;
124
+ events.splice(enter + 2, index - enter - 2);
125
+ index = enter + 2;
126
+ }
127
+ enter = undefined;
128
+ }
129
+ }
130
+ return extraResolver ? extraResolver(events, context) : events;
131
+ }
132
+ }
133
+
134
+ /**
135
+ * A rather ugly set of instructions which again looks at chunks in the input
136
+ * stream.
137
+ * The reason to do this here is that it is *much* faster to parse in reverse.
138
+ * And that we can’t hook into `null` to split the line suffix before an EOF.
139
+ * To do: figure out if we can make this into a clean utility, or even in core.
140
+ * As it will be useful for GFMs literal autolink extension (and maybe even
141
+ * tables?)
142
+ *
143
+ * @type {Resolver}
144
+ */
145
+ function resolveAllLineSuffixes(events, context) {
146
+ const editMap = new EditMap();
147
+ let eventIndex = 0; // Skip first.
148
+
149
+ while (++eventIndex <= events.length) {
150
+ if ((eventIndex === events.length || events[eventIndex][1].type === "lineEnding") && events[eventIndex - 1][1].type === "data") {
151
+ const data = events[eventIndex - 1][1];
152
+ const chunks = context.sliceStream(data);
153
+ let index = chunks.length;
154
+ let bufferIndex = -1;
155
+ let size = 0;
156
+ /** @type {boolean | undefined} */
157
+ let tabs;
158
+ while (index--) {
159
+ const chunk = chunks[index];
160
+ if (typeof chunk === 'string') {
161
+ bufferIndex = chunk.length;
162
+ while (chunk.charCodeAt(bufferIndex - 1) === 32) {
163
+ size++;
164
+ bufferIndex--;
165
+ }
166
+ if (bufferIndex) {
167
+ break;
168
+ }
169
+ bufferIndex = -1;
170
+ }
171
+ // Number
172
+ else if (chunk === -2) {
173
+ tabs = true;
174
+ size++;
175
+ } else if (chunk === -1) {
176
+ // Empty
177
+ } else {
178
+ // Replacement character, exit.
179
+ index++;
180
+ break;
181
+ }
182
+ }
183
+
184
+ // Allow final trailing whitespace.
185
+ if (context._contentTypeTextTrailing && eventIndex === events.length) {
186
+ size = 0;
187
+ }
188
+ if (size) {
189
+ const token = {
190
+ type: eventIndex === events.length || tabs || size < 2 ? "lineSuffix" : "hardBreakTrailing",
191
+ start: {
192
+ _bufferIndex: index ? bufferIndex : data.start._bufferIndex + bufferIndex,
193
+ _index: data.start._index + index,
194
+ line: data.end.line,
195
+ column: data.end.column - size,
196
+ offset: data.end.offset - size
197
+ },
198
+ end: {
199
+ ...data.end
200
+ }
201
+ };
202
+ data.end = {
203
+ ...token.start
204
+ };
205
+ if (data.start.offset === data.end.offset) {
206
+ Object.assign(data, token);
207
+ } else {
208
+ editMap.add(eventIndex, 0, [['enter', token, context], ['exit', token, context]]);
209
+ }
210
+ }
211
+ eventIndex++;
212
+ }
213
+ }
214
+ editMap.consume(events);
215
+ return events;
216
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @import {
3
+ * Create,
4
+ * FullNormalizedExtension,
5
+ * InitialConstruct,
6
+ * ParseContext,
7
+ * ParseOptions
8
+ * } from 'micromark-util-types'
9
+ */
10
+
11
+ import { combineExtensions } from 'micromark-util-combine-extensions';
12
+ import { content } from './initialize/content.js';
13
+ import { document } from './initialize/document.js';
14
+ import { flow } from './initialize/flow.js';
15
+ import { string, text } from './initialize/text.js';
16
+ import * as defaultConstructs from './constructs.js';
17
+ import { createTokenizer } from './create-tokenizer.js';
18
+
19
+ /**
20
+ * @param {ParseOptions | null | undefined} [options]
21
+ * Configuration (optional).
22
+ * @returns {ParseContext}
23
+ * Parser.
24
+ */
25
+ export function parse(options) {
26
+ const settings = options || {};
27
+ const constructs = /** @type {FullNormalizedExtension} */
28
+ combineExtensions([defaultConstructs, ...(settings.extensions || [])]);
29
+
30
+ /** @type {ParseContext} */
31
+ const parser = {
32
+ constructs,
33
+ content: create(content),
34
+ defined: [],
35
+ document: create(document),
36
+ flow: create(flow),
37
+ lazy: {},
38
+ string: create(string),
39
+ text: create(text)
40
+ };
41
+ return parser;
42
+
43
+ /**
44
+ * @param {InitialConstruct} initial
45
+ * Construct to start with.
46
+ * @returns {Create}
47
+ * Create a tokenizer.
48
+ */
49
+ function create(initial) {
50
+ return creator;
51
+ /** @type {Create} */
52
+ function creator(from) {
53
+ return createTokenizer(parser, initial, from, settings.observeTokenizer);
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @import {Event} from 'micromark-util-types'
3
+ */
4
+
5
+ import { subtokenize } from 'micromark-util-subtokenize';
6
+
7
+ /**
8
+ * @param {Array<Event>} events
9
+ * Events.
10
+ * @returns {Array<Event>}
11
+ * Events.
12
+ */
13
+ export function postprocess(events) {
14
+ while (!subtokenize(events)) {
15
+ // Empty
16
+ }
17
+ return events;
18
+ }
@@ -0,0 +1,112 @@
1
+ /**
2
+ * @import {Chunk, Code, Encoding, Value} from 'micromark-util-types'
3
+ */
4
+
5
+ /**
6
+ * @callback Preprocessor
7
+ * Preprocess a value.
8
+ * @param {Value} value
9
+ * Value.
10
+ * @param {Encoding | null | undefined} [encoding]
11
+ * Encoding when `value` is a typed array (optional).
12
+ * @param {boolean | null | undefined} [end=false]
13
+ * Whether this is the last chunk (default: `false`).
14
+ * @returns {Array<Chunk>}
15
+ * Chunks.
16
+ */
17
+
18
+ const search = /[\0\t\n\r]/g;
19
+
20
+ /**
21
+ * @returns {Preprocessor}
22
+ * Preprocess a value.
23
+ */
24
+ export function preprocess() {
25
+ let column = 1;
26
+ let buffer = '';
27
+ /** @type {boolean | undefined} */
28
+ let start = true;
29
+ /** @type {boolean | undefined} */
30
+ let atCarriageReturn;
31
+ return preprocessor;
32
+
33
+ /** @type {Preprocessor} */
34
+ // eslint-disable-next-line complexity
35
+ function preprocessor(value, encoding, end) {
36
+ value = buffer + (typeof value === 'string' ? value.toString() : new TextDecoder(encoding || undefined).decode(value));
37
+
38
+ /** @type {Array<Chunk>} */
39
+ const chunks = [];
40
+ let startPosition = 0;
41
+ buffer = '';
42
+ if (start) {
43
+ // To do: `markdown-rs` actually parses BOMs (byte order mark).
44
+ if (value.charCodeAt(0) === 65279) {
45
+ startPosition++;
46
+ }
47
+ start = undefined;
48
+ }
49
+ while (startPosition < value.length) {
50
+ search.lastIndex = startPosition;
51
+ const match = search.exec(value);
52
+ const endPosition = match && match.index !== undefined ? match.index : value.length;
53
+ const code = value.charCodeAt(endPosition);
54
+ if (!match) {
55
+ buffer = value.slice(startPosition);
56
+ break;
57
+ }
58
+ if (code === 10 && startPosition === endPosition && atCarriageReturn) {
59
+ chunks.push(-3);
60
+ atCarriageReturn = undefined;
61
+ } else {
62
+ if (atCarriageReturn) {
63
+ chunks.push(-5);
64
+ atCarriageReturn = undefined;
65
+ }
66
+ if (startPosition < endPosition) {
67
+ chunks.push(value.slice(startPosition, endPosition));
68
+ column += endPosition - startPosition;
69
+ }
70
+ switch (code) {
71
+ case 0:
72
+ {
73
+ chunks.push(65533);
74
+ column++;
75
+ break;
76
+ }
77
+ case 9:
78
+ {
79
+ const next = Math.ceil(column / 4) * 4;
80
+ chunks.push(-2);
81
+ while (column++ < next) {
82
+ chunks.push(-1);
83
+ }
84
+ break;
85
+ }
86
+ case 10:
87
+ {
88
+ chunks.push(-4);
89
+ column = 1;
90
+ break;
91
+ }
92
+ default:
93
+ {
94
+ atCarriageReturn = true;
95
+ column = 1;
96
+ }
97
+ }
98
+ }
99
+ startPosition = endPosition + 1;
100
+ }
101
+ if (end) {
102
+ if (atCarriageReturn) {
103
+ chunks.push(-5);
104
+ }
105
+ if (buffer) {
106
+ chunks.push(buffer);
107
+ }
108
+ chunks.push(null);
109
+ }
110
+ return chunks;
111
+ }
112
+ }
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) Titus Wormer <tituswormer@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,87 @@
1
+ {
2
+ "name": "micromark",
3
+ "version": "4.0.3",
4
+ "description": "small commonmark compliant markdown parser with positional info and concrete tokens",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "commonmark",
8
+ "compiler",
9
+ "gfm",
10
+ "html",
11
+ "lexer",
12
+ "markdown",
13
+ "markup",
14
+ "md",
15
+ "unified",
16
+ "parse",
17
+ "parser",
18
+ "plugin",
19
+ "process",
20
+ "remark",
21
+ "render",
22
+ "renderer",
23
+ "token",
24
+ "tokenizer"
25
+ ],
26
+ "repository": "https://github.com/micromark/micromark/tree/main/packages/micromark",
27
+ "bugs": "https://github.com/micromark/micromark/issues",
28
+ "funding": [
29
+ {
30
+ "type": "GitHub Sponsors",
31
+ "url": "https://github.com/sponsors/unifiedjs"
32
+ },
33
+ {
34
+ "type": "OpenCollective",
35
+ "url": "https://opencollective.com/unified"
36
+ }
37
+ ],
38
+ "author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
39
+ "contributors": [
40
+ "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
41
+ ],
42
+ "sideEffects": false,
43
+ "type": "module",
44
+ "files": [
45
+ "dev/",
46
+ "lib/",
47
+ "index.d.ts.map",
48
+ "index.d.ts",
49
+ "index.js",
50
+ "stream.d.ts.map",
51
+ "stream.d.ts",
52
+ "stream.js"
53
+ ],
54
+ "exports": {
55
+ ".": {
56
+ "development": "./dev/index.js",
57
+ "default": "./index.js"
58
+ },
59
+ "./stream": {
60
+ "development": "./dev/stream.js",
61
+ "default": "./stream.js"
62
+ }
63
+ },
64
+ "dependencies": {
65
+ "@types/debug": "^4.0.0",
66
+ "debug": "^4.0.0",
67
+ "decode-named-character-reference": "^1.0.0",
68
+ "devlop": "^1.0.0",
69
+ "micromark-core-commonmark": "^2.0.0",
70
+ "micromark-factory-space": "^2.0.0",
71
+ "micromark-util-character": "^2.0.0",
72
+ "micromark-util-chunked": "^2.0.0",
73
+ "micromark-util-combine-extensions": "^2.0.0",
74
+ "micromark-util-decode-numeric-character-reference": "^2.0.0",
75
+ "micromark-util-edit-map": "^1.0.0",
76
+ "micromark-util-encode": "^2.0.0",
77
+ "micromark-util-normalize-identifier": "^2.0.0",
78
+ "micromark-util-resolve-all": "^2.0.0",
79
+ "micromark-util-sanitize-uri": "^2.0.0",
80
+ "micromark-util-subtokenize": "^2.0.0",
81
+ "micromark-util-symbol": "^2.0.0",
82
+ "micromark-util-types": "^2.0.0"
83
+ },
84
+ "scripts": {
85
+ "build": "micromark-build"
86
+ }
87
+ }
@@ -0,0 +1,22 @@
1
+ export { attention } from './lib/attention.js';
2
+ export { autolink } from './lib/autolink.js';
3
+ export { blankLine } from './lib/blank-line.js';
4
+ export { blockQuote } from './lib/block-quote.js';
5
+ export { characterEscape } from './lib/character-escape.js';
6
+ export { characterReference } from './lib/character-reference.js';
7
+ export { codeFenced } from './lib/code-fenced.js';
8
+ export { codeIndented } from './lib/code-indented.js';
9
+ export { codeText } from './lib/code-text.js';
10
+ export { content } from './lib/content.js';
11
+ export { definition } from './lib/definition.js';
12
+ export { hardBreakEscape } from './lib/hard-break-escape.js';
13
+ export { headingAtx } from './lib/heading-atx.js';
14
+ export { htmlFlow } from './lib/html-flow.js';
15
+ export { htmlText } from './lib/html-text.js';
16
+ export { labelEnd } from './lib/label-end.js';
17
+ export { labelStartImage } from './lib/label-start-image.js';
18
+ export { labelStartLink } from './lib/label-start-link.js';
19
+ export { lineEnding } from './lib/line-ending.js';
20
+ export { list } from './lib/list.js';
21
+ export { setextUnderline } from './lib/setext-underline.js';
22
+ export { thematicBreak } from './lib/thematic-break.js';