@mdsvex/parse 1.0.0-next.0 → 1.0.0-next.1

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 (329) hide show
  1. package/CHANGELOG.md +213 -0
  2. package/WIRE_FORMAT.md +5 -1
  3. package/dist/buf-utils.js +23 -23
  4. package/dist/buf_utils.d.ts +1 -1
  5. package/dist/cursor.d.ts +17 -13
  6. package/dist/cursor.js +118 -31
  7. package/dist/main.d.ts +362 -26
  8. package/dist/main.js +5841 -3420
  9. package/dist/node_view-bvM0i0-p.js +407 -0
  10. package/dist/node_view.d.ts +11 -12
  11. package/dist/opcodes.d.ts +23 -6
  12. package/dist/plugin_dispatch.d.ts +22 -8
  13. package/dist/tree-builder.js +185 -66
  14. package/dist/tree_builder.d.ts +42 -11
  15. package/dist/undo_log.d.ts +11 -1
  16. package/dist/utils.d.ts +77 -51
  17. package/dist/utils.js +687 -209
  18. package/dist/wire-tree-builder.js +69 -71
  19. package/dist/wire_tree_builder.d.ts +4 -7
  20. package/package.json +1 -1
  21. package/src/buf_utils.ts +10 -14
  22. package/src/cursor.ts +74 -57
  23. package/src/main.ts +9898 -5593
  24. package/src/node_view.ts +159 -140
  25. package/src/opcodes.ts +39 -7
  26. package/src/plugin_dispatch.ts +328 -219
  27. package/src/tree_builder.ts +278 -98
  28. package/src/undo_log.ts +58 -24
  29. package/src/utils.spec.ts +86 -9
  30. package/src/utils.ts +769 -392
  31. package/src/wire_emitter.ts +6 -0
  32. package/src/wire_tree_builder.ts +39 -52
  33. package/test/block_quotes.spec.ts +78 -7
  34. package/test/code_spans.spec.ts +158 -6
  35. package/test/crlf.spec.ts +49 -1
  36. package/test/directives.spec.ts +530 -1
  37. package/test/emphasis.spec.ts +10 -4
  38. package/test/fixtures/pfm/block_quotes/pfm_fence_close.md +4 -0
  39. package/test/fixtures/pfm/block_quotes/pfm_fence_close_compact.md +4 -0
  40. package/test/fixtures/pfm/block_quotes/pfm_fence_close_end_quote.md +5 -0
  41. package/test/fixtures/pfm/block_quotes/pfm_fence_close_info.md +5 -0
  42. package/test/fixtures/pfm/block_quotes/pfm_fence_close_longer.md +4 -0
  43. package/test/fixtures/pfm/block_quotes/pfm_fence_close_nested.md +3 -0
  44. package/test/fixtures/pfm/block_quotes/pfm_fence_close_twice.md +6 -0
  45. package/test/fixtures/pfm/block_quotes/pfm_fence_info_eof.md +1 -0
  46. package/test/fixtures/pfm/block_quotes/pfm_fence_unclosed.md +2 -0
  47. package/test/fixtures/pfm/code_spans/pfm_328_5.md +1 -0
  48. package/test/fixtures/pfm/code_spans/pfm_328_6.md +1 -0
  49. package/test/fixtures/pfm/code_spans/pfm_328_7.md +1 -0
  50. package/test/fixtures/pfm/code_spans/pfm_328_8.md +1 -0
  51. package/test/fixtures/pfm/code_spans/pfm_328_9.md +2 -0
  52. package/test/fixtures/pfm/fenced_code_blocks/pfm_info_eof.md +1 -0
  53. package/test/fixtures/pfm/fenced_code_blocks/pfm_info_eof_no_lf.md +1 -0
  54. package/test/fixtures/pfm/generic_directives/106.md +1 -0
  55. package/test/fixtures/pfm/generic_directives/107.md +3 -0
  56. package/test/fixtures/pfm/generic_directives/108.md +1 -0
  57. package/test/fixtures/pfm/generic_directives/109.md +1 -0
  58. package/test/fixtures/pfm/generic_directives/110.md +1 -0
  59. package/test/fixtures/pfm/generic_directives/111.md +1 -0
  60. package/test/fixtures/pfm/generic_directives/112.md +1 -0
  61. package/test/fixtures/pfm/generic_directives/113.md +1 -0
  62. package/test/fixtures/pfm/generic_directives/114.md +2 -0
  63. package/test/fixtures/pfm/generic_directives/115.md +1 -0
  64. package/test/fixtures/pfm/generic_directives/116.md +6 -0
  65. package/test/fixtures/pfm/generic_directives/117.md +3 -0
  66. package/test/fixtures/pfm/generic_directives/118.md +6 -0
  67. package/test/fixtures/pfm/generic_directives/119.md +3 -0
  68. package/test/fixtures/pfm/generic_directives/120.md +5 -0
  69. package/test/fixtures/pfm/generic_directives/121.md +3 -0
  70. package/test/fixtures/pfm/generic_directives/122.md +4 -0
  71. package/test/fixtures/pfm/generic_directives/123.md +2 -0
  72. package/test/html.spec.ts +44 -1
  73. package/test/html_block_containers.spec.ts +445 -0
  74. package/test/incremental.spec.ts +271 -0
  75. package/test/lists.spec.ts +107 -1
  76. package/test/parser_reuse.spec.ts +40 -0
  77. package/test/plugins.spec.ts +196 -226
  78. package/test/print.ts +2 -3
  79. package/test/run_bytecode.spec.ts +36 -0
  80. package/test/snapshots/hybrid/component-children.snap.ast +9 -16
  81. package/test/snapshots/hybrid/component-simple-00.snap.ast +1 -2
  82. package/test/snapshots/hybrid/component-simple-01.snap.ast +1 -2
  83. package/test/snapshots/hybrid/component-simple-03.snap.ast +13 -13
  84. package/test/snapshots/hybrid/component-simple-04.snap.ast +1 -2
  85. package/test/snapshots/hybrid/error.snap.ast +1 -2
  86. package/test/snapshots/markdown/blockquote-nested-markdown.snap.ast +2 -1
  87. package/test/snapshots/markdown/emphasis.snap.ast +2 -2
  88. package/test/snapshots/markdown/encodeHTMLCodeTags.snap.ast +1 -2
  89. package/test/snapshots/markdown/github-style-codeblock-inside-quote.snap.ast +8 -1
  90. package/test/snapshots/markdown/html-comments.snap.ast +11 -13
  91. package/test/snapshots/markdown/html5-strutural-tags.snap.ast +16 -31
  92. package/test/snapshots/markdown/line-starts-with-html.snap.ast +5 -6
  93. package/test/snapshots/markdown/literal-html-tags.snap.ast +11 -14
  94. package/test/snapshots/markdown/nested-blockquote.snap.ast +3 -3
  95. package/test/snapshots/markdown/pre-code-tags.snap.ast +5 -8
  96. package/test/snapshots/pfm/block_quotes/237.snap.ast +1 -2
  97. package/test/snapshots/pfm/block_quotes/251.snap.ast +5 -5
  98. package/test/snapshots/pfm/block_quotes/pfm_fence_close.snap.ast +6 -0
  99. package/test/snapshots/pfm/block_quotes/pfm_fence_close_compact.snap.ast +6 -0
  100. package/test/snapshots/pfm/block_quotes/pfm_fence_close_end_quote.snap.ast +8 -0
  101. package/test/snapshots/pfm/block_quotes/pfm_fence_close_info.snap.ast +4 -0
  102. package/test/snapshots/pfm/block_quotes/pfm_fence_close_longer.snap.ast +6 -0
  103. package/test/snapshots/pfm/block_quotes/pfm_fence_close_nested.snap.ast +5 -0
  104. package/test/snapshots/pfm/block_quotes/pfm_fence_close_twice.snap.ast +5 -0
  105. package/test/snapshots/pfm/block_quotes/pfm_fence_info_eof.snap.ast +3 -0
  106. package/test/snapshots/pfm/block_quotes/pfm_fence_unclosed.snap.ast +3 -0
  107. package/test/snapshots/pfm/code_spans/344.snap.ast +1 -1
  108. package/test/snapshots/pfm/code_spans/347.snap.ast +1 -2
  109. package/test/snapshots/pfm/code_spans/pfm_328_5.snap.ast +6 -0
  110. package/test/snapshots/pfm/code_spans/pfm_328_6.snap.ast +6 -0
  111. package/test/snapshots/pfm/code_spans/pfm_328_7.snap.ast +6 -0
  112. package/test/snapshots/pfm/code_spans/pfm_328_8.snap.ast +8 -0
  113. package/test/snapshots/pfm/code_spans/pfm_328_9.snap.ast +10 -0
  114. package/test/snapshots/pfm/emphasis_and_strong_emphasis/417.snap.ast +2 -2
  115. package/test/snapshots/pfm/emphasis_and_strong_emphasis/438.snap.ast +1 -1
  116. package/test/snapshots/pfm/emphasis_and_strong_emphasis/441.snap.ast +1 -1
  117. package/test/snapshots/pfm/emphasis_and_strong_emphasis/444.snap.ast +1 -1
  118. package/test/snapshots/pfm/emphasis_and_strong_emphasis/445.snap.ast +1 -1
  119. package/test/snapshots/pfm/emphasis_and_strong_emphasis/450.snap.ast +1 -1
  120. package/test/snapshots/pfm/emphasis_and_strong_emphasis/453.snap.ast +1 -1
  121. package/test/snapshots/pfm/emphasis_and_strong_emphasis/456.snap.ast +1 -1
  122. package/test/snapshots/pfm/emphasis_and_strong_emphasis/457.snap.ast +1 -1
  123. package/test/snapshots/pfm/emphasis_and_strong_emphasis/473.snap.ast +1 -1
  124. package/test/snapshots/pfm/emphasis_and_strong_emphasis/475.snap.ast +1 -1
  125. package/test/snapshots/pfm/emphasis_and_strong_emphasis/476.snap.ast +1 -1
  126. package/test/snapshots/pfm/emphasis_and_strong_emphasis/477.snap.ast +1 -1
  127. package/test/snapshots/pfm/emphasis_and_strong_emphasis/478.snap.ast +3 -4
  128. package/test/snapshots/pfm/emphasis_and_strong_emphasis/479.snap.ast +3 -4
  129. package/test/snapshots/pfm/fenced_code_blocks/126.snap.ast +1 -2
  130. package/test/snapshots/pfm/fenced_code_blocks/pfm_info_eof.snap.ast +2 -0
  131. package/test/snapshots/pfm/fenced_code_blocks/pfm_info_eof_no_lf.snap.ast +2 -0
  132. package/test/snapshots/pfm/generic_directives/011.snap.ast +3 -1
  133. package/test/snapshots/pfm/generic_directives/015.snap.ast +3 -1
  134. package/test/snapshots/pfm/generic_directives/016.snap.ast +3 -1
  135. package/test/snapshots/pfm/generic_directives/017.snap.ast +3 -1
  136. package/test/snapshots/pfm/generic_directives/019.snap.ast +3 -1
  137. package/test/snapshots/pfm/generic_directives/020.snap.ast +3 -1
  138. package/test/snapshots/pfm/generic_directives/030.snap.ast +4 -6
  139. package/test/snapshots/pfm/generic_directives/034.snap.ast +6 -2
  140. package/test/snapshots/pfm/generic_directives/036.snap.ast +5 -1
  141. package/test/snapshots/pfm/generic_directives/038.snap.ast +6 -2
  142. package/test/snapshots/pfm/generic_directives/039.snap.ast +3 -1
  143. package/test/snapshots/pfm/generic_directives/040.snap.ast +3 -1
  144. package/test/snapshots/pfm/generic_directives/044.snap.ast +3 -1
  145. package/test/snapshots/pfm/generic_directives/046.snap.ast +3 -1
  146. package/test/snapshots/pfm/generic_directives/089.snap.ast +1 -1
  147. package/test/snapshots/pfm/generic_directives/103.snap.ast +6 -2
  148. package/test/snapshots/pfm/generic_directives/106.snap.ast +9 -0
  149. package/test/snapshots/pfm/generic_directives/107.snap.ast +9 -0
  150. package/test/snapshots/pfm/generic_directives/108.snap.ast +5 -0
  151. package/test/snapshots/pfm/generic_directives/109.snap.ast +4 -0
  152. package/test/snapshots/pfm/generic_directives/110.snap.ast +10 -0
  153. package/test/snapshots/pfm/generic_directives/111.snap.ast +7 -0
  154. package/test/snapshots/pfm/generic_directives/112.snap.ast +18 -0
  155. package/test/snapshots/pfm/generic_directives/113.snap.ast +7 -0
  156. package/test/snapshots/pfm/generic_directives/114.snap.ast +12 -0
  157. package/test/snapshots/pfm/generic_directives/115.snap.ast +10 -0
  158. package/test/snapshots/pfm/generic_directives/116.snap.ast +13 -0
  159. package/test/snapshots/pfm/generic_directives/117.snap.ast +9 -0
  160. package/test/snapshots/pfm/generic_directives/118.snap.ast +10 -0
  161. package/test/snapshots/pfm/generic_directives/119.snap.ast +9 -0
  162. package/test/snapshots/pfm/generic_directives/120.snap.ast +12 -0
  163. package/test/snapshots/pfm/generic_directives/121.snap.ast +3 -0
  164. package/test/snapshots/pfm/generic_directives/122.snap.ast +3 -0
  165. package/test/snapshots/pfm/generic_directives/123.snap.ast +3 -0
  166. package/test/snapshots/pfm/hard_line_breaks/642.snap.ast +1 -1
  167. package/test/snapshots/pfm/hard_line_breaks/643.snap.ast +1 -1
  168. package/test/snapshots/pfm/html/148.snap.ast +1 -1
  169. package/test/snapshots/pfm/html/150.snap.ast +1 -1
  170. package/test/snapshots/pfm/html/159.snap.ast +2 -3
  171. package/test/snapshots/pfm/html/162.snap.ast +3 -4
  172. package/test/snapshots/pfm/html/163.snap.ast +1 -1
  173. package/test/snapshots/pfm/html/164.snap.ast +3 -4
  174. package/test/snapshots/pfm/html/166.snap.ast +1 -1
  175. package/test/snapshots/pfm/html/168.snap.ast +2 -3
  176. package/test/snapshots/pfm/html/169.snap.ast +5 -7
  177. package/test/snapshots/pfm/html/174.snap.ast +3 -3
  178. package/test/snapshots/pfm/html/182.snap.ast +1 -1
  179. package/test/snapshots/pfm/html/613.snap.ast +2 -2
  180. package/test/snapshots/pfm/html/615.snap.ast +2 -2
  181. package/test/snapshots/pfm/images/585.snap.ast +1 -1
  182. package/test/snapshots/pfm/images/589.snap.ast +1 -1
  183. package/test/snapshots/pfm/link_reference_definitions/201.snap.ast +1 -1
  184. package/test/snapshots/pfm/link_reference_definitions/208.snap.ast +1 -1
  185. package/test/snapshots/pfm/links/491.snap.ast +1 -1
  186. package/test/snapshots/pfm/links/494.snap.ast +2 -2
  187. package/test/snapshots/pfm/links/516.snap.ast +8 -9
  188. package/test/snapshots/pfm/links/521.snap.ast +1 -1
  189. package/test/snapshots/pfm/links/530.snap.ast +8 -12
  190. package/test/snapshots/pfm/links/534.snap.ast +1 -1
  191. package/test/snapshots/pfm/links/552.snap.ast +2 -2
  192. package/test/snapshots/pfm/links/559.snap.ast +1 -1
  193. package/test/snapshots/pfm/links/564.snap.ast +1 -1
  194. package/test/snapshots/pfm/list_items/260.snap.ast +3 -4
  195. package/test/snapshots/pfm/list_items/293.snap.ast +2 -2
  196. package/test/snapshots/pfm/tabs/16.snap.ast +2 -3
  197. package/test/snapshots/pfm/tabs/4.snap.ast +6 -5
  198. package/test/snapshots/svelte/00-introduction/00-hello-world/App.snap.ast +3 -4
  199. package/test/snapshots/svelte/00-introduction/02-styling/App.snap.ast +2 -3
  200. package/test/snapshots/svelte/00-introduction/03-nested-components/App.snap.ast +2 -3
  201. package/test/snapshots/svelte/00-introduction/03-nested-components/Nested.snap.ast +1 -2
  202. package/test/snapshots/svelte/00-introduction/04-html-tags/App.snap.ast +1 -2
  203. package/test/snapshots/svelte/01-reactivity/00-reactive-assignments/App.snap.ast +5 -6
  204. package/test/snapshots/svelte/01-reactivity/01-reactive-declarations/App.snap.ast +11 -14
  205. package/test/snapshots/svelte/01-reactivity/02-reactive-statements/App.snap.ast +5 -6
  206. package/test/snapshots/svelte/02-props/00-declaring-props/Nested.snap.ast +2 -3
  207. package/test/snapshots/svelte/02-props/01-default-values/App.snap.ast +1 -1
  208. package/test/snapshots/svelte/02-props/01-default-values/Nested.snap.ast +2 -3
  209. package/test/snapshots/svelte/02-props/02-spread-props/Info.snap.ast +16 -17
  210. package/test/snapshots/svelte/03-logic/00-if-blocks/App.snap.ast +4 -8
  211. package/test/snapshots/svelte/03-logic/01-else-blocks/App.snap.ast +4 -8
  212. package/test/snapshots/svelte/03-logic/02-else-if-blocks/App.snap.ast +6 -9
  213. package/test/snapshots/svelte/03-logic/03-each-blocks/App.snap.ast +5 -8
  214. package/test/snapshots/svelte/03-logic/04-keyed-each-blocks/App.snap.ast +4 -7
  215. package/test/snapshots/svelte/03-logic/04-keyed-each-blocks/Thing.snap.ast +4 -5
  216. package/test/snapshots/svelte/04-events/02-event-modifiers/App.snap.ast +2 -3
  217. package/test/snapshots/svelte/04-events/03-component-events/Inner.snap.ast +2 -3
  218. package/test/snapshots/svelte/04-events/04-event-forwarding/Inner.snap.ast +2 -3
  219. package/test/snapshots/svelte/04-events/05-dom-event-forwarding/FancyButton.snap.ast +2 -3
  220. package/test/snapshots/svelte/05-bindings/00-text-inputs/App.snap.ast +3 -4
  221. package/test/snapshots/svelte/05-bindings/01-numeric-inputs/App.snap.ast +9 -8
  222. package/test/snapshots/svelte/05-bindings/02-checkbox-inputs/App.snap.ast +7 -11
  223. package/test/snapshots/svelte/05-bindings/03-group-inputs/App.snap.ast +21 -30
  224. package/test/snapshots/svelte/05-bindings/04-textarea-inputs/App.snap.ast +1 -2
  225. package/test/snapshots/svelte/05-bindings/05-select-bindings/App.snap.ast +5 -9
  226. package/test/snapshots/svelte/05-bindings/06-multiple-select-bindings/App.snap.ast +18 -26
  227. package/test/snapshots/svelte/05-bindings/07-each-block-bindings/App.snap.ast +7 -11
  228. package/test/snapshots/svelte/05-bindings/08-media-elements/App.snap.ast +15 -19
  229. package/test/snapshots/svelte/05-bindings/09-dimensions/App.snap.ast +7 -9
  230. package/test/snapshots/svelte/05-bindings/11-component-bindings/App.snap.ast +1 -2
  231. package/test/snapshots/svelte/05-bindings/11-component-bindings/Keypad.snap.ast +32 -34
  232. package/test/snapshots/svelte/06-lifecycle/00-onmount/App.snap.ast +3 -6
  233. package/test/snapshots/svelte/06-lifecycle/01-ondestroy/App.snap.ast +6 -7
  234. package/test/snapshots/svelte/06-lifecycle/02-update/App.snap.ast +2 -4
  235. package/test/snapshots/svelte/07-stores/00-writable-stores/App.snap.ast +4 -5
  236. package/test/snapshots/svelte/07-stores/00-writable-stores/Decrementer.snap.ast +2 -3
  237. package/test/snapshots/svelte/07-stores/00-writable-stores/Incrementer.snap.ast +2 -3
  238. package/test/snapshots/svelte/07-stores/00-writable-stores/Resetter.snap.ast +2 -3
  239. package/test/snapshots/svelte/07-stores/01-auto-subscriptions/App.snap.ast +4 -5
  240. package/test/snapshots/svelte/07-stores/01-auto-subscriptions/Decrementer.snap.ast +2 -3
  241. package/test/snapshots/svelte/07-stores/01-auto-subscriptions/Incrementer.snap.ast +2 -3
  242. package/test/snapshots/svelte/07-stores/01-auto-subscriptions/Resetter.snap.ast +2 -3
  243. package/test/snapshots/svelte/07-stores/02-readable-stores/App.snap.ast +2 -3
  244. package/test/snapshots/svelte/07-stores/03-derived-stores/App.snap.ast +8 -10
  245. package/test/snapshots/svelte/07-stores/04-custom-stores/App.snap.ast +7 -11
  246. package/test/snapshots/svelte/08-motion/00-tweened/App.snap.ast +10 -15
  247. package/test/snapshots/svelte/08-motion/01-spring/App.snap.ast +10 -10
  248. package/test/snapshots/svelte/09-transitions/00-transition/App.snap.ast +3 -5
  249. package/test/snapshots/svelte/09-transitions/01-adding-parameters-to-transitions/App.snap.ast +3 -5
  250. package/test/snapshots/svelte/09-transitions/02-in-and-out/App.snap.ast +3 -5
  251. package/test/snapshots/svelte/09-transitions/03-custom-css-transitions/App.snap.ast +4 -6
  252. package/test/snapshots/svelte/09-transitions/04-custom-js-transitions/App.snap.ast +3 -5
  253. package/test/snapshots/svelte/09-transitions/05-transition-events/App.snap.ast +5 -8
  254. package/test/snapshots/svelte/10-animations/00-animate/App.snap.ast +16 -20
  255. package/test/snapshots/svelte/11-easing/00-easing/App.snap.ast +16 -11
  256. package/test/snapshots/svelte/11-easing/00-easing/Controls.snap.ast +11 -16
  257. package/test/snapshots/svelte/11-easing/00-easing/Grid.snap.ast +2 -2
  258. package/test/snapshots/svelte/12-svg/01-clock/App.snap.ast +2 -1
  259. package/test/snapshots/svelte/12-svg/02-bar-chart/App.snap.ast +7 -9
  260. package/test/snapshots/svelte/12-svg/03-area-chart/App.snap.ast +14 -15
  261. package/test/snapshots/svelte/12-svg/04-scatterplot/App.snap.ast +7 -5
  262. package/test/snapshots/svelte/12-svg/04-scatterplot/Scatterplot.snap.ast +6 -6
  263. package/test/snapshots/svelte/12-svg/05-svg-transitions/App.snap.ast +5 -6
  264. package/test/snapshots/svelte/13-actions/01-adding-parameters-to-actions/App.snap.ast +2 -3
  265. package/test/snapshots/svelte/14-classes/00-classes/App.snap.ast +3 -6
  266. package/test/snapshots/svelte/14-classes/01-class-shorthand/App.snap.ast +2 -3
  267. package/test/snapshots/svelte/15-composition/00-slots/App.snap.ast +3 -5
  268. package/test/snapshots/svelte/15-composition/01-slot-fallbacks/App.snap.ast +3 -5
  269. package/test/snapshots/svelte/15-composition/01-slot-fallbacks/Box.snap.ast +1 -2
  270. package/test/snapshots/svelte/15-composition/02-named-slots/App.snap.ast +7 -11
  271. package/test/snapshots/svelte/15-composition/02-named-slots/ContactCard.snap.ast +3 -6
  272. package/test/snapshots/svelte/15-composition/03-slot-props/App.snap.ast +9 -15
  273. package/test/snapshots/svelte/15-composition/04-modal/App.snap.ast +17 -26
  274. package/test/snapshots/svelte/15-composition/04-modal/Modal.snap.ast +3 -3
  275. package/test/snapshots/svelte/16-context/00-context-api/App.snap.ast +10 -5
  276. package/test/snapshots/svelte/17-special-elements/00-svelte-self/File.snap.ast +1 -2
  277. package/test/snapshots/svelte/17-special-elements/00-svelte-self/Folder.snap.ast +1 -2
  278. package/test/snapshots/svelte/17-special-elements/01-svelte-component/App.snap.ast +1 -2
  279. package/test/snapshots/svelte/17-special-elements/01-svelte-component/BlueThing.snap.ast +1 -2
  280. package/test/snapshots/svelte/17-special-elements/01-svelte-component/GreenThing.snap.ast +1 -2
  281. package/test/snapshots/svelte/17-special-elements/01-svelte-component/RedThing.snap.ast +1 -2
  282. package/test/snapshots/svelte/17-special-elements/02-svelte-window/App.snap.ast +3 -6
  283. package/test/snapshots/svelte/17-special-elements/03-svelte-window-bindings/App.snap.ast +2 -4
  284. package/test/snapshots/svelte/17-special-elements/05-svelte-head/App.snap.ast +6 -12
  285. package/test/snapshots/svelte/18-module-context/01-module-exports/App.snap.ast +2 -3
  286. package/test/snapshots/svelte/18-module-context/01-module-exports/AudioPlayer.snap.ast +4 -7
  287. package/test/snapshots/svelte/19-debugging/00-debug/App.snap.ast +5 -7
  288. package/test/snapshots/svelte/19-debugging/00-debug/Test.snap.ast +7 -11
  289. package/test/snapshots/svelte/20-7guis/01-7guis-counter/App.snap.ast +2 -3
  290. package/test/snapshots/svelte/20-7guis/02-7guis-temperature/App.snap.ast +2 -2
  291. package/test/snapshots/svelte/20-7guis/03-7guis-flight-booker/App.snap.ast +4 -7
  292. package/test/snapshots/svelte/20-7guis/04-7guis-timer/App.snap.ast +13 -17
  293. package/test/snapshots/svelte/20-7guis/05-7guis-crud/App.snap.ast +11 -13
  294. package/test/snapshots/svelte/20-7guis/06-7guis-circles/App.snap.ast +10 -11
  295. package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/Comment.snap.ast +4 -6
  296. package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/Item.snap.ast +9 -13
  297. package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/List.snap.ast +3 -5
  298. package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/Summary.snap.ast +7 -11
  299. package/test/snapshots/svelte/21-miscellaneous/02-immutable-data/App.snap.ast +2 -4
  300. package/test/snapshots/svelte/99-embeds/20181225-blog-svelte-css-in-js/App.snap.ast +6 -7
  301. package/test/snapshots/svelte/99-embeds/20181225-blog-svelte-css-in-js/Hero.snap.ast +3 -5
  302. package/test/snapshots/svelte/99-embeds/20190420-blog-write-less-code/App.snap.ast +6 -7
  303. package/test/svelte_expressions.spec.ts +93 -4
  304. package/test/svelte_tags.spec.ts +27 -12
  305. package/test/tables.spec.ts +347 -0
  306. package/test/tree_builder.spec.ts +286 -1
  307. package/test/unclosed_delimiters.spec.ts +529 -0
  308. package/tsc/buf_utils.d.ts +1 -1
  309. package/tsc/buf_utils.js +9 -9
  310. package/tsc/cursor.d.ts +17 -13
  311. package/tsc/cursor.js +60 -43
  312. package/tsc/main.d.ts +362 -26
  313. package/tsc/main.js +8955 -4891
  314. package/tsc/node_view.d.ts +11 -12
  315. package/tsc/node_view.js +134 -102
  316. package/tsc/opcodes.d.ts +23 -6
  317. package/tsc/plugin_dispatch.d.ts +22 -8
  318. package/tsc/plugin_dispatch.js +292 -170
  319. package/tsc/tree_builder.d.ts +42 -11
  320. package/tsc/tree_builder.js +237 -82
  321. package/tsc/undo_log.d.ts +11 -1
  322. package/tsc/undo_log.js +54 -19
  323. package/tsc/utils.d.ts +77 -51
  324. package/tsc/utils.js +687 -344
  325. package/tsc/utils.spec.js +83 -9
  326. package/tsc/wire_emitter.js +6 -0
  327. package/tsc/wire_tree_builder.d.ts +4 -7
  328. package/tsc/wire_tree_builder.js +34 -37
  329. package/dist/node_view-BEh2-H86.js +0 -373
