@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.
- package/CHANGELOG.md +213 -0
- package/WIRE_FORMAT.md +5 -1
- package/dist/buf-utils.js +23 -23
- package/dist/buf_utils.d.ts +1 -1
- package/dist/cursor.d.ts +17 -13
- package/dist/cursor.js +118 -31
- package/dist/main.d.ts +362 -26
- package/dist/main.js +5841 -3420
- package/dist/node_view-bvM0i0-p.js +407 -0
- package/dist/node_view.d.ts +11 -12
- package/dist/opcodes.d.ts +23 -6
- package/dist/plugin_dispatch.d.ts +22 -8
- package/dist/tree-builder.js +185 -66
- package/dist/tree_builder.d.ts +42 -11
- package/dist/undo_log.d.ts +11 -1
- package/dist/utils.d.ts +77 -51
- package/dist/utils.js +687 -209
- package/dist/wire-tree-builder.js +69 -71
- package/dist/wire_tree_builder.d.ts +4 -7
- package/package.json +1 -1
- package/src/buf_utils.ts +10 -14
- package/src/cursor.ts +74 -57
- package/src/main.ts +9898 -5593
- package/src/node_view.ts +159 -140
- package/src/opcodes.ts +39 -7
- package/src/plugin_dispatch.ts +328 -219
- package/src/tree_builder.ts +278 -98
- package/src/undo_log.ts +58 -24
- package/src/utils.spec.ts +86 -9
- package/src/utils.ts +769 -392
- package/src/wire_emitter.ts +6 -0
- package/src/wire_tree_builder.ts +39 -52
- package/test/block_quotes.spec.ts +78 -7
- package/test/code_spans.spec.ts +158 -6
- package/test/crlf.spec.ts +49 -1
- package/test/directives.spec.ts +530 -1
- package/test/emphasis.spec.ts +10 -4
- package/test/fixtures/pfm/block_quotes/pfm_fence_close.md +4 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_close_compact.md +4 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_close_end_quote.md +5 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_close_info.md +5 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_close_longer.md +4 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_close_nested.md +3 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_close_twice.md +6 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_info_eof.md +1 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_unclosed.md +2 -0
- package/test/fixtures/pfm/code_spans/pfm_328_5.md +1 -0
- package/test/fixtures/pfm/code_spans/pfm_328_6.md +1 -0
- package/test/fixtures/pfm/code_spans/pfm_328_7.md +1 -0
- package/test/fixtures/pfm/code_spans/pfm_328_8.md +1 -0
- package/test/fixtures/pfm/code_spans/pfm_328_9.md +2 -0
- package/test/fixtures/pfm/fenced_code_blocks/pfm_info_eof.md +1 -0
- package/test/fixtures/pfm/fenced_code_blocks/pfm_info_eof_no_lf.md +1 -0
- package/test/fixtures/pfm/generic_directives/106.md +1 -0
- package/test/fixtures/pfm/generic_directives/107.md +3 -0
- package/test/fixtures/pfm/generic_directives/108.md +1 -0
- package/test/fixtures/pfm/generic_directives/109.md +1 -0
- package/test/fixtures/pfm/generic_directives/110.md +1 -0
- package/test/fixtures/pfm/generic_directives/111.md +1 -0
- package/test/fixtures/pfm/generic_directives/112.md +1 -0
- package/test/fixtures/pfm/generic_directives/113.md +1 -0
- package/test/fixtures/pfm/generic_directives/114.md +2 -0
- package/test/fixtures/pfm/generic_directives/115.md +1 -0
- package/test/fixtures/pfm/generic_directives/116.md +6 -0
- package/test/fixtures/pfm/generic_directives/117.md +3 -0
- package/test/fixtures/pfm/generic_directives/118.md +6 -0
- package/test/fixtures/pfm/generic_directives/119.md +3 -0
- package/test/fixtures/pfm/generic_directives/120.md +5 -0
- package/test/fixtures/pfm/generic_directives/121.md +3 -0
- package/test/fixtures/pfm/generic_directives/122.md +4 -0
- package/test/fixtures/pfm/generic_directives/123.md +2 -0
- package/test/html.spec.ts +44 -1
- package/test/html_block_containers.spec.ts +445 -0
- package/test/incremental.spec.ts +271 -0
- package/test/lists.spec.ts +107 -1
- package/test/parser_reuse.spec.ts +40 -0
- package/test/plugins.spec.ts +196 -226
- package/test/print.ts +2 -3
- package/test/run_bytecode.spec.ts +36 -0
- package/test/snapshots/hybrid/component-children.snap.ast +9 -16
- package/test/snapshots/hybrid/component-simple-00.snap.ast +1 -2
- package/test/snapshots/hybrid/component-simple-01.snap.ast +1 -2
- package/test/snapshots/hybrid/component-simple-03.snap.ast +13 -13
- package/test/snapshots/hybrid/component-simple-04.snap.ast +1 -2
- package/test/snapshots/hybrid/error.snap.ast +1 -2
- package/test/snapshots/markdown/blockquote-nested-markdown.snap.ast +2 -1
- package/test/snapshots/markdown/emphasis.snap.ast +2 -2
- package/test/snapshots/markdown/encodeHTMLCodeTags.snap.ast +1 -2
- package/test/snapshots/markdown/github-style-codeblock-inside-quote.snap.ast +8 -1
- package/test/snapshots/markdown/html-comments.snap.ast +11 -13
- package/test/snapshots/markdown/html5-strutural-tags.snap.ast +16 -31
- package/test/snapshots/markdown/line-starts-with-html.snap.ast +5 -6
- package/test/snapshots/markdown/literal-html-tags.snap.ast +11 -14
- package/test/snapshots/markdown/nested-blockquote.snap.ast +3 -3
- package/test/snapshots/markdown/pre-code-tags.snap.ast +5 -8
- package/test/snapshots/pfm/block_quotes/237.snap.ast +1 -2
- package/test/snapshots/pfm/block_quotes/251.snap.ast +5 -5
- package/test/snapshots/pfm/block_quotes/pfm_fence_close.snap.ast +6 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_close_compact.snap.ast +6 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_close_end_quote.snap.ast +8 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_close_info.snap.ast +4 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_close_longer.snap.ast +6 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_close_nested.snap.ast +5 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_close_twice.snap.ast +5 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_info_eof.snap.ast +3 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_unclosed.snap.ast +3 -0
- package/test/snapshots/pfm/code_spans/344.snap.ast +1 -1
- package/test/snapshots/pfm/code_spans/347.snap.ast +1 -2
- package/test/snapshots/pfm/code_spans/pfm_328_5.snap.ast +6 -0
- package/test/snapshots/pfm/code_spans/pfm_328_6.snap.ast +6 -0
- package/test/snapshots/pfm/code_spans/pfm_328_7.snap.ast +6 -0
- package/test/snapshots/pfm/code_spans/pfm_328_8.snap.ast +8 -0
- package/test/snapshots/pfm/code_spans/pfm_328_9.snap.ast +10 -0
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/417.snap.ast +2 -2
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/438.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/441.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/444.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/445.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/450.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/453.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/456.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/457.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/473.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/475.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/476.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/477.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/478.snap.ast +3 -4
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/479.snap.ast +3 -4
- package/test/snapshots/pfm/fenced_code_blocks/126.snap.ast +1 -2
- package/test/snapshots/pfm/fenced_code_blocks/pfm_info_eof.snap.ast +2 -0
- package/test/snapshots/pfm/fenced_code_blocks/pfm_info_eof_no_lf.snap.ast +2 -0
- package/test/snapshots/pfm/generic_directives/011.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/015.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/016.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/017.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/019.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/020.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/030.snap.ast +4 -6
- package/test/snapshots/pfm/generic_directives/034.snap.ast +6 -2
- package/test/snapshots/pfm/generic_directives/036.snap.ast +5 -1
- package/test/snapshots/pfm/generic_directives/038.snap.ast +6 -2
- package/test/snapshots/pfm/generic_directives/039.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/040.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/044.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/046.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/089.snap.ast +1 -1
- package/test/snapshots/pfm/generic_directives/103.snap.ast +6 -2
- package/test/snapshots/pfm/generic_directives/106.snap.ast +9 -0
- package/test/snapshots/pfm/generic_directives/107.snap.ast +9 -0
- package/test/snapshots/pfm/generic_directives/108.snap.ast +5 -0
- package/test/snapshots/pfm/generic_directives/109.snap.ast +4 -0
- package/test/snapshots/pfm/generic_directives/110.snap.ast +10 -0
- package/test/snapshots/pfm/generic_directives/111.snap.ast +7 -0
- package/test/snapshots/pfm/generic_directives/112.snap.ast +18 -0
- package/test/snapshots/pfm/generic_directives/113.snap.ast +7 -0
- package/test/snapshots/pfm/generic_directives/114.snap.ast +12 -0
- package/test/snapshots/pfm/generic_directives/115.snap.ast +10 -0
- package/test/snapshots/pfm/generic_directives/116.snap.ast +13 -0
- package/test/snapshots/pfm/generic_directives/117.snap.ast +9 -0
- package/test/snapshots/pfm/generic_directives/118.snap.ast +10 -0
- package/test/snapshots/pfm/generic_directives/119.snap.ast +9 -0
- package/test/snapshots/pfm/generic_directives/120.snap.ast +12 -0
- package/test/snapshots/pfm/generic_directives/121.snap.ast +3 -0
- package/test/snapshots/pfm/generic_directives/122.snap.ast +3 -0
- package/test/snapshots/pfm/generic_directives/123.snap.ast +3 -0
- package/test/snapshots/pfm/hard_line_breaks/642.snap.ast +1 -1
- package/test/snapshots/pfm/hard_line_breaks/643.snap.ast +1 -1
- package/test/snapshots/pfm/html/148.snap.ast +1 -1
- package/test/snapshots/pfm/html/150.snap.ast +1 -1
- package/test/snapshots/pfm/html/159.snap.ast +2 -3
- package/test/snapshots/pfm/html/162.snap.ast +3 -4
- package/test/snapshots/pfm/html/163.snap.ast +1 -1
- package/test/snapshots/pfm/html/164.snap.ast +3 -4
- package/test/snapshots/pfm/html/166.snap.ast +1 -1
- package/test/snapshots/pfm/html/168.snap.ast +2 -3
- package/test/snapshots/pfm/html/169.snap.ast +5 -7
- package/test/snapshots/pfm/html/174.snap.ast +3 -3
- package/test/snapshots/pfm/html/182.snap.ast +1 -1
- package/test/snapshots/pfm/html/613.snap.ast +2 -2
- package/test/snapshots/pfm/html/615.snap.ast +2 -2
- package/test/snapshots/pfm/images/585.snap.ast +1 -1
- package/test/snapshots/pfm/images/589.snap.ast +1 -1
- package/test/snapshots/pfm/link_reference_definitions/201.snap.ast +1 -1
- package/test/snapshots/pfm/link_reference_definitions/208.snap.ast +1 -1
- package/test/snapshots/pfm/links/491.snap.ast +1 -1
- package/test/snapshots/pfm/links/494.snap.ast +2 -2
- package/test/snapshots/pfm/links/516.snap.ast +8 -9
- package/test/snapshots/pfm/links/521.snap.ast +1 -1
- package/test/snapshots/pfm/links/530.snap.ast +8 -12
- package/test/snapshots/pfm/links/534.snap.ast +1 -1
- package/test/snapshots/pfm/links/552.snap.ast +2 -2
- package/test/snapshots/pfm/links/559.snap.ast +1 -1
- package/test/snapshots/pfm/links/564.snap.ast +1 -1
- package/test/snapshots/pfm/list_items/260.snap.ast +3 -4
- package/test/snapshots/pfm/list_items/293.snap.ast +2 -2
- package/test/snapshots/pfm/tabs/16.snap.ast +2 -3
- package/test/snapshots/pfm/tabs/4.snap.ast +6 -5
- package/test/snapshots/svelte/00-introduction/00-hello-world/App.snap.ast +3 -4
- package/test/snapshots/svelte/00-introduction/02-styling/App.snap.ast +2 -3
- package/test/snapshots/svelte/00-introduction/03-nested-components/App.snap.ast +2 -3
- package/test/snapshots/svelte/00-introduction/03-nested-components/Nested.snap.ast +1 -2
- package/test/snapshots/svelte/00-introduction/04-html-tags/App.snap.ast +1 -2
- package/test/snapshots/svelte/01-reactivity/00-reactive-assignments/App.snap.ast +5 -6
- package/test/snapshots/svelte/01-reactivity/01-reactive-declarations/App.snap.ast +11 -14
- package/test/snapshots/svelte/01-reactivity/02-reactive-statements/App.snap.ast +5 -6
- package/test/snapshots/svelte/02-props/00-declaring-props/Nested.snap.ast +2 -3
- package/test/snapshots/svelte/02-props/01-default-values/App.snap.ast +1 -1
- package/test/snapshots/svelte/02-props/01-default-values/Nested.snap.ast +2 -3
- package/test/snapshots/svelte/02-props/02-spread-props/Info.snap.ast +16 -17
- package/test/snapshots/svelte/03-logic/00-if-blocks/App.snap.ast +4 -8
- package/test/snapshots/svelte/03-logic/01-else-blocks/App.snap.ast +4 -8
- package/test/snapshots/svelte/03-logic/02-else-if-blocks/App.snap.ast +6 -9
- package/test/snapshots/svelte/03-logic/03-each-blocks/App.snap.ast +5 -8
- package/test/snapshots/svelte/03-logic/04-keyed-each-blocks/App.snap.ast +4 -7
- package/test/snapshots/svelte/03-logic/04-keyed-each-blocks/Thing.snap.ast +4 -5
- package/test/snapshots/svelte/04-events/02-event-modifiers/App.snap.ast +2 -3
- package/test/snapshots/svelte/04-events/03-component-events/Inner.snap.ast +2 -3
- package/test/snapshots/svelte/04-events/04-event-forwarding/Inner.snap.ast +2 -3
- package/test/snapshots/svelte/04-events/05-dom-event-forwarding/FancyButton.snap.ast +2 -3
- package/test/snapshots/svelte/05-bindings/00-text-inputs/App.snap.ast +3 -4
- package/test/snapshots/svelte/05-bindings/01-numeric-inputs/App.snap.ast +9 -8
- package/test/snapshots/svelte/05-bindings/02-checkbox-inputs/App.snap.ast +7 -11
- package/test/snapshots/svelte/05-bindings/03-group-inputs/App.snap.ast +21 -30
- package/test/snapshots/svelte/05-bindings/04-textarea-inputs/App.snap.ast +1 -2
- package/test/snapshots/svelte/05-bindings/05-select-bindings/App.snap.ast +5 -9
- package/test/snapshots/svelte/05-bindings/06-multiple-select-bindings/App.snap.ast +18 -26
- package/test/snapshots/svelte/05-bindings/07-each-block-bindings/App.snap.ast +7 -11
- package/test/snapshots/svelte/05-bindings/08-media-elements/App.snap.ast +15 -19
- package/test/snapshots/svelte/05-bindings/09-dimensions/App.snap.ast +7 -9
- package/test/snapshots/svelte/05-bindings/11-component-bindings/App.snap.ast +1 -2
- package/test/snapshots/svelte/05-bindings/11-component-bindings/Keypad.snap.ast +32 -34
- package/test/snapshots/svelte/06-lifecycle/00-onmount/App.snap.ast +3 -6
- package/test/snapshots/svelte/06-lifecycle/01-ondestroy/App.snap.ast +6 -7
- package/test/snapshots/svelte/06-lifecycle/02-update/App.snap.ast +2 -4
- package/test/snapshots/svelte/07-stores/00-writable-stores/App.snap.ast +4 -5
- package/test/snapshots/svelte/07-stores/00-writable-stores/Decrementer.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/00-writable-stores/Incrementer.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/00-writable-stores/Resetter.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/01-auto-subscriptions/App.snap.ast +4 -5
- package/test/snapshots/svelte/07-stores/01-auto-subscriptions/Decrementer.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/01-auto-subscriptions/Incrementer.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/01-auto-subscriptions/Resetter.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/02-readable-stores/App.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/03-derived-stores/App.snap.ast +8 -10
- package/test/snapshots/svelte/07-stores/04-custom-stores/App.snap.ast +7 -11
- package/test/snapshots/svelte/08-motion/00-tweened/App.snap.ast +10 -15
- package/test/snapshots/svelte/08-motion/01-spring/App.snap.ast +10 -10
- package/test/snapshots/svelte/09-transitions/00-transition/App.snap.ast +3 -5
- package/test/snapshots/svelte/09-transitions/01-adding-parameters-to-transitions/App.snap.ast +3 -5
- package/test/snapshots/svelte/09-transitions/02-in-and-out/App.snap.ast +3 -5
- package/test/snapshots/svelte/09-transitions/03-custom-css-transitions/App.snap.ast +4 -6
- package/test/snapshots/svelte/09-transitions/04-custom-js-transitions/App.snap.ast +3 -5
- package/test/snapshots/svelte/09-transitions/05-transition-events/App.snap.ast +5 -8
- package/test/snapshots/svelte/10-animations/00-animate/App.snap.ast +16 -20
- package/test/snapshots/svelte/11-easing/00-easing/App.snap.ast +16 -11
- package/test/snapshots/svelte/11-easing/00-easing/Controls.snap.ast +11 -16
- package/test/snapshots/svelte/11-easing/00-easing/Grid.snap.ast +2 -2
- package/test/snapshots/svelte/12-svg/01-clock/App.snap.ast +2 -1
- package/test/snapshots/svelte/12-svg/02-bar-chart/App.snap.ast +7 -9
- package/test/snapshots/svelte/12-svg/03-area-chart/App.snap.ast +14 -15
- package/test/snapshots/svelte/12-svg/04-scatterplot/App.snap.ast +7 -5
- package/test/snapshots/svelte/12-svg/04-scatterplot/Scatterplot.snap.ast +6 -6
- package/test/snapshots/svelte/12-svg/05-svg-transitions/App.snap.ast +5 -6
- package/test/snapshots/svelte/13-actions/01-adding-parameters-to-actions/App.snap.ast +2 -3
- package/test/snapshots/svelte/14-classes/00-classes/App.snap.ast +3 -6
- package/test/snapshots/svelte/14-classes/01-class-shorthand/App.snap.ast +2 -3
- package/test/snapshots/svelte/15-composition/00-slots/App.snap.ast +3 -5
- package/test/snapshots/svelte/15-composition/01-slot-fallbacks/App.snap.ast +3 -5
- package/test/snapshots/svelte/15-composition/01-slot-fallbacks/Box.snap.ast +1 -2
- package/test/snapshots/svelte/15-composition/02-named-slots/App.snap.ast +7 -11
- package/test/snapshots/svelte/15-composition/02-named-slots/ContactCard.snap.ast +3 -6
- package/test/snapshots/svelte/15-composition/03-slot-props/App.snap.ast +9 -15
- package/test/snapshots/svelte/15-composition/04-modal/App.snap.ast +17 -26
- package/test/snapshots/svelte/15-composition/04-modal/Modal.snap.ast +3 -3
- package/test/snapshots/svelte/16-context/00-context-api/App.snap.ast +10 -5
- package/test/snapshots/svelte/17-special-elements/00-svelte-self/File.snap.ast +1 -2
- package/test/snapshots/svelte/17-special-elements/00-svelte-self/Folder.snap.ast +1 -2
- package/test/snapshots/svelte/17-special-elements/01-svelte-component/App.snap.ast +1 -2
- package/test/snapshots/svelte/17-special-elements/01-svelte-component/BlueThing.snap.ast +1 -2
- package/test/snapshots/svelte/17-special-elements/01-svelte-component/GreenThing.snap.ast +1 -2
- package/test/snapshots/svelte/17-special-elements/01-svelte-component/RedThing.snap.ast +1 -2
- package/test/snapshots/svelte/17-special-elements/02-svelte-window/App.snap.ast +3 -6
- package/test/snapshots/svelte/17-special-elements/03-svelte-window-bindings/App.snap.ast +2 -4
- package/test/snapshots/svelte/17-special-elements/05-svelte-head/App.snap.ast +6 -12
- package/test/snapshots/svelte/18-module-context/01-module-exports/App.snap.ast +2 -3
- package/test/snapshots/svelte/18-module-context/01-module-exports/AudioPlayer.snap.ast +4 -7
- package/test/snapshots/svelte/19-debugging/00-debug/App.snap.ast +5 -7
- package/test/snapshots/svelte/19-debugging/00-debug/Test.snap.ast +7 -11
- package/test/snapshots/svelte/20-7guis/01-7guis-counter/App.snap.ast +2 -3
- package/test/snapshots/svelte/20-7guis/02-7guis-temperature/App.snap.ast +2 -2
- package/test/snapshots/svelte/20-7guis/03-7guis-flight-booker/App.snap.ast +4 -7
- package/test/snapshots/svelte/20-7guis/04-7guis-timer/App.snap.ast +13 -17
- package/test/snapshots/svelte/20-7guis/05-7guis-crud/App.snap.ast +11 -13
- package/test/snapshots/svelte/20-7guis/06-7guis-circles/App.snap.ast +10 -11
- package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/Comment.snap.ast +4 -6
- package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/Item.snap.ast +9 -13
- package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/List.snap.ast +3 -5
- package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/Summary.snap.ast +7 -11
- package/test/snapshots/svelte/21-miscellaneous/02-immutable-data/App.snap.ast +2 -4
- package/test/snapshots/svelte/99-embeds/20181225-blog-svelte-css-in-js/App.snap.ast +6 -7
- package/test/snapshots/svelte/99-embeds/20181225-blog-svelte-css-in-js/Hero.snap.ast +3 -5
- package/test/snapshots/svelte/99-embeds/20190420-blog-write-less-code/App.snap.ast +6 -7
- package/test/svelte_expressions.spec.ts +93 -4
- package/test/svelte_tags.spec.ts +27 -12
- package/test/tables.spec.ts +347 -0
- package/test/tree_builder.spec.ts +286 -1
- package/test/unclosed_delimiters.spec.ts +529 -0
- package/tsc/buf_utils.d.ts +1 -1
- package/tsc/buf_utils.js +9 -9
- package/tsc/cursor.d.ts +17 -13
- package/tsc/cursor.js +60 -43
- package/tsc/main.d.ts +362 -26
- package/tsc/main.js +8955 -4891
- package/tsc/node_view.d.ts +11 -12
- package/tsc/node_view.js +134 -102
- package/tsc/opcodes.d.ts +23 -6
- package/tsc/plugin_dispatch.d.ts +22 -8
- package/tsc/plugin_dispatch.js +292 -170
- package/tsc/tree_builder.d.ts +42 -11
- package/tsc/tree_builder.js +237 -82
- package/tsc/undo_log.d.ts +11 -1
- package/tsc/undo_log.js +54 -19
- package/tsc/utils.d.ts +77 -51
- package/tsc/utils.js +687 -344
- package/tsc/utils.spec.js +83 -9
- package/tsc/wire_emitter.js +6 -0
- package/tsc/wire_tree_builder.d.ts +4 -7
- package/tsc/wire_tree_builder.js +34 -37
- package/dist/node_view-BEh2-H86.js +0 -373
package/src/wire_emitter.ts
CHANGED
|
@@ -78,6 +78,12 @@ const KIND_NAMES: string[] = [
|
|
|
78
78
|
"svelte_tag",
|
|
79
79
|
"svelte_block",
|
|
80
80
|
"svelte_branch",
|
|
81
|
+
"directive_inline",
|
|
82
|
+
"directive_leaf",
|
|
83
|
+
"directive_container",
|
|
84
|
+
"frontmatter",
|
|
85
|
+
"import_statement",
|
|
86
|
+
"directive_label",
|
|
81
87
|
];
|
|
82
88
|
|
|
83
89
|
/** tracks progressive text emission for a node. */
|
package/src/wire_tree_builder.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* WireTreeBuilder, populates a NodeBuffer from wire format batches.
|
|
3
3
|
*
|
|
4
4
|
* client-side counterpart to TreeBuilder. consumes the same json
|
|
5
|
-
* opcode batches that WireEmitter produces and builds the same
|
|
5
|
+
* opcode batches that WireEmitter produces and builds the same
|
|
6
6
|
* NodeBuffer structure. the resulting buffer is walkable by Cursor
|
|
7
7
|
* with identical semantics.
|
|
8
8
|
*
|
|
@@ -17,15 +17,14 @@
|
|
|
17
17
|
* const html = renderCursor(cursor);
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
import { NodeBuffer, NodeKind } from
|
|
21
|
-
import { Cursor } from
|
|
22
|
-
import type { PluginDispatcher } from
|
|
23
|
-
import { WireTextSource } from
|
|
20
|
+
import { NodeBuffer, NodeKind, make_meta, merge_meta } from './utils';
|
|
21
|
+
import { Cursor } from './cursor';
|
|
22
|
+
import type { PluginDispatcher } from './plugin_dispatch';
|
|
23
|
+
import { WireTextSource } from './node_view';
|
|
24
24
|
|
|
25
25
|
const NONE = 0xffffffff;
|
|
26
26
|
|
|
27
27
|
export class WireTreeBuilder {
|
|
28
|
-
/** the soa buffer. */
|
|
29
28
|
private buf: NodeBuffer;
|
|
30
29
|
/** maps wire node id -> buffer index. */
|
|
31
30
|
private id_to_index: number[];
|
|
@@ -34,13 +33,10 @@ export class WireTreeBuilder {
|
|
|
34
33
|
/** optional plugin dispatcher. null when no plugins registered. */
|
|
35
34
|
private dispatcher: PluginDispatcher | null;
|
|
36
35
|
|
|
37
|
-
/** callback for dispatcher to register synthetic node ids. */
|
|
38
|
-
private register_id = (synthetic_id: number, buf_idx: number): void => {
|
|
39
|
-
this.id_to_index[synthetic_id] = buf_idx;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
36
|
constructor(capacity = 128, dispatcher?: PluginDispatcher) {
|
|
43
37
|
this.buf = new NodeBuffer(capacity);
|
|
38
|
+
// this builder writes strings in place and its text source holds the array
|
|
39
|
+
this.buf.own_strings();
|
|
44
40
|
this.id_to_index = [0]; // root id 0 -> buffer index 0
|
|
45
41
|
this.schema = null;
|
|
46
42
|
this.dispatcher = dispatcher ?? null;
|
|
@@ -48,9 +44,7 @@ export class WireTreeBuilder {
|
|
|
48
44
|
// wire mode: point the dispatcher's text source at the buffer's
|
|
49
45
|
// _strings array so NodeView.text_content resolves correctly.
|
|
50
46
|
if (this.dispatcher) {
|
|
51
|
-
this.dispatcher.set_text_source(
|
|
52
|
-
new WireTextSource(this.buf._strings),
|
|
53
|
-
);
|
|
47
|
+
this.dispatcher.set_text_source(new WireTextSource(this.buf._strings));
|
|
54
48
|
}
|
|
55
49
|
}
|
|
56
50
|
|
|
@@ -65,34 +59,34 @@ export class WireTreeBuilder {
|
|
|
65
59
|
for (let i = 0; i < batch.length; i++) {
|
|
66
60
|
const op = batch[i];
|
|
67
61
|
switch (op[0]) {
|
|
68
|
-
case
|
|
62
|
+
case 'S':
|
|
69
63
|
this.schema = op[1] as string[];
|
|
70
64
|
break;
|
|
71
|
-
case
|
|
65
|
+
case 'O':
|
|
72
66
|
this._open(
|
|
73
67
|
op[1] as number,
|
|
74
68
|
op[2] as number,
|
|
75
69
|
op[3] as number,
|
|
76
70
|
(op[4] as number) === 1,
|
|
77
|
-
op[5] as number
|
|
71
|
+
op[5] as number
|
|
78
72
|
);
|
|
79
73
|
break;
|
|
80
|
-
case
|
|
74
|
+
case 'C':
|
|
81
75
|
this._close(op[1] as number);
|
|
82
76
|
break;
|
|
83
|
-
case
|
|
77
|
+
case 'T':
|
|
84
78
|
this._text(op[1] as number, op[2] as string);
|
|
85
79
|
break;
|
|
86
|
-
case
|
|
80
|
+
case 'A':
|
|
87
81
|
this._attr(op[1] as number, op[2] as string, op[3]);
|
|
88
82
|
break;
|
|
89
|
-
case
|
|
83
|
+
case 'R':
|
|
90
84
|
this._revoke(op[1] as number, op[2] as string);
|
|
91
85
|
break;
|
|
92
|
-
case
|
|
86
|
+
case 'K':
|
|
93
87
|
this._commit(op[1] as number);
|
|
94
88
|
break;
|
|
95
|
-
case
|
|
89
|
+
case 'X':
|
|
96
90
|
this._clear(op[1] as number);
|
|
97
91
|
break;
|
|
98
92
|
}
|
|
@@ -101,7 +95,7 @@ export class WireTreeBuilder {
|
|
|
101
95
|
|
|
102
96
|
/** get a cursor over the current buffer state. */
|
|
103
97
|
cursor(): Cursor {
|
|
104
|
-
return new Cursor(this.buf,
|
|
98
|
+
return new Cursor(this.buf, '');
|
|
105
99
|
}
|
|
106
100
|
|
|
107
101
|
/** get the underlying NodeBuffer. */
|
|
@@ -123,13 +117,12 @@ export class WireTreeBuilder {
|
|
|
123
117
|
kind: number,
|
|
124
118
|
parent: number,
|
|
125
119
|
pending: boolean,
|
|
126
|
-
extra: number
|
|
120
|
+
extra: number
|
|
127
121
|
): void {
|
|
128
122
|
// root (id=0) is auto-created by NodeBuffer constructor
|
|
129
123
|
if (id === 0) return;
|
|
130
124
|
|
|
131
|
-
let parent_idx =
|
|
132
|
-
parent === -1 ? NONE : (this.id_to_index[parent] ?? NONE);
|
|
125
|
+
let parent_idx = parent === -1 ? NONE : (this.id_to_index[parent] ?? NONE);
|
|
133
126
|
|
|
134
127
|
// plugin redirect: if parent has a wrap_inner wrapper, children go there
|
|
135
128
|
if (this.dispatcher && parent_idx !== NONE) {
|
|
@@ -144,12 +137,7 @@ export class WireTreeBuilder {
|
|
|
144
137
|
|
|
145
138
|
// plugin dispatch
|
|
146
139
|
if (this.dispatcher && this.dispatcher.has_handlers(kind as NodeKind)) {
|
|
147
|
-
this.dispatcher.dispatch_open(
|
|
148
|
-
idx,
|
|
149
|
-
kind as NodeKind,
|
|
150
|
-
this.buf,
|
|
151
|
-
this.register_id,
|
|
152
|
-
);
|
|
140
|
+
this.dispatcher.dispatch_open(idx, kind as NodeKind, this.buf);
|
|
153
141
|
}
|
|
154
142
|
}
|
|
155
143
|
|
|
@@ -161,7 +149,7 @@ export class WireTreeBuilder {
|
|
|
161
149
|
// capture pending state BEFORE close dispatch / commit.
|
|
162
150
|
// pending nodes may still be revoked after close, so their
|
|
163
151
|
// undo logs must be preserved until explicit commit or revoke.
|
|
164
|
-
const was_pending = this.buf.
|
|
152
|
+
const was_pending = this.buf.pending_at(idx) === 1;
|
|
165
153
|
|
|
166
154
|
// plugin close dispatch
|
|
167
155
|
if (this.dispatcher) {
|
|
@@ -171,13 +159,13 @@ export class WireTreeBuilder {
|
|
|
171
159
|
// pending paragraphs inside list_items are tight-list speculation
|
|
172
160
|
// wrappers, they stay pending after close until the list closes
|
|
173
161
|
// and the parser either revokes (tight) or commits (loose) them.
|
|
174
|
-
const kind = this.buf.
|
|
175
|
-
const parent_kind = this.buf.
|
|
162
|
+
const kind = this.buf.kind_at(idx);
|
|
163
|
+
const parent_kind = this.buf.kind_at(this.buf.parent_at(idx));
|
|
176
164
|
if (
|
|
177
165
|
!(
|
|
178
166
|
kind === NodeKind.paragraph &&
|
|
179
167
|
parent_kind === NodeKind.list_item &&
|
|
180
|
-
this.buf.
|
|
168
|
+
this.buf.pending_at(idx) === 1
|
|
181
169
|
)
|
|
182
170
|
) {
|
|
183
171
|
this.buf.commit_node(idx);
|
|
@@ -193,13 +181,13 @@ export class WireTreeBuilder {
|
|
|
193
181
|
if (kind === NodeKind.list) {
|
|
194
182
|
const meta = this.buf.metadata_at(idx);
|
|
195
183
|
if (meta && meta.tight) {
|
|
196
|
-
let item = this.buf.
|
|
184
|
+
let item = this.buf.first_child_at(idx);
|
|
197
185
|
while (item !== NONE) {
|
|
198
|
-
const next_item = this.buf.
|
|
199
|
-
let child = this.buf.
|
|
186
|
+
const next_item = this.buf.next_at(item);
|
|
187
|
+
let child = this.buf.first_child_at(item);
|
|
200
188
|
while (child !== NONE) {
|
|
201
|
-
const next_child = this.buf.
|
|
202
|
-
if (this.buf.
|
|
189
|
+
const next_child = this.buf.next_at(child);
|
|
190
|
+
if (this.buf.kind_at(child) === NodeKind.paragraph) {
|
|
203
191
|
this.buf.unwrap_node(child);
|
|
204
192
|
}
|
|
205
193
|
child = next_child;
|
|
@@ -220,7 +208,7 @@ export class WireTreeBuilder {
|
|
|
220
208
|
if (redirect !== undefined) idx = redirect;
|
|
221
209
|
}
|
|
222
210
|
|
|
223
|
-
const kind = this.buf.
|
|
211
|
+
const kind = this.buf.kind_at(idx);
|
|
224
212
|
const strings = this.buf._strings;
|
|
225
213
|
|
|
226
214
|
// content leaves: store string directly on the node
|
|
@@ -240,7 +228,7 @@ export class WireTreeBuilder {
|
|
|
240
228
|
// the parser writes value_start/value_end directly on the html node.
|
|
241
229
|
if (kind === NodeKind.html) {
|
|
242
230
|
const meta = this.buf.metadata_at(idx);
|
|
243
|
-
if (meta && (meta.tag ===
|
|
231
|
+
if (meta && (meta.tag === 'script' || meta.tag === 'style')) {
|
|
244
232
|
const existing = strings[idx];
|
|
245
233
|
strings[idx] = existing !== undefined ? existing + content : content;
|
|
246
234
|
return;
|
|
@@ -262,7 +250,7 @@ export class WireTreeBuilder {
|
|
|
262
250
|
|
|
263
251
|
const text_idx = this.buf.push(NodeKind.text, 0, idx);
|
|
264
252
|
strings[text_idx] = content;
|
|
265
|
-
this.buf.
|
|
253
|
+
this.buf.set_end(text_idx, 1);
|
|
266
254
|
}
|
|
267
255
|
|
|
268
256
|
/**
|
|
@@ -271,15 +259,15 @@ export class WireTreeBuilder {
|
|
|
271
259
|
* and _clear (discard in-progress text).
|
|
272
260
|
*/
|
|
273
261
|
private _last_text_child(idx: number): number {
|
|
274
|
-
let child = this.buf.
|
|
262
|
+
let child = this.buf.first_child_at(idx);
|
|
275
263
|
if (child === NONE) return NONE;
|
|
276
264
|
let last = child;
|
|
277
265
|
while (true) {
|
|
278
|
-
const next = this.buf.
|
|
279
|
-
if (next === NONE || this.buf.
|
|
266
|
+
const next = this.buf.next_at(last);
|
|
267
|
+
if (next === NONE || this.buf.parent_at(next) !== idx) break;
|
|
280
268
|
last = next;
|
|
281
269
|
}
|
|
282
|
-
return this.buf.
|
|
270
|
+
return this.buf.kind_at(last) === NodeKind.text ? last : NONE;
|
|
283
271
|
}
|
|
284
272
|
|
|
285
273
|
private _attr(id: number, key: string, value: unknown): void {
|
|
@@ -288,10 +276,9 @@ export class WireTreeBuilder {
|
|
|
288
276
|
|
|
289
277
|
const existing = this.buf.metadata_at(idx);
|
|
290
278
|
if (existing) {
|
|
291
|
-
existing
|
|
292
|
-
this.buf.set_metadata(idx, existing);
|
|
279
|
+
merge_meta(existing, key, value);
|
|
293
280
|
} else {
|
|
294
|
-
this.buf.set_metadata(idx,
|
|
281
|
+
this.buf.set_metadata(idx, make_meta(key, value));
|
|
295
282
|
}
|
|
296
283
|
}
|
|
297
284
|
|
|
@@ -353,11 +353,7 @@ describe('Block quotes', () => {
|
|
|
353
353
|
// >>> foo
|
|
354
354
|
// > bar
|
|
355
355
|
// >>baz
|
|
356
|
-
//
|
|
357
|
-
// a shorter marker count on a continuation line does NOT close outer
|
|
358
|
-
// frames, it just opens a new paragraph inside the innermost. A
|
|
359
|
-
// future revision may change this, but it is out of scope for the
|
|
360
|
-
// no-lazy-continuation change.
|
|
356
|
+
// no lazy continuation, bar closes the inner quotes and baz opens a new one
|
|
361
357
|
const input = load_fixture('251');
|
|
362
358
|
const { nodes } = parse_markdown_svelte(input);
|
|
363
359
|
const children = non_breaks(nodes);
|
|
@@ -366,8 +362,58 @@ describe('Block quotes', () => {
|
|
|
366
362
|
expect(children[0].kind).toBe('block_quote');
|
|
367
363
|
|
|
368
364
|
const bq1_children = non_breaks(nodes, children[0].index);
|
|
369
|
-
expect(bq1_children.
|
|
370
|
-
|
|
365
|
+
expect(bq1_children.map((n) => n.kind)).toEqual([
|
|
366
|
+
'block_quote',
|
|
367
|
+
'paragraph',
|
|
368
|
+
'block_quote',
|
|
369
|
+
]);
|
|
370
|
+
|
|
371
|
+
const bq2_children = non_breaks(nodes, bq1_children[0].index);
|
|
372
|
+
expect(bq2_children.length).toBe(1);
|
|
373
|
+
expect(bq2_children[0].kind).toBe('block_quote');
|
|
374
|
+
|
|
375
|
+
const baz = non_breaks(nodes, bq1_children[2].index);
|
|
376
|
+
expect(baz.length).toBe(1);
|
|
377
|
+
expect(baz[0].kind).toBe('paragraph');
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
test('pfm: leaf block inside nested quote keeps following line at depth', () => {
|
|
381
|
+
const input = '> > # h\n> > x';
|
|
382
|
+
const { nodes } = parse_markdown_svelte(input);
|
|
383
|
+
const bq1 = non_breaks(nodes);
|
|
384
|
+
expect(bq1.map((n) => n.kind)).toEqual(['block_quote']);
|
|
385
|
+
const bq2 = non_breaks(nodes, bq1[0].index);
|
|
386
|
+
expect(bq2.map((n) => n.kind)).toEqual(['block_quote']);
|
|
387
|
+
const inner = non_breaks(nodes, bq2[0].index);
|
|
388
|
+
expect(inner.map((n) => n.kind)).toEqual(['heading', 'paragraph']);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
test('pfm: blank quoted line inside compact nested quote keeps depth', () => {
|
|
392
|
+
const input = '>> b\n>>\n>> c';
|
|
393
|
+
const { nodes } = parse_markdown_svelte(input);
|
|
394
|
+
const bq1 = non_breaks(nodes);
|
|
395
|
+
const bq2 = non_breaks(nodes, bq1[0].index);
|
|
396
|
+
expect(bq2.map((n) => n.kind)).toEqual(['block_quote']);
|
|
397
|
+
const inner = non_breaks(nodes, bq2[0].index);
|
|
398
|
+
expect(inner.map((n) => n.kind)).toEqual(['paragraph', 'paragraph']);
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
test('pfm: fewer markers after a leaf block close the inner quote', () => {
|
|
402
|
+
const input = '> > # h\n> c';
|
|
403
|
+
const { nodes } = parse_markdown_svelte(input);
|
|
404
|
+
const bq1 = non_breaks(nodes);
|
|
405
|
+
const outer = non_breaks(nodes, bq1[0].index);
|
|
406
|
+
expect(outer.map((n) => n.kind)).toEqual(['block_quote', 'paragraph']);
|
|
407
|
+
const inner = non_breaks(nodes, outer[0].index);
|
|
408
|
+
expect(inner.map((n) => n.kind)).toEqual(['heading']);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
test('pfm: extra marker interrupts a paragraph inside a quote', () => {
|
|
412
|
+
const input = '> bar\n>> baz';
|
|
413
|
+
const { nodes } = parse_markdown_svelte(input);
|
|
414
|
+
const bq1 = non_breaks(nodes);
|
|
415
|
+
const outer = non_breaks(nodes, bq1[0].index);
|
|
416
|
+
expect(outer.map((n) => n.kind)).toEqual(['paragraph', 'block_quote']);
|
|
371
417
|
});
|
|
372
418
|
|
|
373
419
|
test('pfm: code fence opener without > continuation is paragraph text', () => {
|
|
@@ -412,6 +458,31 @@ describe('Block quotes', () => {
|
|
|
412
458
|
expect(bq_children[0].kind).toBe('code_fence');
|
|
413
459
|
});
|
|
414
460
|
|
|
461
|
+
test('pfm: code fence closes on a quoted closing line, its value keeps the markers', () => {
|
|
462
|
+
const input = '> ```\n> code\n> ```\n> after\n';
|
|
463
|
+
const { nodes } = parse_markdown_svelte(input);
|
|
464
|
+
const children = non_breaks(nodes);
|
|
465
|
+
expect(children.length).toBe(1);
|
|
466
|
+
|
|
467
|
+
const bq_children = non_breaks(nodes, children[0].index);
|
|
468
|
+
expect(bq_children.map((n) => n.kind)).toEqual(['code_fence', 'paragraph']);
|
|
469
|
+
expect(get_value(nodes, bq_children[0].index, input)).toBe('> code');
|
|
470
|
+
const text = nodes.get_node(bq_children[1].children[0]);
|
|
471
|
+
expect(get_value(nodes, text.index, input)).toBe('after');
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
test('pfm: code fence in a nested blockquote closes on its markers', () => {
|
|
475
|
+
const input = '> > ```\n> > a\n> > ```\n';
|
|
476
|
+
const { nodes } = parse_markdown_svelte(input);
|
|
477
|
+
const outer = non_breaks(nodes)[0];
|
|
478
|
+
const inner = non_breaks(nodes, outer.index)[0];
|
|
479
|
+
expect(inner.kind).toBe('block_quote');
|
|
480
|
+
|
|
481
|
+
const fence = non_breaks(nodes, inner.index);
|
|
482
|
+
expect(fence.map((n) => n.kind)).toEqual(['code_fence']);
|
|
483
|
+
expect(get_value(nodes, fence[0].index, input)).toBe('> > a');
|
|
484
|
+
});
|
|
485
|
+
|
|
415
486
|
test('pfm: cascade close through nested blockquotes then resume', () => {
|
|
416
487
|
// > > foo
|
|
417
488
|
// bar
|
package/test/code_spans.spec.ts
CHANGED
|
@@ -4,8 +4,10 @@ import { fileURLToPath } from 'node:url';
|
|
|
4
4
|
|
|
5
5
|
import { describe, expect, test } from 'vitest';
|
|
6
6
|
|
|
7
|
-
import { parse_markdown_svelte } from '../src/main';
|
|
7
|
+
import { PFMParser, parse_markdown_svelte } from '../src/main';
|
|
8
|
+
import { TreeBuilder } from '../src/tree_builder';
|
|
8
9
|
import { NodeKind } from '../src/utils';
|
|
10
|
+
import { print_ast } from './print';
|
|
9
11
|
|
|
10
12
|
const this_dir = dirname(fileURLToPath(import.meta.url));
|
|
11
13
|
const fixtures_root = resolve(this_dir, 'fixtures/pfm/code_spans');
|
|
@@ -473,9 +475,11 @@ describe('code spans', () => {
|
|
|
473
475
|
.map((i: number) => nodes.get_node(i))
|
|
474
476
|
.filter((n: any) => n.kind !== 'line_break');
|
|
475
477
|
|
|
476
|
-
expect(children.length).
|
|
477
|
-
expect(children[0].kind).toBe('
|
|
478
|
-
expect(
|
|
478
|
+
expect(children.length).toBe(1);
|
|
479
|
+
expect(children[0].kind).toBe('paragraph');
|
|
480
|
+
expect(
|
|
481
|
+
children[0].children.map((i: number) => nodes.get_node(i).kind)
|
|
482
|
+
).toEqual(['html', 'text']);
|
|
479
483
|
});
|
|
480
484
|
|
|
481
485
|
// Autolink with backtick
|
|
@@ -507,9 +511,9 @@ describe('code spans', () => {
|
|
|
507
511
|
|
|
508
512
|
const code_fence = nodes.get_node(root.children[0]);
|
|
509
513
|
|
|
510
|
-
|
|
511
|
-
expect(nodes.size).toBe(3);
|
|
514
|
+
expect(nodes.size).toBe(2);
|
|
512
515
|
expect(code_fence.kind).toBe('code_fence');
|
|
516
|
+
expect(code_fence.value).toEqual([input.length, input.length]);
|
|
513
517
|
});
|
|
514
518
|
|
|
515
519
|
test('pfm example 348', () => {
|
|
@@ -707,4 +711,152 @@ describe('code spans', () => {
|
|
|
707
711
|
expect(paragraph_kinds.length).toBe(1);
|
|
708
712
|
expect(code_span_kinds.length).toBe(1);
|
|
709
713
|
});
|
|
714
|
+
|
|
715
|
+
const hint_cases: [string, [string, string | undefined][]][] = [
|
|
716
|
+
['pfm_328_5', [['#!ts', undefined]]],
|
|
717
|
+
['pfm_328_6', [['#!', undefined]]],
|
|
718
|
+
['pfm_328_7', [['#!ts ', undefined]]],
|
|
719
|
+
[
|
|
720
|
+
'pfm_328_8',
|
|
721
|
+
[
|
|
722
|
+
['#!ts', undefined],
|
|
723
|
+
['c', 'js'],
|
|
724
|
+
],
|
|
725
|
+
],
|
|
726
|
+
[
|
|
727
|
+
'pfm_328_9',
|
|
728
|
+
[
|
|
729
|
+
['#!', undefined],
|
|
730
|
+
['d', undefined],
|
|
731
|
+
],
|
|
732
|
+
],
|
|
733
|
+
];
|
|
734
|
+
|
|
735
|
+
for (const [id, expected] of hint_cases) {
|
|
736
|
+
test(`pfm example ${id} keeps a bare #! as code`, () => {
|
|
737
|
+
const input = load_fixture(id);
|
|
738
|
+
const { nodes } = parse_markdown_svelte(input);
|
|
739
|
+
const spans = nodes
|
|
740
|
+
.get_kinds(NodeKind.code_span)
|
|
741
|
+
.map((i) => nodes.get_node(i));
|
|
742
|
+
|
|
743
|
+
expect(
|
|
744
|
+
spans.map((s) => {
|
|
745
|
+
const { info_start, info_end } = s.metadata ?? {};
|
|
746
|
+
return [
|
|
747
|
+
input.slice(s.value[0], s.value[1]),
|
|
748
|
+
info_start === undefined
|
|
749
|
+
? undefined
|
|
750
|
+
: input.slice(info_start, info_end),
|
|
751
|
+
];
|
|
752
|
+
})
|
|
753
|
+
).toEqual(expected);
|
|
754
|
+
for (const s of spans) {
|
|
755
|
+
const text = input.slice(s.start, s.end);
|
|
756
|
+
expect(text.startsWith('`') && text.endsWith('`')).toBe(true);
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
describe('unmatched code spans', () => {
|
|
763
|
+
const print_batch = (input: string): string =>
|
|
764
|
+
print_ast(parse_markdown_svelte(input).nodes, input);
|
|
765
|
+
|
|
766
|
+
const print_incremental = (input: string, chunk_size: number): string => {
|
|
767
|
+
const tree = new TreeBuilder(input.length);
|
|
768
|
+
const parser = new PFMParser(tree);
|
|
769
|
+
parser.init();
|
|
770
|
+
for (let i = 0; i < input.length; i += chunk_size) {
|
|
771
|
+
parser.feed(input.slice(i, i + chunk_size));
|
|
772
|
+
}
|
|
773
|
+
parser.finish();
|
|
774
|
+
return print_ast(tree.get_buffer(), input);
|
|
775
|
+
};
|
|
776
|
+
|
|
777
|
+
const cases: [string, string][] = [
|
|
778
|
+
[
|
|
779
|
+
'a``\n\nx',
|
|
780
|
+
'root\n paragraph\n text "a"\n text "``"\n line_break\n line_break\n paragraph\n text "x"',
|
|
781
|
+
],
|
|
782
|
+
[
|
|
783
|
+
'a``\nx',
|
|
784
|
+
'root\n paragraph\n text "a"\n text "``"\n soft_break\n text "x"',
|
|
785
|
+
],
|
|
786
|
+
['a``', 'root\n paragraph\n text "a"\n text "``"'],
|
|
787
|
+
['a```', 'root\n paragraph\n text "a"\n text "```"'],
|
|
788
|
+
[
|
|
789
|
+
'a`` b\n\nx',
|
|
790
|
+
'root\n paragraph\n text "a"\n text "``"\n text " b"\n line_break\n line_break\n paragraph\n text "x"',
|
|
791
|
+
],
|
|
792
|
+
['x ` c', 'root\n paragraph\n text "x "\n text "`"\n text " c"'],
|
|
793
|
+
[
|
|
794
|
+
'a ` \n\nb `',
|
|
795
|
+
'root\n paragraph\n text "a "\n text "`"\n text " "\n line_break\n line_break\n paragraph\n text "b "\n text "`"',
|
|
796
|
+
],
|
|
797
|
+
[
|
|
798
|
+
'a ``b` c',
|
|
799
|
+
'root\n paragraph\n text "a "\n text "``"\n text "b"\n text "`"\n text " c"',
|
|
800
|
+
],
|
|
801
|
+
[
|
|
802
|
+
'a `#!ts',
|
|
803
|
+
'root\n paragraph\n text "a "\n text "`"\n text "#"\n text "!ts"',
|
|
804
|
+
],
|
|
805
|
+
[
|
|
806
|
+
'a `#!',
|
|
807
|
+
'root\n paragraph\n text "a "\n text "`"\n text "#"\n text "!"',
|
|
808
|
+
],
|
|
809
|
+
[
|
|
810
|
+
'a `#!ts\n\nx',
|
|
811
|
+
'root\n paragraph\n text "a "\n text "`"\n text "#"\n text "!ts"\n line_break\n line_break\n paragraph\n text "x"',
|
|
812
|
+
],
|
|
813
|
+
];
|
|
814
|
+
|
|
815
|
+
for (const [input, expected] of cases) {
|
|
816
|
+
test(`keeps backticks literal: ${JSON.stringify(input)}`, () => {
|
|
817
|
+
expect(print_batch(input)).toBe(expected);
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
test(`incremental matches batch: ${JSON.stringify(input)}`, () => {
|
|
821
|
+
for (let size = 1; size <= 8; size++) {
|
|
822
|
+
expect(print_incremental(input, size), `chunk size ${size}`).toBe(
|
|
823
|
+
expected
|
|
824
|
+
);
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
describe('code spans wrapped in delimiters', () => {
|
|
831
|
+
const print_incremental = (input: string, chunk_size: number): string => {
|
|
832
|
+
const tree = new TreeBuilder(input.length);
|
|
833
|
+
const parser = new PFMParser(tree);
|
|
834
|
+
parser.init();
|
|
835
|
+
for (let i = 0; i < input.length; i += chunk_size) {
|
|
836
|
+
parser.feed(input.slice(i, i + chunk_size));
|
|
837
|
+
}
|
|
838
|
+
parser.finish();
|
|
839
|
+
return print_ast(tree.get_buffer(), input);
|
|
840
|
+
};
|
|
841
|
+
|
|
842
|
+
const cases: [string, string][] = [
|
|
843
|
+
[
|
|
844
|
+
'*`x`* b',
|
|
845
|
+
'root\n paragraph\n strong_emphasis\n code_span "x"\n text " b"',
|
|
846
|
+
],
|
|
847
|
+
['_`` x ``_', 'root\n paragraph\n emphasis\n code_span "x"'],
|
|
848
|
+
];
|
|
849
|
+
|
|
850
|
+
for (const [input, expected] of cases) {
|
|
851
|
+
test(`closes after the code span: ${JSON.stringify(input)}`, () => {
|
|
852
|
+
expect(print_ast(parse_markdown_svelte(input).nodes, input)).toBe(
|
|
853
|
+
expected
|
|
854
|
+
);
|
|
855
|
+
for (let size = 1; size <= 8; size++) {
|
|
856
|
+
expect(print_incremental(input, size), `chunk size ${size}`).toBe(
|
|
857
|
+
expected
|
|
858
|
+
);
|
|
859
|
+
}
|
|
860
|
+
});
|
|
861
|
+
}
|
|
710
862
|
});
|
package/test/crlf.spec.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { describe, expect, test } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
normalize_newlines,
|
|
5
|
+
parse_markdown_svelte,
|
|
6
|
+
PFMParser,
|
|
7
|
+
raw_offsets,
|
|
8
|
+
} from '../src/main';
|
|
4
9
|
import { TreeBuilder } from '../src/tree_builder';
|
|
10
|
+
import { print_ast } from './print';
|
|
5
11
|
|
|
6
12
|
describe('line ending normalization', () => {
|
|
7
13
|
describe('batch mode', () => {
|
|
@@ -121,5 +127,47 @@ describe('line ending normalization', () => {
|
|
|
121
127
|
p.finish();
|
|
122
128
|
expect(get_source(p)).toBe('abc\ndef');
|
|
123
129
|
});
|
|
130
|
+
|
|
131
|
+
for (const input of ['~~~\r', 'a *\r', '{a} *~*\r', '- ~~~\r']) {
|
|
132
|
+
test(`a trailing lone \\r in ${JSON.stringify(input)} parses as in batch mode`, () => {
|
|
133
|
+
const tree = new TreeBuilder(128);
|
|
134
|
+
const p = new PFMParser(tree);
|
|
135
|
+
p.init();
|
|
136
|
+
p.feed(input);
|
|
137
|
+
p.finish();
|
|
138
|
+
const batch = parse_markdown_svelte(input);
|
|
139
|
+
expect(print_ast(tree.get_buffer(), get_source(p))).toBe(
|
|
140
|
+
print_ast(batch.nodes, batch.source)
|
|
141
|
+
);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe('raw_offsets', () => {
|
|
148
|
+
test('returns null when there is no \\r\\n', () => {
|
|
149
|
+
expect(raw_offsets('a\nb')).toBe(null);
|
|
150
|
+
expect(raw_offsets('a\rb')).toBe(null);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('maps every normalized offset to the same character in raw', () => {
|
|
154
|
+
const raw = 'ab\r\ncd\r\n\r\ne\rf\ng\r\n';
|
|
155
|
+
const normalized = normalize_newlines(raw);
|
|
156
|
+
const offsets = raw_offsets(raw)!;
|
|
157
|
+
expect(offsets.collapsed).toEqual([2, 5, 6, 12]);
|
|
158
|
+
for (let i = 0; i < normalized.length; i++) {
|
|
159
|
+
const r = offsets.to_raw(i);
|
|
160
|
+
// a collapsed \n maps to the \r that started its \r\n
|
|
161
|
+
const char = raw[r] === '\r' ? '\n' : raw[r];
|
|
162
|
+
expect(char, `offset ${i}`).toBe(normalized[i]);
|
|
163
|
+
}
|
|
164
|
+
expect(offsets.to_raw(normalized.length)).toBe(raw.length);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('a range spanning a \\r\\n grows by one in raw', () => {
|
|
168
|
+
const raw = 'a\r\nb';
|
|
169
|
+
const offsets = raw_offsets(raw)!;
|
|
170
|
+
expect(raw.slice(offsets.to_raw(0), offsets.to_raw(3))).toBe(raw);
|
|
171
|
+
expect(raw.slice(offsets.to_raw(0), offsets.to_raw(1))).toBe('a');
|
|
124
172
|
});
|
|
125
173
|
});
|