@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,78 @@
1
+ /**
2
+ * @import {Info, State} from 'mdast-util-to-markdown'
3
+ * @import {LinkReference, Parents} from 'mdast'
4
+ */
5
+
6
+ linkReference.peek = linkReferencePeek
7
+
8
+ /**
9
+ * Serialize a link reference node.
10
+ *
11
+ * @param {LinkReference} node
12
+ * Node to serialize.
13
+ * @param {Parents | undefined} _
14
+ * Parent node.
15
+ * @param {State} state
16
+ * Info passed around.
17
+ * @param {Info} info
18
+ * Info on surrounding context.
19
+ * @returns {string}
20
+ * Serialized markdown.
21
+ */
22
+ export function linkReference(node, _, state, info) {
23
+ const type = node.referenceType
24
+ const exit = state.enter('linkReference')
25
+ let subexit = state.enter('label')
26
+ const tracker = state.createTracker(info)
27
+ let value = tracker.move('[')
28
+ const text = state.containerPhrasing(node, {
29
+ before: value,
30
+ after: ']',
31
+ ...tracker.current()
32
+ })
33
+ value += tracker.move(text + '][')
34
+
35
+ subexit()
36
+ // Hide that we’re in phrasing as things like attention or code cannot form
37
+ // in references.
38
+ // Character escapes and references *do* work.
39
+ // It is important to know about other constructs, such as table cells.
40
+ const stack = state.stack
41
+ state.stack = stack.filter(function (d) {
42
+ return d !== 'phrasing'
43
+ })
44
+ subexit = state.enter('reference')
45
+ // Note: for proper tracking, we should reset the output positions when we end
46
+ // up making a `shortcut` reference, because then there is no brace output.
47
+ // Practically, in that case, there is no content, so it doesn’t matter that
48
+ // we’ve tracked one too many characters.
49
+ const reference = state.safe(state.associationId(node), {
50
+ before: value,
51
+ after: ']',
52
+ ...tracker.current()
53
+ })
54
+ subexit()
55
+ state.stack = stack
56
+ exit()
57
+
58
+ if (type === 'full' || !text || text !== reference) {
59
+ value += tracker.move(reference + ']')
60
+ } else if (type === 'shortcut') {
61
+ // Remove the unwanted `[`.
62
+ value = value.slice(0, -1)
63
+ } else {
64
+ value += tracker.move(']')
65
+ }
66
+
67
+ return value
68
+ }
69
+
70
+ /**
71
+ * Peek at this node.
72
+ *
73
+ * @returns {string}
74
+ * Start of the serialized markdown.
75
+ */
76
+ function linkReferencePeek() {
77
+ return '['
78
+ }
@@ -0,0 +1,129 @@
1
+ /**
2
+ * @import {Info, State} from 'mdast-util-to-markdown'
3
+ * @import {Link, Parents} from 'mdast'
4
+ * @import {Exit} from '../types.js'
5
+ */
6
+
7
+ import {checkQuote} from '../util/check-quote.js'
8
+ import {formatLinkAsAutolink} from '../util/format-link-as-autolink.js'
9
+
10
+ link.peek = linkPeek
11
+
12
+ /**
13
+ * Serialize a link node.
14
+ *
15
+ * @param {Link} node
16
+ * Node to serialize.
17
+ * @param {Parents | undefined} _
18
+ * Parent node.
19
+ * @param {State} state
20
+ * Info passed around.
21
+ * @param {Info} info
22
+ * Info on surrounding context.
23
+ * @returns {string}
24
+ * Serialized markdown.
25
+ */
26
+ export function link(node, _, state, info) {
27
+ const quote = checkQuote(state)
28
+ const suffix = quote === '"' ? 'Quote' : 'Apostrophe'
29
+ const tracker = state.createTracker(info)
30
+
31
+ if (formatLinkAsAutolink(node, state)) {
32
+ // Hide that we’re in phrasing as things like attention or code cannot form
33
+ // in autolinks.
34
+ // Character escapes also don’t work (nor character references),
35
+ // but that is a different matter, which `safe.js` handles for `autolink`.
36
+ // It is important to know about other constructs, such as table cells.
37
+ const stack = state.stack
38
+ state.stack = stack.filter(function (d) {
39
+ return d !== 'phrasing'
40
+ })
41
+ const exit = state.enter('autolink')
42
+ let value = tracker.move('<')
43
+ value += tracker.move(
44
+ state.containerPhrasing(node, {
45
+ before: value,
46
+ after: '>',
47
+ ...tracker.current()
48
+ })
49
+ )
50
+ value += tracker.move('>')
51
+ exit()
52
+ state.stack = stack
53
+ return value
54
+ }
55
+
56
+ const exit = state.enter('link')
57
+ let subexit = state.enter('label')
58
+ let value = tracker.move('[')
59
+ value += tracker.move(
60
+ state.containerPhrasing(node, {
61
+ before: value,
62
+ after: '](',
63
+ ...tracker.current()
64
+ })
65
+ )
66
+ value += tracker.move('](')
67
+ subexit()
68
+
69
+ if (
70
+ // If there’s no url but there is a title…
71
+ (!node.url && node.title) ||
72
+ // If there are control characters or whitespace.
73
+ /[\0- \u007F]/.test(node.url)
74
+ ) {
75
+ subexit = state.enter('destinationLiteral')
76
+ value += tracker.move('<')
77
+ value += tracker.move(
78
+ state.safe(node.url, {before: value, after: '>', ...tracker.current()})
79
+ )
80
+ value += tracker.move('>')
81
+ } else {
82
+ // No whitespace, raw is prettier.
83
+ subexit = state.enter('destinationRaw')
84
+ value += tracker.move(
85
+ state.safe(node.url, {
86
+ before: value,
87
+ after: node.title ? ' ' : ')',
88
+ ...tracker.current()
89
+ })
90
+ )
91
+ }
92
+
93
+ subexit()
94
+
95
+ if (node.title) {
96
+ subexit = state.enter(`title${suffix}`)
97
+ value += tracker.move(' ' + quote)
98
+ value += tracker.move(
99
+ state.safe(node.title, {
100
+ before: value,
101
+ after: quote,
102
+ ...tracker.current()
103
+ })
104
+ )
105
+ value += tracker.move(quote)
106
+ subexit()
107
+ }
108
+
109
+ value += tracker.move(')')
110
+
111
+ exit()
112
+ return value
113
+ }
114
+
115
+ /**
116
+ * Peek at this node.
117
+ *
118
+ * @param {Link} node
119
+ * Node to peek at.
120
+ * @param {Parents | undefined} _
121
+ * Parent node.
122
+ * @param {State} state
123
+ * Info passed around.
124
+ * @returns {string}
125
+ * Start of the serialized markdown.
126
+ */
127
+ function linkPeek(node, _, state) {
128
+ return formatLinkAsAutolink(node, state) ? '<' : '['
129
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @import {Info, Map, State} from 'mdast-util-to-markdown'
3
+ * @import {ListItem, Parents} from 'mdast'
4
+ */
5
+
6
+ import {checkBullet} from '../util/check-bullet.js'
7
+ import {checkListItemIndent} from '../util/check-list-item-indent.js'
8
+
9
+ /**
10
+ * Serialize a list item node.
11
+ *
12
+ * @param {ListItem} node
13
+ * Node to serialize.
14
+ * @param {Parents | undefined} parent
15
+ * Parent node.
16
+ * @param {State} state
17
+ * Info passed around.
18
+ * @param {Info} info
19
+ * Info on surrounding context.
20
+ * @returns {string}
21
+ * Serialized markdown.
22
+ */
23
+ export function listItem(node, parent, state, info) {
24
+ const listItemIndent = checkListItemIndent(state)
25
+ let bullet = state.bulletCurrent || checkBullet(state)
26
+
27
+ // Add the marker value for ordered lists.
28
+ if (parent && parent.type === 'list' && parent.ordered) {
29
+ bullet =
30
+ (typeof parent.start === 'number' && parent.start > -1
31
+ ? parent.start
32
+ : 1) +
33
+ (state.options.incrementListMarker === false
34
+ ? 0
35
+ : parent.children.indexOf(node)) +
36
+ bullet
37
+ }
38
+
39
+ let size = bullet.length + 1
40
+
41
+ if (
42
+ listItemIndent === 'tab' ||
43
+ (listItemIndent === 'mixed' &&
44
+ ((parent && parent.type === 'list' && parent.spread) || node.spread))
45
+ ) {
46
+ size = Math.ceil(size / 4) * 4
47
+ }
48
+
49
+ const tracker = state.createTracker(info)
50
+ tracker.move(bullet + ' '.repeat(size - bullet.length))
51
+ tracker.shift(size)
52
+ const exit = state.enter('listItem')
53
+ const value = state.indentLines(
54
+ state.containerFlow(node, tracker.current()),
55
+ map
56
+ )
57
+ exit()
58
+
59
+ return value
60
+
61
+ /**
62
+ * Indent lines of the list item.
63
+ *
64
+ * @type {Map}
65
+ */
66
+ function map(line, index, blank) {
67
+ if (index) {
68
+ return (blank ? '' : ' '.repeat(size)) + line
69
+ }
70
+
71
+ return (blank ? bullet : bullet + ' '.repeat(size - bullet.length)) + line
72
+ }
73
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * @import {Info, State} from 'mdast-util-to-markdown'
3
+ * @import {List, Parents} from 'mdast'
4
+ */
5
+
6
+ import {checkBullet} from '../util/check-bullet.js'
7
+ import {checkBulletOther} from '../util/check-bullet-other.js'
8
+ import {checkBulletOrdered} from '../util/check-bullet-ordered.js'
9
+ import {checkRule} from '../util/check-rule.js'
10
+
11
+ /**
12
+ * Serialize a list node.
13
+ *
14
+ * @param {List} node
15
+ * Node to serialize.
16
+ * @param {Parents | undefined} parent
17
+ * Parent node.
18
+ * @param {State} state
19
+ * Info passed around.
20
+ * @param {Info} info
21
+ * Info on surrounding context.
22
+ * @returns {string}
23
+ * Serialized markdown.
24
+ */
25
+ export function list(node, parent, state, info) {
26
+ const exit = state.enter('list')
27
+ const bulletCurrent = state.bulletCurrent
28
+ /** @type {string} */
29
+ let bullet = node.ordered ? checkBulletOrdered(state) : checkBullet(state)
30
+ /** @type {string} */
31
+ const bulletOther = node.ordered
32
+ ? bullet === '.'
33
+ ? ')'
34
+ : '.'
35
+ : checkBulletOther(state)
36
+ let useDifferentMarker =
37
+ parent && state.bulletLastUsed ? bullet === state.bulletLastUsed : false
38
+
39
+ if (!node.ordered) {
40
+ const firstListItem = node.children ? node.children[0] : undefined
41
+
42
+ // If there’s an empty first list item directly in two list items,
43
+ // we have to use a different bullet:
44
+ //
45
+ // ```markdown
46
+ // * - *
47
+ // ```
48
+ //
49
+ // …because otherwise it would become one big thematic break.
50
+ if (
51
+ // Bullet could be used as a thematic break marker:
52
+ (bullet === '*' || bullet === '-') &&
53
+ // Empty first list item:
54
+ firstListItem &&
55
+ (!firstListItem.children || !firstListItem.children[0]) &&
56
+ // Directly in two other list items:
57
+ state.stack[state.stack.length - 1] === 'list' &&
58
+ state.stack[state.stack.length - 2] === 'listItem' &&
59
+ state.stack[state.stack.length - 3] === 'list' &&
60
+ state.stack[state.stack.length - 4] === 'listItem' &&
61
+ // That are each the first child.
62
+ state.indexStack[state.indexStack.length - 1] === 0 &&
63
+ state.indexStack[state.indexStack.length - 2] === 0 &&
64
+ state.indexStack[state.indexStack.length - 3] === 0
65
+ ) {
66
+ useDifferentMarker = true
67
+ }
68
+
69
+ // If there’s a thematic break at the start of the first list item,
70
+ // we have to use a different bullet:
71
+ //
72
+ // ```markdown
73
+ // * ---
74
+ // ```
75
+ //
76
+ // …because otherwise it would become one big thematic break.
77
+ if (checkRule(state) === bullet && firstListItem) {
78
+ let index = -1
79
+
80
+ while (++index < node.children.length) {
81
+ const item = node.children[index]
82
+
83
+ if (
84
+ item &&
85
+ item.type === 'listItem' &&
86
+ item.children &&
87
+ item.children[0] &&
88
+ item.children[0].type === 'thematicBreak'
89
+ ) {
90
+ useDifferentMarker = true
91
+ break
92
+ }
93
+ }
94
+ }
95
+ }
96
+
97
+ if (useDifferentMarker) {
98
+ bullet = bulletOther
99
+ }
100
+
101
+ state.bulletCurrent = bullet
102
+ const value = state.containerFlow(node, info)
103
+ state.bulletLastUsed = bullet
104
+ state.bulletCurrent = bulletCurrent
105
+ exit()
106
+ return value
107
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @import {Info, State} from 'mdast-util-to-markdown'
3
+ * @import {Paragraph, Parents} from 'mdast'
4
+ */
5
+
6
+ /**
7
+ * Serialize a paragraph node.
8
+ *
9
+ * @param {Paragraph} node
10
+ * Node to serialize.
11
+ * @param {Parents | undefined} _
12
+ * Parent node.
13
+ * @param {State} state
14
+ * Info passed around.
15
+ * @param {Info} info
16
+ * Info on surrounding context.
17
+ * @returns {string}
18
+ * Serialized markdown.
19
+ */
20
+ export function paragraph(node, _, state, info) {
21
+ const exit = state.enter('paragraph')
22
+ const subexit = state.enter('phrasing')
23
+ const value = state.containerPhrasing(node, info)
24
+ subexit()
25
+ exit()
26
+ return value
27
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @import {Info, State} from 'mdast-util-to-markdown'
3
+ * @import {Parents, Root} from 'mdast'
4
+ */
5
+
6
+ import {phrasing} from 'mdast-util-phrasing'
7
+
8
+ /**
9
+ * Serialize a root node.
10
+ *
11
+ * @param {Root} node
12
+ * Node to serialize.
13
+ * @param {Parents | undefined} _
14
+ * Parent node.
15
+ * @param {State} state
16
+ * Info passed around.
17
+ * @param {Info} info
18
+ * Info on surrounding context.
19
+ * @returns {string}
20
+ * Serialized markdown.
21
+ */
22
+ export function root(node, _, state, info) {
23
+ // Note: `html` nodes are ambiguous.
24
+ const hasPhrasing = node.children.some(function (d) {
25
+ return phrasing(d)
26
+ })
27
+
28
+ if (!hasPhrasing) return state.containerFlow(node, info)
29
+
30
+ const exit = state.enter('phrasing')
31
+ const value = state.containerPhrasing(node, info)
32
+ exit()
33
+ return value
34
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @import {AttentionInfo, Info, State} from 'mdast-util-to-markdown'
3
+ * @import {Parents, Strong} from 'mdast'
4
+ */
5
+
6
+ import {checkStrong} from '../util/check-strong.js'
7
+
8
+ strong.attention = attention
9
+ strong.peek = peek
10
+
11
+ /**
12
+ * Serialize a strong node.
13
+ *
14
+ * Attention is properly handled by `containerPhrasing`.
15
+ *
16
+ * @param {Strong} node
17
+ * Node to serialize.
18
+ * @param {Parents | undefined} _
19
+ * Parent node.
20
+ * @param {State} state
21
+ * Info passed around.
22
+ * @param {Info} info
23
+ * Info on surrounding context.
24
+ * @returns {string}
25
+ * Serialized markdown.
26
+ */
27
+ export function strong(node, _, state, info) {
28
+ const exit = state.enter('phrasing')
29
+ const value = state.containerPhrasing({type: 'root', children: [node]}, info)
30
+ exit()
31
+ return value
32
+ }
33
+
34
+ /**
35
+ * Serialize a strong node as attention.
36
+ *
37
+ * @param {Strong} _
38
+ * Node to serialize.
39
+ * @param {State} state
40
+ * Info passed around.
41
+ * @returns {AttentionInfo}
42
+ * Info on how to serialize the node.
43
+ */
44
+ function attention(_, state) {
45
+ const marker = checkStrong(state)
46
+ return {
47
+ construct: 'strong',
48
+ markers: marker === '*' ? ['*', '_'] : ['_', '*'],
49
+ sizes: [2]
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Peek at this node.
55
+ *
56
+ * @param {Strong} _
57
+ * Node to serialize.
58
+ * @param {Parents | undefined} _1
59
+ * Parent node.
60
+ * @param {State} state
61
+ * Info passed around.
62
+ * @returns {string}
63
+ * Start of the serialized markdown.
64
+ */
65
+ function peek(_, _1, state) {
66
+ return state.options.strong || '*'
67
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @import {Info, State} from 'mdast-util-to-markdown'
3
+ * @import {Parents, Text} from 'mdast'
4
+ */
5
+
6
+ /**
7
+ * Serialize a text node.
8
+ *
9
+ * @param {Text} node
10
+ * Node to serialize.
11
+ * @param {Parents | undefined} parent
12
+ * Parent node.
13
+ * @param {State} state
14
+ * Info passed around.
15
+ * @param {Info} info
16
+ * Info on surrounding context.
17
+ * @returns {string}
18
+ * Serialized markdown.
19
+ */
20
+ export function text(node, parent, state, info) {
21
+ /* c8 ignore next -- parent always passed */
22
+ const siblings = parent ? parent.children : []
23
+ const index = siblings.indexOf(node)
24
+
25
+ return state.safe(node.value, {
26
+ ...info,
27
+ afterNode: siblings[index + 1],
28
+ beforeNode: siblings[index - 1]
29
+ })
30
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @import {State} from 'mdast-util-to-markdown'
3
+ * @import {Parents, ThematicBreak} from 'mdast'
4
+ */
5
+
6
+ import {checkRuleRepetition} from '../util/check-rule-repetition.js'
7
+ import {checkRule} from '../util/check-rule.js'
8
+
9
+ /**
10
+ * Serialize a thematic break node.
11
+ *
12
+ * @param {ThematicBreak} _
13
+ * Node to serialize.
14
+ * @param {Parents | undefined} _1
15
+ * Parent node.
16
+ * @param {State} state
17
+ * Info passed around.
18
+ * @returns {string}
19
+ * Serialized markdown.
20
+ */
21
+ export function thematicBreak(_, _1, state) {
22
+ const value = (
23
+ checkRule(state) + (state.options.ruleSpaces ? ' ' : '')
24
+ ).repeat(checkRuleRepetition(state))
25
+
26
+ return state.options.ruleSpaces ? value.slice(0, -1) : value
27
+ }