@@ -1,7 +1,19 @@
1
1
  import { describe, expect, test } from 'vitest';
2
2
 
3
3
  import { get_content, get_all_child_kinds } from './utils';
4
- import { parse_markdown_svelte } from '../src/main';
4
+ import { print_ast } from './print';
5
+ import {
6
+ NodeKind,
7
+ PFMParser,
8
+ WireEmitter,
9
+ parse_markdown_svelte,
10
+ } from '../src/main';
11
+ import type { Emitter } from '../src/opcodes';
12
+ import type { ParsePlugin } from '../src/plugin_types';
13
+ import { TreeBuilder } from '../src/tree_builder';
14
+ import { kind_to_string } from '../src/utils';
15
+ import type { NodeBuffer } from '../src/utils';
16
+ import { WireTreeBuilder } from '../src/wire_tree_builder';
5
17
 
6
18
  /** Find first child of a given kind under a node. */
7
19
  const find_child = (
@@ -405,6 +417,216 @@ describe('container block directives', () => {
405
417
  const directive = find_child(nodes, bq!.index, 'directive_container');
406
418
  expect(directive).not.toBeNull();
407
419
  });
420
+
421
+ describe('fence ending at eof keeps the container label', () => {
422
+ for (const input of [
423
+ ':::q[lab]\n```\ncode',
424
+ ':::q[lab]\n```\ncode\n',
425
+ ':::q[lab]\n```\ncode\n```',
426
+ ':::q[lab]\n```js',
427
+ ':::q[lab]\n```js\n',
428
+ ]) {
429
+ test(JSON.stringify(input), () => {
430
+ for (const nodes of [
431
+ parse_markdown_svelte(input).nodes,
432
+ parse_fed(input, 1),
433
+ ]) {
434
+ const directive = find_child(nodes, 0, 'directive_container')!;
435
+ expect(get_content(nodes, directive.index, input).value).toBe('lab');
436
+ expect(directive.end).toBe(input.length);
437
+ const code = find_child(nodes, directive.index, 'code_fence')!;
438
+ expect(code.children).toEqual([]);
439
+ }
440
+ });
441
+ }
442
+ });
443
+ });
444
+
445
+ const shape_without_positions = (
446
+ nodes: ReturnType<typeof parse_markdown_svelte>['nodes'],
447
+ idx: number,
448
+ input: string
449
+ ): unknown => {
450
+ const node = nodes.get_node(idx);
451
+ return {
452
+ kind: node.kind,
453
+ metadata: node.metadata,
454
+ text: node.kind === 'text' ? input.slice(node.value[0], node.value[1]) : '',
455
+ children: node.children.map((c) =>
456
+ shape_without_positions(nodes, c, input)
457
+ ),
458
+ };
459
+ };
460
+
461
+ /** parses body at the root and inside a note container */
462
+ const root_and_container_lists = (body: string) => {
463
+ const at_root = parse_markdown_svelte(body);
464
+ const root_list = find_child(
465
+ at_root.nodes,
466
+ at_root.nodes.get_node().index,
467
+ 'list'
468
+ );
469
+ expect(root_list).not.toBeNull();
470
+
471
+ const input = `:::note[]\n${body}:::\n`;
472
+ const { nodes } = parse_markdown_svelte(input);
473
+ const container = find_child(
474
+ nodes,
475
+ nodes.get_node().index,
476
+ 'directive_container'
477
+ );
478
+ expect(container).not.toBeNull();
479
+ expect(find_children(nodes, container!.index, 'paragraph')).toEqual([]);
480
+ const list = find_child(nodes, container!.index, 'list');
481
+ expect(list).not.toBeNull();
482
+
483
+ return {
484
+ root: shape_without_positions(at_root.nodes, root_list!.index, body),
485
+ container: shape_without_positions(nodes, list!.index, input),
486
+ list: list!,
487
+ nodes,
488
+ };
489
+ };
490
+
491
+ describe('lists in container directives', () => {
492
+ test('bullet list', () => {
493
+ const { root, container, list, nodes } =
494
+ root_and_container_lists('- a\n- b\n');
495
+ expect(container).toEqual(root);
496
+ expect(list.metadata.ordered).toBe(false);
497
+ expect(find_children(nodes, list.index, 'list_item').length).toBe(2);
498
+ });
499
+
500
+ test('bullet list with * and + markers', () => {
501
+ for (const body of ['* a\n* b\n', '+ a\n+ b\n']) {
502
+ const { root, container } = root_and_container_lists(body);
503
+ expect(container).toEqual(root);
504
+ }
505
+ });
506
+
507
+ test('ordered list', () => {
508
+ const { root, container, list } = root_and_container_lists('3. a\n4. b\n');
509
+ expect(container).toEqual(root);
510
+ expect(list.metadata.ordered).toBe(true);
511
+ expect(list.metadata.start).toBe(3);
512
+ });
513
+
514
+ test('ordered list with ) delimiter', () => {
515
+ const { root, container } = root_and_container_lists('1) a\n2) b\n');
516
+ expect(container).toEqual(root);
517
+ });
518
+
519
+ test('task list items', () => {
520
+ const { root, container, list, nodes } =
521
+ root_and_container_lists('- [ ] a\n- [x] b\n');
522
+ expect(container).toEqual(root);
523
+ expect(find_children(nodes, list.index, 'list_item').length).toBe(2);
524
+ });
525
+
526
+ test('nested list', () => {
527
+ const { root, container } = root_and_container_lists(
528
+ '- a\n - b\n - c\n- d\n'
529
+ );
530
+ expect(container).toEqual(root);
531
+ });
532
+
533
+ test('loose list', () => {
534
+ const { root, container, list } = root_and_container_lists('- a\n\n- b\n');
535
+ expect(container).toEqual(root);
536
+ expect(list.metadata.tight).toBe(false);
537
+ });
538
+
539
+ test('list after a paragraph', () => {
540
+ const input = ':::note[]\nintro\n- a\n:::\n';
541
+ const { nodes } = parse_markdown_svelte(input);
542
+
543
+ const container = find_child(
544
+ nodes,
545
+ nodes.get_node().index,
546
+ 'directive_container'
547
+ );
548
+ const kinds = get_all_child_kinds(nodes, container!.index).filter(
549
+ (k) => k !== 'line_break'
550
+ );
551
+ expect(kinds).toEqual(['paragraph', 'list']);
552
+ });
553
+
554
+ test('closing fence ends the list and the container', () => {
555
+ const input = ':::note[]\n- a\n- b\n:::\nafter\n';
556
+ const { nodes } = parse_markdown_svelte(input);
557
+
558
+ const root = nodes.get_node();
559
+ const root_kinds = get_all_child_kinds(nodes, root.index).filter(
560
+ (k) => k !== 'line_break'
561
+ );
562
+ expect(root_kinds).toEqual(['directive_container', 'paragraph']);
563
+
564
+ const container = find_child(nodes, root.index, 'directive_container');
565
+ const list = find_child(nodes, container!.index, 'list');
566
+ const items = find_children(nodes, list!.index, 'list_item');
567
+ expect(items.length).toBe(2);
568
+ const text = find_child(nodes, items[1].index, 'text');
569
+ expect(get_content(nodes, text!.index, input).value).toBe('b');
570
+ });
571
+
572
+ test('list closes at eof without a closing fence', () => {
573
+ const input = ':::note[]\n- a\n- b';
574
+ const { nodes } = parse_markdown_svelte(input);
575
+
576
+ const container = find_child(
577
+ nodes,
578
+ nodes.get_node().index,
579
+ 'directive_container'
580
+ );
581
+ const list = find_child(nodes, container!.index, 'list');
582
+ expect(find_children(nodes, list!.index, 'list_item').length).toBe(2);
583
+ });
584
+
585
+ test('list in a nested container, then in the outer one', () => {
586
+ const input = '::::outer[]\n:::inner[]\n- a\n:::\n1. b\n::::\n';
587
+ const { nodes } = parse_markdown_svelte(input);
588
+
589
+ const outer = find_child(
590
+ nodes,
591
+ nodes.get_node().index,
592
+ 'directive_container'
593
+ );
594
+ const inner = find_child(nodes, outer!.index, 'directive_container');
595
+ expect(find_child(nodes, inner!.index, 'list')!.metadata.ordered).toBe(
596
+ false
597
+ );
598
+ expect(find_child(nodes, outer!.index, 'list')!.metadata.ordered).toBe(
599
+ true
600
+ );
601
+ });
602
+
603
+ test('thematic break is still a thematic break', () => {
604
+ const input = ':::note[]\n- - -\n:::\n';
605
+ const { nodes } = parse_markdown_svelte(input);
606
+
607
+ const container = find_child(
608
+ nodes,
609
+ nodes.get_node().index,
610
+ 'directive_container'
611
+ );
612
+ expect(
613
+ find_child(nodes, container!.index, 'thematic_break')
614
+ ).not.toBeNull();
615
+ expect(find_child(nodes, container!.index, 'list')).toBeNull();
616
+ });
617
+
618
+ test('number without a list delimiter is a paragraph', () => {
619
+ const input = ':::note[]\n2026 was a year\n:::\n';
620
+ const { nodes } = parse_markdown_svelte(input);
621
+
622
+ const container = find_child(
623
+ nodes,
624
+ nodes.get_node().index,
625
+ 'directive_container'
626
+ );
627
+ expect(find_child(nodes, container!.index, 'paragraph')).not.toBeNull();
628
+ expect(find_child(nodes, container!.index, 'list')).toBeNull();
629
+ });
408
630
  });
