@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,32 @@
1
+ /**
2
+ * @import {Event, Resolver, TokenizeContext} from 'micromark-util-types'
3
+ */
4
+
5
+ /**
6
+ * Call all `resolveAll`s.
7
+ *
8
+ * @param {ReadonlyArray<{resolveAll?: Resolver | undefined}>} constructs
9
+ * List of constructs, optionally with `resolveAll`s.
10
+ * @param {Array<Event>} events
11
+ * List of events.
12
+ * @param {TokenizeContext} context
13
+ * Context used by `tokenize`.
14
+ * @returns {Array<Event>}
15
+ * Changed events.
16
+ */
17
+ export function resolveAll(constructs, events, context) {
18
+ /** @type {Array<Resolver>} */
19
+ const called = []
20
+ let index = -1
21
+
22
+ while (++index < constructs.length) {
23
+ const resolve = constructs[index].resolveAll
24
+
25
+ if (resolve && !called.includes(resolve)) {
26
+ events = resolve(events, context)
27
+ called.push(resolve)
28
+ }
29
+ }
30
+
31
+ return events
32
+ }
@@ -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,48 @@
1
+ {
2
+ "name": "micromark-util-resolve-all",
3
+ "version": "2.0.1",
4
+ "description": "micromark utility to resolve subtokens",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "micromark",
8
+ "util",
9
+ "utility",
10
+ "resolve"
11
+ ],
12
+ "repository": "https://github.com/micromark/micromark/tree/main/packages/micromark-util-resolve-all",
13
+ "bugs": "https://github.com/micromark/micromark/issues",
14
+ "funding": [
15
+ {
16
+ "type": "GitHub Sponsors",
17
+ "url": "https://github.com/sponsors/unifiedjs"
18
+ },
19
+ {
20
+ "type": "OpenCollective",
21
+ "url": "https://opencollective.com/unified"
22
+ }
23
+ ],
24
+ "author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
25
+ "contributors": [
26
+ "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
27
+ ],
28
+ "sideEffects": false,
29
+ "type": "module",
30
+ "files": [
31
+ "index.d.ts.map",
32
+ "index.d.ts",
33
+ "index.js"
34
+ ],
35
+ "exports": "./index.js",
36
+ "dependencies": {
37
+ "micromark-util-types": "^2.0.0"
38
+ },
39
+ "xo": {
40
+ "envs": [
41
+ "shared-node-browser"
42
+ ],
43
+ "prettier": true,
44
+ "rules": {
45
+ "unicorn/prefer-code-point": "off"
46
+ }
47
+ }
48
+ }
@@ -0,0 +1,107 @@
1
+ import { asciiAlphanumeric } from 'micromark-util-character';
2
+ import { encode } from 'micromark-util-encode';
3
+ /**
4
+ * Make a value safe for injection as a URL.
5
+ *
6
+ * This encodes unsafe characters with percent-encoding and skips already
7
+ * encoded sequences (see `normalizeUri`).
8
+ * Further unsafe characters are encoded as character references (see
9
+ * `micromark-util-encode`).
10
+ *
11
+ * A regex of allowed protocols can be given, in which case the URL is
12
+ * sanitized.
13
+ * For example, `/^(https?|ircs?|mailto|xmpp)$/i` can be used for `a[href]`, or
14
+ * `/^https?$/i` for `img[src]` (this is what `github.com` allows).
15
+ * If the URL includes an unknown protocol (one not matched by `protocol`, such
16
+ * as a dangerous example, `javascript:`), the value is ignored.
17
+ *
18
+ * @param {string | null | undefined} url
19
+ * URI to sanitize.
20
+ * @param {RegExp | null | undefined} [protocol]
21
+ * Allowed protocols.
22
+ * @returns {string}
23
+ * Sanitized URI.
24
+ */
25
+ export function sanitizeUri(url, protocol) {
26
+ const value = encode(normalizeUri(url || ''));
27
+ if (!protocol) {
28
+ return value;
29
+ }
30
+ const colon = value.indexOf(':');
31
+ const questionMark = value.indexOf('?');
32
+ const numberSign = value.indexOf('#');
33
+ const slash = value.indexOf('/');
34
+ if (
35
+ // If there is no protocol, it’s relative.
36
+ colon < 0 ||
37
+ // If the first colon is after a `?`, `#`, or `/`, it’s not a protocol.
38
+ slash > -1 && colon > slash || questionMark > -1 && colon > questionMark || numberSign > -1 && colon > numberSign ||
39
+ // It is a protocol, it should be allowed.
40
+ protocol.test(value.slice(0, colon))) {
41
+ return value;
42
+ }
43
+ return '';
44
+ }
45
+
46
+ /**
47
+ * Normalize a URL.
48
+ *
49
+ * Encode unsafe characters with percent-encoding, skipping already encoded
50
+ * sequences.
51
+ *
52
+ * @param {string} value
53
+ * URI to normalize.
54
+ * @returns {string}
55
+ * Normalized URI.
56
+ */
57
+ export function normalizeUri(value) {
58
+ /** @type {Array<string>} */
59
+ const result = [];
60
+ let index = -1;
61
+ let start = 0;
62
+ let skip = 0;
63
+ while (++index < value.length) {
64
+ const code = value.charCodeAt(index);
65
+ /** @type {string} */
66
+ let replace = '';
67
+
68
+ // A correct percent encoded value.
69
+ if (code === 37 && asciiAlphanumeric(value.charCodeAt(index + 1)) && asciiAlphanumeric(value.charCodeAt(index + 2))) {
70
+ skip = 2;
71
+ }
72
+ // ASCII.
73
+ else if (code < 128) {
74
+ if (!/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(code))) {
75
+ replace = String.fromCharCode(code);
76
+ }
77
+ }
78
+ // Astral.
79
+ else if (code > 55_295 && code < 57_344) {
80
+ const next = value.charCodeAt(index + 1);
81
+
82
+ // A correct surrogate pair.
83
+ if (code < 56_320 && next > 56_319 && next < 57_344) {
84
+ replace = String.fromCharCode(code, next);
85
+ skip = 1;
86
+ }
87
+ // Lone surrogate.
88
+ else {
89
+ replace = "\uFFFD";
90
+ }
91
+ }
92
+ // Unicode.
93
+ else {
94
+ replace = String.fromCharCode(code);
95
+ }
96
+ if (replace) {
97
+ result.push(value.slice(start, index), encodeURIComponent(replace));
98
+ start = index + skip + 1;
99
+ replace = '';
100
+ }
101
+ if (skip) {
102
+ index += skip;
103
+ skip = 0;
104
+ }
105
+ }
106
+ return result.join('') + value.slice(start);
107
+ }
@@ -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,59 @@
1
+ {
2
+ "name": "micromark-util-sanitize-uri",
3
+ "version": "2.0.1",
4
+ "description": "micromark utility to sanitize urls",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "micromark",
8
+ "util",
9
+ "utility",
10
+ "sanitize",
11
+ "clear",
12
+ "url"
13
+ ],
14
+ "repository": "https://github.com/micromark/micromark/tree/main/packages/micromark-util-sanitize-uri",
15
+ "bugs": "https://github.com/micromark/micromark/issues",
16
+ "funding": [
17
+ {
18
+ "type": "GitHub Sponsors",
19
+ "url": "https://github.com/sponsors/unifiedjs"
20
+ },
21
+ {
22
+ "type": "OpenCollective",
23
+ "url": "https://opencollective.com/unified"
24
+ }
25
+ ],
26
+ "author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
27
+ "contributors": [
28
+ "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
29
+ ],
30
+ "sideEffects": false,
31
+ "type": "module",
32
+ "files": [
33
+ "dev/",
34
+ "index.d.ts.map",
35
+ "index.d.ts",
36
+ "index.js"
37
+ ],
38
+ "exports": {
39
+ "development": "./dev/index.js",
40
+ "default": "./index.js"
41
+ },
42
+ "dependencies": {
43
+ "micromark-util-character": "^2.0.0",
44
+ "micromark-util-encode": "^2.0.0",
45
+ "micromark-util-symbol": "^2.0.0"
46
+ },
47
+ "scripts": {
48
+ "build": "micromark-build"
49
+ },
50
+ "xo": {
51
+ "envs": [
52
+ "shared-node-browser"
53
+ ],
54
+ "prettier": true,
55
+ "rules": {
56
+ "unicorn/prefer-code-point": "off"
57
+ }
58
+ }
59
+ }
@@ -0,0 +1,228 @@
1
+ /**
2
+ * @import {Chunk, Event, Token} from 'micromark-util-types'
3
+ */
4
+
5
+ import { splice } from 'micromark-util-chunked';
6
+ import { SpliceBuffer } from './lib/splice-buffer.js';
7
+
8
+ // Hidden API exposed for testing.
9
+ export { SpliceBuffer } from './lib/splice-buffer.js';
10
+
11
+ /**
12
+ * Tokenize subcontent.
13
+ *
14
+ * @param {Array<Event>} eventsArray
15
+ * List of events.
16
+ * @returns {boolean}
17
+ * Whether subtokens were found.
18
+ */
19
+ // eslint-disable-next-line complexity
20
+ export function subtokenize(eventsArray) {
21
+ /** @type {Record<string, number>} */
22
+ const jumps = {};
23
+ let index = -1;
24
+ /** @type {Event} */
25
+ let event;
26
+ /** @type {number | undefined} */
27
+ let lineIndex;
28
+ /** @type {number} */
29
+ let otherIndex;
30
+ /** @type {Event} */
31
+ let otherEvent;
32
+ /** @type {Array<Event>} */
33
+ let parameters;
34
+ /** @type {Array<Event>} */
35
+ let subevents;
36
+ /** @type {boolean | undefined} */
37
+ let more;
38
+ const events = new SpliceBuffer(eventsArray);
39
+ while (++index < events.length) {
40
+ while (index in jumps) {
41
+ index = jumps[index];
42
+ }
43
+ event = events.get(index);
44
+
45
+ // Add a hook for the GFM tasklist extension, which needs to know if text
46
+ // is in the first content of a list item.
47
+ if (index && event[1].type === "chunkFlow" && events.get(index - 1)[1].type === "listItemPrefix") {
48
+ subevents = event[1]._tokenizer.events;
49
+ otherIndex = 0;
50
+ if (otherIndex < subevents.length && subevents[otherIndex][1].type === "lineEndingBlank") {
51
+ otherIndex += 2;
52
+ }
53
+ if (otherIndex < subevents.length && subevents[otherIndex][1].type === "content") {
54
+ while (++otherIndex < subevents.length) {
55
+ if (subevents[otherIndex][1].type === "content") {
56
+ break;
57
+ }
58
+ if (subevents[otherIndex][1].type === "chunkText") {
59
+ subevents[otherIndex][1]._isInFirstContentOfListItem = true;
60
+ otherIndex++;
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ // Enter.
67
+ if (event[0] === 'enter') {
68
+ if (event[1].contentType) {
69
+ Object.assign(jumps, subcontent(events, index));
70
+ index = jumps[index];
71
+ more = true;
72
+ }
73
+ }
74
+ // Exit.
75
+ else if (event[1]._container) {
76
+ otherIndex = index;
77
+ lineIndex = undefined;
78
+ while (otherIndex--) {
79
+ otherEvent = events.get(otherIndex);
80
+ if (otherEvent[1].type === "lineEnding" || otherEvent[1].type === "lineEndingBlank") {
81
+ if (otherEvent[0] === 'enter') {
82
+ if (lineIndex) {
83
+ events.get(lineIndex)[1].type = "lineEndingBlank";
84
+ }
85
+ otherEvent[1].type = "lineEnding";
86
+ lineIndex = otherIndex;
87
+ }
88
+ } else if (otherEvent[1].type === "linePrefix" || otherEvent[1].type === "listItemIndent") {
89
+ // Move past.
90
+ } else {
91
+ break;
92
+ }
93
+ }
94
+ if (lineIndex) {
95
+ // Fix position.
96
+ event[1].end = {
97
+ ...events.get(lineIndex)[1].start
98
+ };
99
+
100
+ // Switch container exit w/ line endings.
101
+ parameters = events.slice(lineIndex, index);
102
+ parameters.unshift(event);
103
+ events.splice(lineIndex, index - lineIndex + 1, parameters);
104
+ }
105
+ }
106
+ }
107
+
108
+ // The changes to the `events` buffer must be copied back into the eventsArray
109
+ splice(eventsArray, 0, Number.POSITIVE_INFINITY, events.slice(0));
110
+ return !more;
111
+ }
112
+
113
+ /**
114
+ * Tokenize embedded tokens.
115
+ *
116
+ * @param {SpliceBuffer<Event>} events
117
+ * Events.
118
+ * @param {number} eventIndex
119
+ * Index.
120
+ * @returns {Record<string, number>}
121
+ * Gaps.
122
+ */
123
+ function subcontent(events, eventIndex) {
124
+ const token = events.get(eventIndex)[1];
125
+ const context = events.get(eventIndex)[2];
126
+ let startPosition = eventIndex - 1;
127
+ /** @type {Array<number>} */
128
+ const startPositions = [];
129
+ let tokenizer = token._tokenizer;
130
+ if (!tokenizer) {
131
+ tokenizer = context.parser[token.contentType](token.start);
132
+ if (token._contentTypeTextTrailing) {
133
+ tokenizer._contentTypeTextTrailing = true;
134
+ }
135
+ }
136
+ const childEvents = tokenizer.events;
137
+ /** @type {Array<[number, number]>} */
138
+ const jumps = [];
139
+ /** @type {Record<string, number>} */
140
+ const gaps = {};
141
+ /** @type {Array<Chunk>} */
142
+ let stream;
143
+ /** @type {Token | undefined} */
144
+ let previous;
145
+ let index = -1;
146
+ /** @type {Token | undefined} */
147
+ let current = token;
148
+ let adjust = 0;
149
+ let start = 0;
150
+ const breaks = [start];
151
+
152
+ // Loop forward through the linked tokens to pass them in order to the
153
+ // subtokenizer.
154
+ while (current) {
155
+ // Find the position of the event for this token.
156
+ while (events.get(++startPosition)[1] !== current) {
157
+ // Empty.
158
+ }
159
+ startPositions.push(startPosition);
160
+ if (!current._tokenizer) {
161
+ stream = context.sliceStream(current);
162
+ if (!current.next) {
163
+ stream.push(null);
164
+ }
165
+ if (previous) {
166
+ tokenizer.defineSkip(current.start);
167
+ }
168
+ if (current._isInFirstContentOfListItem) {
169
+ tokenizer._gfmTasklistFirstContentOfListItem = true;
170
+ }
171
+ tokenizer.write(stream);
172
+ if (current._isInFirstContentOfListItem) {
173
+ tokenizer._gfmTasklistFirstContentOfListItem = undefined;
174
+ }
175
+ }
176
+
177
+ // Unravel the next token.
178
+ previous = current;
179
+ current = current.next;
180
+ }
181
+
182
+ // Now, loop back through all events (and linked tokens), to figure out which
183
+ // parts belong where.
184
+ current = token;
185
+ while (++index < childEvents.length) {
186
+ if (
187
+ // Find a void token that includes a break.
188
+ childEvents[index][0] === 'exit' && childEvents[index - 1][0] === 'enter' && childEvents[index][1].type === childEvents[index - 1][1].type && childEvents[index][1].start.line !== childEvents[index][1].end.line) {
189
+ start = index + 1;
190
+ breaks.push(start);
191
+ // Help GC.
192
+ current._tokenizer = undefined;
193
+ current.previous = undefined;
194
+ current = current.next;
195
+ }
196
+ }
197
+
198
+ // Help GC.
199
+ tokenizer.events = [];
200
+
201
+ // If there’s one more token (which is the cases for lines that end in an
202
+ // EOF), that’s perfect: the last point we found starts it.
203
+ // If there isn’t then make sure any remaining content is added to it.
204
+ if (current) {
205
+ // Help GC.
206
+ current._tokenizer = undefined;
207
+ current.previous = undefined;
208
+ } else {
209
+ breaks.pop();
210
+ }
211
+
212
+ // Now splice the events from the subtokenizer into the current events,
213
+ // moving back to front so that splice indices aren’t affected.
214
+ index = breaks.length;
215
+ while (index--) {
216
+ const slice = childEvents.slice(breaks[index], breaks[index + 1]);
217
+ const start = startPositions.pop();
218
+ jumps.push([start, start + slice.length - 1]);
219
+ events.splice(start, 2, slice);
220
+ }
221
+ jumps.reverse();
222
+ index = -1;
223
+ while (++index < jumps.length) {
224
+ gaps[adjust + jumps[index][0]] = adjust + jumps[index][1];
225
+ adjust += jumps[index][1] - jumps[index][0] - 1;
226
+ }
227
+ return gaps;
228
+ }