409
631
 
410
632
  // ===========================================================
@@ -774,3 +996,310 @@ describe('directive text content', () => {
774
996
  expect(kinds).toContain('link');
775
997
  });
776
998
  });
999
+
1000
+ /** the tree under the root, as print_ast prints it */
1001
+ const ast = (input: string) => {
1002
+ const { nodes, source } = parse_markdown_svelte(input);
1003
+ return print_ast(nodes, source).split('\n').slice(1).join('\n');
1004
+ };
1005
+
1006
+ /** kinds and text of a buffer, text read from the source or a wire string */
1007
+ function shape(nodes: NodeBuffer, source: string | null, index = 0): unknown {
1008
+ const node = nodes.get_node(index);
1009
+ if (node.kind === 'text') {
1010
+ const text =
1011
+ source === null
1012
+ ? nodes._strings[index]
1013
+ : source.slice(node.value[0], node.value[1]);
1014
+ return 'text:' + text;
1015
+ }
1016
+ const kids = node.children
1017
+ .filter((c) => nodes.get_node(c).kind !== 'line_break')
1018
+ .map((c) => shape(nodes, source, c));
1019
+ return kids.length === 0 ? node.kind : [node.kind, ...kids];
1020
+ }
1021
+
1022
+ function parse_fed(source: string, chunk: number): NodeBuffer {
1023
+ const tree = new TreeBuilder(source.length);
1024
+ const parser = new PFMParser(tree);
1025
+ parser.init();
1026
+ for (let i = 0; i < source.length; i += chunk) {
1027
+ parser.feed(source.slice(i, i + chunk));
1028
+ }
1029
+ parser.finish();
1030
+ return tree.get_buffer();
1031
+ }
1032
+
1033
+ function parse_over_wire(source: string, chunk: number): NodeBuffer {
1034
+ const emitter = new WireEmitter();
1035
+ const parser = new PFMParser(emitter);
1036
+ const builder = new WireTreeBuilder();
1037
+ parser.init();
1038
+ for (let i = 0; i < source.length; i += chunk) {
1039
+ emitter.set_source(source.slice(0, i + chunk));
1040
+ parser.feed(source.slice(i, i + chunk));
1041
+ builder.apply(emitter.flush());
1042
+ }
1043
+ emitter.set_source(source);
1044
+ parser.finish();
1045
+ builder.apply(emitter.flush());
1046
+ return builder.get_buffer();
1047
+ }
1048
+
1049
+ describe('block directive labels', () => {
1050
+ test('a leaf label is a directive_label child holding inline nodes', () => {
1051
+ expect(ast('::note[Heads *up* and _soft_]\n')).toBe(
1052
+ [
1053
+ ' directive_leaf name="note"',
1054
+ ' directive_label',
1055
+ ' text "Heads "',
1056
+ ' strong_emphasis',
1057
+ ' text "up"',
1058
+ ' text " and "',
1059
+ ' emphasis',
1060
+ ' text "soft"',
1061
+ ].join('\n')
1062
+ );
1063
+ });
1064
+
1065
+ test('a container label comes first, the body blocks follow it', () => {
1066
+ const input = ':::Callout[Heads *up*](kind=warn)\nbody\n\n> quote\n:::\n';
1067
+ const { nodes, source } = parse_markdown_svelte(input);
1068
+ const box = find_child(nodes, 0, 'directive_container')!;
1069
+ expect(box.metadata.args).toEqual({ kind: 'warn' });
1070
+ expect(shape(nodes, source, box.index)).toEqual([
1071
+ 'directive_container',
1072
+ ['directive_label', 'text:Heads ', ['strong_emphasis', 'text:up']],
1073
+ ['paragraph', 'text:body'],
1074
+ ['block_quote', ['paragraph', 'text:quote']],
1075
+ ]);
1076
+ const kinds = get_all_child_kinds(nodes, box.index);
1077
+ expect(kinds.filter((k) => k === 'directive_label')).toHaveLength(1);
1078
+ });
1079
+
1080
+ test('the label spans its brackets, its value is the text between', () => {
1081
+ const input = '::x[a *b*](k=v)\n';
1082
+ const { nodes, source } = parse_markdown_svelte(input);
1083
+ const leaf = find_child(nodes, 0, 'directive_leaf')!;
1084
+ const label = find_child(nodes, leaf.index, 'directive_label')!;
1085
+ expect(get_content(nodes, label.index, source)).toEqual({
1086
+ content: '[a *b*]',
1087
+ value: 'a *b*',
1088
+ });
1089
+ expect(get_content(nodes, leaf.index, source).value).toBe('a *b*');
1090
+ const strong = find_child(nodes, label.index, 'strong_emphasis')!;
1091
+ expect(get_content(nodes, strong.index, source)).toEqual({
1092
+ content: '*b*',
1093
+ value: 'b',
1094
+ });
1095
+ });
1096
+
1097
+ test('empty brackets make no label', () => {
1098
+ expect(ast('::x[]\n')).toBe(' directive_leaf name="x"');
1099
+ expect(
1100
+ get_all_child_kinds(parse_markdown_svelte(':::x[]\na\n:::\n').nodes, 1)
1101
+ ).toEqual(['paragraph', 'line_break']);
1102
+ });
1103
+
1104
+ test('whitespace only text is still a label', () => {
1105
+ expect(ast('::x[ ]\n')).toBe(
1106
+ [
1107
+ ' directive_leaf name="x"',
1108
+ ' directive_label',
1109
+ ' text " "',
1110
+ ].join('\n')
1111
+ );
1112
+ });
1113
+
1114
+ test('an unclosed delimiter stays literal and never reaches the args', () => {
1115
+ expect(ast('::x[*open](k=*)\n')).toBe(
1116
+ [
1117
+ ' directive_leaf name="x" args.k="*"',
1118
+ ' directive_label',
1119
+ ' text "*open"',
1120
+ ].join('\n')
1121
+ );
1122
+ });
1123
+
1124
+ test('a delimiter cannot close past the ], the line stays a directive', () => {
1125
+ const { nodes } = parse_markdown_svelte('::x[a _b](c=d_)\n');
1126
+ const leaf = find_child(nodes, 0, 'directive_leaf')!;
1127
+ expect(leaf.metadata.args).toEqual({ c: 'd_' });
1128
+ const label = find_child(nodes, leaf.index, 'directive_label')!;
1129
+ expect(get_all_child_kinds(nodes, label.index)).not.toContain('emphasis');
1130
+ });
1131
+
1132
+ test('a code span keeps its brackets', () => {
1133
+ expect(ast('::x[`a]b` code]\n')).toBe(
1134
+ [
1135
+ ' directive_leaf name="x"',
1136
+ ' directive_label',
1137
+ ' code_span "a]b"',
1138
+ ' text " code"',
1139
+ ].join('\n')
1140
+ );
1141
+ const { nodes } = parse_markdown_svelte('::x[a `b] c\n');
1142
+ expect(get_all_child_kinds(nodes, 0)).toEqual(['paragraph', 'line_break']);
1143
+ });
1144
+
1145
+ test('links, images and autolinks stay literal text', () => {
1146
+ const { nodes } = parse_markdown_svelte(
1147
+ '::x[see [docs](/d) <https://x.y> ![i](s)]\n'
1148
+ );
1149
+ const leaf = find_child(nodes, 0, 'directive_leaf')!;
1150
+ const label = find_child(nodes, leaf.index, 'directive_label')!;
1151
+ const kinds = get_all_child_kinds(nodes, label.index);
1152
+ expect(kinds.every((k) => k === 'text')).toBe(true);
1153
+ });
1154
+
1155
+ test('an inline directive nests in a label', () => {
1156
+ expect(ast(':::x[a :y[b](k=v) c]\n:::\n')).toBe(
1157
+ [
1158
+ ' directive_container name="x"',
1159
+ ' directive_label',
1160
+ ' text "a "',
1161
+ ' directive_inline name="y" args.k="v"',
1162
+ ' text "b"',
1163
+ ' text " c"',
1164
+ ].join('\n')
1165
+ );
1166
+ });
1167
+
1168
+ test('links parse again in the body after a label', () => {
1169
+ const { nodes } = parse_markdown_svelte(':::x[a]\n[l](u)\n:::\n');
1170
+ const box = find_child(nodes, 0, 'directive_container')!;
1171
+ const para = find_child(nodes, box.index, 'paragraph')!;
1172
+ expect(get_all_child_kinds(nodes, para.index)).toEqual(['link']);
1173
+ });
1174
+
1175
+ test('labels in a block quote and a list', () => {
1176
+ const quoted = parse_markdown_svelte('> ::q[*a*]\n');
1177
+ expect(shape(quoted.nodes, quoted.source)).toEqual([
1178
+ 'root',
1179
+ [
1180
+ 'block_quote',
1181
+ ['directive_leaf', ['directive_label', ['strong_emphasis', 'text:a']]],
1182
+ ],
1183
+ ]);
1184
+ const { nodes, source } = parse_markdown_svelte(
1185
+ '- ::x[a *b*]\n- ::y[`c`]\n'
1186
+ );
1187
+ expect(shape(nodes, source)).toEqual([
1188
+ 'root',
1189
+ [
1190
+ 'list',
1191
+ [
1192
+ 'list_item',
1193
+ [
1194
+ 'directive_leaf',
1195
+ ['directive_label', 'text:a ', ['strong_emphasis', 'text:b']],
1196
+ ],
1197
+ ],
1198
+ ['list_item', ['directive_leaf', ['directive_label', 'code_span']]],
1199
+ ],
1200
+ ]);
1201
+ });
1202
+
1203
+ describe('incremental', () => {
1204
+ const cases = [
1205
+ '::note[Heads *up* and _soft_]\n',
1206
+ ':::Callout[Heads *up*](kind=warn)\nbody *x*\n:::\n',
1207
+ '::x[*open](k=*)\n',
1208
+ '::x[`a]b` and :y[c](k=v)]\nafter\n',
1209
+ 'text\n::x[~~s~~ ^up^ ~down~ \\*l\\* {e} <b>h</b>]\n',
1210
+ '> ::q[*a*]\n\n- ::x[a *b*]\n',
1211
+ ':::a[*o*]\n:::b[_i_]\nx\n:::\n:::\n',
1212
+ '::x[a',
1213
+ '::x[*a*]',
1214
+ ];
1215
+ for (const input of cases) {
1216
+ test(`fed in chunks matches the batch tree: ${JSON.stringify(input)}`, () => {
1217
+ const { nodes, source } = parse_markdown_svelte(input);
1218
+ const batch = print_ast(nodes, source);
1219
+ for (const chunk of [1, 2, 3, 5, 8, 64]) {
1220
+ expect(print_ast(parse_fed(input, chunk), source)).toBe(batch);
1221
+ }
1222
+ });
1223
+ }
1224
+
1225
+ test('the label opens and closes at the end of its line, before the body', () => {
1226
+ const ops: string[] = [];
1227
+ const rec: Emitter = {
1228
+ open: (_id, kind) => ops.push('open ' + kind_to_string(kind)),
1229
+ close: (id) => ops.push('close ' + id),
1230
+ text() {},
1231
+ attr() {},
1232
+ set_value_start() {},
1233
+ set_value_end() {},
1234
+ revoke: (id) => ops.push('revoke ' + id),
1235
+ commit() {},
1236
+ cursor() {},
1237
+ };
1238
+ const p = new PFMParser(rec);
1239
+ p.init();
1240
+ p.feed(':::box[*L*](k=v)');
1241
+ expect(ops).toEqual(['open root']);
1242
+ p.feed('\n');
1243
+ expect(ops).toEqual([
1244
+ 'open root',
1245
+ 'open directive_container',
1246
+ 'open directive_label',
1247
+ 'open strong_emphasis',
1248
+ 'open text',
1249
+ 'close 4',
1250
+ 'close 3',
1251
+ 'close 2',
1252
+ ]);
1253
+ p.feed('body\n:::\n');
1254
+ p.finish();
1255
+ expect(ops.slice(8, 10)).toEqual(['open paragraph', 'open text']);
1256
+ });
1257
+ });
1258
+
1259
+ describe('wire', () => {
1260
+ test('the schema names the label kind', () => {
1261
+ const emitter = new WireEmitter();
1262
+ emitter.set_source('::x[a]\n');
1263
+ new PFMParser(emitter).parse('::x[a]\n');
1264
+ const schema = emitter.flush()[0];
1265
+ expect(schema[0]).toBe('S');
1266
+ expect((schema[1] as string[])[NodeKind.directive_label]).toBe(
1267
+ 'directive_label'
1268
+ );
1269
+ });
1270
+
1271
+ const cases = [
1272
+ ':::Callout[Heads *up* `c`](kind=warn)\nbody\n:::\n',
1273
+ '::x[a :y[b] c]\n',
1274
+ '> ::q[_a_ b]\n',
1275
+ ];
1276
+ for (const input of cases) {
1277
+ test(`the wire tree matches the batch tree: ${JSON.stringify(input)}`, () => {
1278
+ const { nodes, source } = parse_markdown_svelte(input);
1279
+ const expected = shape(nodes, source);
1280
+ for (const chunk of [1, 4, input.length]) {
1281
+ expect(shape(parse_over_wire(input, chunk), null)).toEqual(expected);
1282
+ }
1283
+ });
1284
+ }
1285
+ });
1286
+
1287
+ test('a parse plugin can address the label', () => {
1288
+ const seen: string[] = [];
1289
+ const plugin: ParsePlugin = {
1290
+ directive_label: {
1291
+ parse(node) {
1292
+ seen.push(node.type);
1293
+ node.attrs.role = 'caption';
1294
+ },
1295
+ },
1296
+ };
1297
+ const { nodes } = parse_markdown_svelte(':::x[*a*]\nb\n:::\n', {
1298
+ plugins: [plugin],
1299
+ });
1300
+ expect(seen).toEqual(['directive_label']);
1301
+ const box = find_child(nodes, 0, 'directive_container')!;
1302
+ const label = find_child(nodes, box.index, 'directive_label')!;
1303
+ expect(label.metadata).toEqual({ role: 'caption' });
1304
+ });
1305
+ });
@@ -1848,7 +1848,7 @@ describe('emphasis and strong emphasis', () => {
1848
1848
  expect(kinds).not.toContain('emphasis');
1849
1849
  });
1850
1850
 
1851
- // *a `*`*, code span takes precedence, prevents emphasis closing
1851
+ // *a `*`*, code span takes precedence over the inner *
1852
1852
  test('pfm example 478', () => {
1853
1853
  const input = load_fixture('478');
1854
1854
  const { nodes } = parse_markdown_svelte(input);
@@ -1857,10 +1857,13 @@ describe('emphasis and strong emphasis', () => {
1857
1857
  const paragraph = nodes.get_node(root.children[0]);
1858
1858
  expect(paragraph.kind).toBe('paragraph');
1859
1859
  const kinds = paragraph.children.map((i) => nodes.get_node(i).kind);
1860
- expect(kinds).toContain('code_span');
1860
+ expect(kinds).toEqual(['strong_emphasis']);
1861
+ const wrapper = nodes.get_node(paragraph.children[0]);
1862
+ const inner = wrapper.children.map((i) => nodes.get_node(i).kind);
1863
+ expect(inner).toEqual(['text', 'code_span']);
1861
1864
  });
1862
1865
 
1863
- // _a `_`_, code span takes precedence, prevents emphasis closing
1866
+ // _a `_`_, code span takes precedence over the inner _
1864
1867
  test('pfm example 479', () => {
1865
1868
  const input = load_fixture('479');
1866
1869
  const { nodes } = parse_markdown_svelte(input);
@@ -1869,7 +1872,10 @@ describe('emphasis and strong emphasis', () => {
1869
1872
  const paragraph = nodes.get_node(root.children[0]);
1870
1873
  expect(paragraph.kind).toBe('paragraph');
1871
1874
  const kinds = paragraph.children.map((i) => nodes.get_node(i).kind);
1872
- expect(kinds).toContain('code_span');
1875
+ expect(kinds).toEqual(['emphasis']);
1876
+ const wrapper = nodes.get_node(paragraph.children[0]);
1877
+ const inner = wrapper.children.map((i) => nodes.get_node(i).kind);
1878
+ expect(inner).toEqual(['text', 'code_span']);
1873
1879
  });
1874
1880
 
1875
1881
  // **a<https://foo.bar/?q=**>, autolink takes precedence over strong
@@ -0,0 +1,4 @@
1
+ > ```
2
+ > code
3
+ > ```
4
+ > after
@@ -0,0 +1,4 @@
1
+ >```
2
+ >a
3
+ > ```
4
+ >b
@@ -0,0 +1,5 @@
1
+ > ```
2
+ > a
3
+ > ```
4
+
5
+ after
@@ -0,0 +1,5 @@
1
+ > ```js
2
+ > a
3
+ >
4
+ > b
5
+ > ```
@@ -0,0 +1,4 @@
1
+ > ````
2
+ > ```
3
+ > ````
4
+ > after
@@ -0,0 +1,3 @@
1
+ > > ```
2
+ > > a
3
+ > > ```
@@ -0,0 +1,6 @@
1
+ > ```
2
+ > a
3
+ > ```
4
+ > ```
5
+ > b
6
+ > ```
@@ -0,0 +1,2 @@
1
+ > ```
2
+ > code
@@ -0,0 +1 @@
1
+ a `#!ts` b.
@@ -0,0 +1 @@
1
+ a `#!` b.
@@ -0,0 +1 @@
1
+ a `#!ts ` b.
@@ -0,0 +1 @@
1
+ a `#!ts` b `#!js c` d.
@@ -0,0 +1,2 @@
1
+ a `#!` b
2
+ c `d` e.
@@ -0,0 +1 @@
1
+ ::note[Heads *up* and _soft_]
@@ -0,0 +1,3 @@
1
+ :::Callout[Heads *up*](kind=warn)
2
+ body
3
+ :::
@@ -0,0 +1 @@
1
+ ::x[`a]b` code]
@@ -0,0 +1 @@
1
+ ::x[*open](k=*)
@@ -0,0 +1 @@
1
+ ::x[see [docs](/d) <https://x.y> ![i](s)]
@@ -0,0 +1 @@
1
+ ::x[a :y[b](k=v) c]
@@ -0,0 +1 @@
1
+ ::x[~~s~~ ^up^ ~down~ \*lit\* {expr} <b>h</b>]
@@ -0,0 +1 @@
1
+ > ::q[*quoted* text]