@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/test/incremental.spec.ts
CHANGED
|
@@ -168,6 +168,24 @@ describe('Incremental parsing', () => {
|
|
|
168
168
|
expect(closes2.some((o) => (o as any).id === fence_open.id)).toBe(true);
|
|
169
169
|
});
|
|
170
170
|
|
|
171
|
+
it('raw text element opens once its open tag is complete', () => {
|
|
172
|
+
const rec = new OpRecorder();
|
|
173
|
+
const p = new PFMParser(rec);
|
|
174
|
+
p.init();
|
|
175
|
+
p.feed('<style>\n.a { color: red }\n</sty');
|
|
176
|
+
const html_open = rec.ops.find(
|
|
177
|
+
(o) => o.op === 'open' && o.kind === 'html'
|
|
178
|
+
) as any;
|
|
179
|
+
expect(html_open).toBeDefined();
|
|
180
|
+
expect(html_open.pending).toBe(false);
|
|
181
|
+
const closed = () =>
|
|
182
|
+
rec.ops.some((o) => o.op === 'close' && o.id === html_open.id);
|
|
183
|
+
expect(closed()).toBe(false);
|
|
184
|
+
|
|
185
|
+
p.feed('le>\n');
|
|
186
|
+
expect(closed()).toBe(true);
|
|
187
|
+
});
|
|
188
|
+
|
|
171
189
|
it('revokes unclosed emphasis on finish', () => {
|
|
172
190
|
const rec = new OpRecorder();
|
|
173
191
|
const p = new PFMParser(rec);
|
|
@@ -260,6 +278,21 @@ describe('Incremental parsing', () => {
|
|
|
260
278
|
}
|
|
261
279
|
});
|
|
262
280
|
|
|
281
|
+
describe('code span failed by a blank line across a chunk boundary', () => {
|
|
282
|
+
for (const input of ['`a\n\nb`', '`a\n \nb`', '`` a\n\nb``']) {
|
|
283
|
+
for (const size of [1, 2, 3, 4]) {
|
|
284
|
+
it(`${JSON.stringify(input)} chunk size ${size}`, () => {
|
|
285
|
+
const batch = parse_batch(input);
|
|
286
|
+
expect(
|
|
287
|
+
batch.get_node(0).children.map((i) => batch.get_node(i).kind)
|
|
288
|
+
).toEqual(['paragraph', 'line_break', 'line_break', 'paragraph']);
|
|
289
|
+
const diffs = tree_diff(batch, parse_incremental(input, size), input);
|
|
290
|
+
expect(diffs).toEqual([]);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
|
|
263
296
|
describe('fixture equivalence (char-by-char)', () => {
|
|
264
297
|
const fixturesDir = path.resolve(__dirname, 'fixtures/pfm');
|
|
265
298
|
const categories = fs
|
|
@@ -336,6 +369,14 @@ describe('Incremental parsing', () => {
|
|
|
336
369
|
'mixed doc',
|
|
337
370
|
'# Title\n\n<div class="note">\n\nSome *text* here.\n\n</div>\n\nAfter.\n',
|
|
338
371
|
],
|
|
372
|
+
['block script', '<script>\nlet a = 1 > 0;\n</script>\n\nafter\n'],
|
|
373
|
+
['inline style', 'text <style>a > b {}</style> end\n'],
|
|
374
|
+
['unterminated block script', 'text\n\n<script>\nlet a = 1;\n'],
|
|
375
|
+
['unterminated inline style', 'a <style>b {}\n'],
|
|
376
|
+
['script in html block', '<div>\n<script>\nfoo()\n</script>\n</div>\n'],
|
|
377
|
+
['style in svelte block', '{#if a}\n<style>\nb {}\n</style>\n{/if}\n'],
|
|
378
|
+
['style in block quote', '> <style>\n> a {}\n> </style>\n'],
|
|
379
|
+
['close tag lookalike', '<script>"</scrip" + "t>";</script>\n'],
|
|
339
380
|
];
|
|
340
381
|
|
|
341
382
|
for (const [name, input] of html_cases) {
|
|
@@ -463,6 +504,65 @@ describe('directive incremental behavior', () => {
|
|
|
463
504
|
expect(closes_for(rec, box.id).length).toBe(1);
|
|
464
505
|
});
|
|
465
506
|
|
|
507
|
+
it('container body starts a list, the fence closes it before the container', () => {
|
|
508
|
+
const rec = new OpRecorder();
|
|
509
|
+
const p = new PFMParser(rec);
|
|
510
|
+
p.init();
|
|
511
|
+
|
|
512
|
+
p.feed(':::note[]\n- a');
|
|
513
|
+
const list = opens_of(rec, 'list')[0];
|
|
514
|
+
const box = opens_of(rec, 'directive_container')[0];
|
|
515
|
+
// a tight item paragraph stays pending, as at the root
|
|
516
|
+
expect(
|
|
517
|
+
rec.ops
|
|
518
|
+
.filter((o) => o.op === 'open')
|
|
519
|
+
.map((o) => (o as any).kind + ((o as any).pending ? '?' : ''))
|
|
520
|
+
).toEqual([
|
|
521
|
+
'root',
|
|
522
|
+
'directive_container',
|
|
523
|
+
'list',
|
|
524
|
+
'list_item',
|
|
525
|
+
'paragraph?',
|
|
526
|
+
'text',
|
|
527
|
+
]);
|
|
528
|
+
|
|
529
|
+
p.feed('\n- b\n');
|
|
530
|
+
expect(opens_of(rec, 'list_item').length).toBe(2);
|
|
531
|
+
expect(closes_for(rec, list.id).length).toBe(0);
|
|
532
|
+
|
|
533
|
+
p.feed(':::\n');
|
|
534
|
+
const close_ids = rec.ops
|
|
535
|
+
.filter((o) => o.op === 'close')
|
|
536
|
+
.map((o) => (o as any).id);
|
|
537
|
+
const list_close = close_ids.indexOf(list.id);
|
|
538
|
+
expect(list_close).toBeGreaterThanOrEqual(0);
|
|
539
|
+
expect(close_ids.indexOf(box.id)).toBeGreaterThan(list_close);
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
describe('lists in containers match batch at every chunk size', () => {
|
|
543
|
+
const cases: [string, string][] = [
|
|
544
|
+
['bullet', ':::note[]\n- a\n- b\n:::\n'],
|
|
545
|
+
['plus', ':::note[]\n+ a\n+ b\n:::\n'],
|
|
546
|
+
['ordered', ':::note[]\n10. a\n11. b\n:::\n'],
|
|
547
|
+
['task', ':::note[]\n- [ ] a\n- [x] b\n:::\n'],
|
|
548
|
+
['nested', ':::note[]\n- a\n 1. b\n- c\n:::\nafter\n'],
|
|
549
|
+
['loose', ':::note[]\n- a\n\n- b\n:::\n'],
|
|
550
|
+
['after paragraph', ':::note[]\nintro\n- a\n:::\n'],
|
|
551
|
+
['thematic break', ':::note[]\n- - -\n:::\n'],
|
|
552
|
+
['no fence', ':::note[]\n- a\n- b'],
|
|
553
|
+
['nested containers', '::::o[]\n:::i[]\n- a\n:::\n2. b\n::::\n'],
|
|
554
|
+
];
|
|
555
|
+
for (const [name, input] of cases) {
|
|
556
|
+
for (const size of [1, 2, 3, 5, 8]) {
|
|
557
|
+
it(`${name} chunk size ${size}`, () => {
|
|
558
|
+
const batch = parse_batch(input);
|
|
559
|
+
const diffs = tree_diff(batch, parse_incremental(input, size), input);
|
|
560
|
+
expect(diffs).toEqual([]);
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
|
|
466
566
|
it('revokes an unclosed directive at a paragraph boundary', () => {
|
|
467
567
|
const rec = new OpRecorder();
|
|
468
568
|
const p = new PFMParser(rec);
|
|
@@ -477,3 +577,174 @@ describe('directive incremental behavior', () => {
|
|
|
477
577
|
expect(revokes.length).toBeGreaterThan(0);
|
|
478
578
|
});
|
|
479
579
|
});
|
|
580
|
+
|
|
581
|
+
describe('retained source window', () => {
|
|
582
|
+
const lines = (n: number, f: (i: number) => string) =>
|
|
583
|
+
Array.from({ length: n }, (_, i) => f(i)).join('\n') + '\n';
|
|
584
|
+
const cases: [string, string][] = [
|
|
585
|
+
[
|
|
586
|
+
'code fence',
|
|
587
|
+
'```js\n' + lines(2000, (i) => `const x${i} = ${i};`) + '```\n',
|
|
588
|
+
],
|
|
589
|
+
['tight list', lines(2000, (i) => `- item ${i} *em*`)],
|
|
590
|
+
['loose list', lines(2000, (i) => (i % 2 ? '' : `- item ${i}`))],
|
|
591
|
+
[
|
|
592
|
+
'nested list',
|
|
593
|
+
lines(2000, (i) => (i % 3 ? ` - sub ${i}` : `- item ${i}`)),
|
|
594
|
+
],
|
|
595
|
+
['block quote', lines(2000, (i) => (i % 2 ? '>' : `> quote ${i}`))],
|
|
596
|
+
['list in block quote', lines(2000, (i) => `> - item ${i}`)],
|
|
597
|
+
[
|
|
598
|
+
'style block',
|
|
599
|
+
'<style>\n' +
|
|
600
|
+
lines(2000, (i) => `.c${i} > a { color: red }`) +
|
|
601
|
+
'</style>\n',
|
|
602
|
+
],
|
|
603
|
+
[
|
|
604
|
+
'script after blocks',
|
|
605
|
+
'# title\n\n- a\n\n<script>\n' +
|
|
606
|
+
lines(2000, (i) => `let x${i} = ${i} > 0;`) +
|
|
607
|
+
'</script>\n\nafter\n',
|
|
608
|
+
],
|
|
609
|
+
[
|
|
610
|
+
'fence in list',
|
|
611
|
+
'- item\n ```\n' + lines(2000, (i) => ` code ${i}`) + ' ```\n',
|
|
612
|
+
],
|
|
613
|
+
];
|
|
614
|
+
|
|
615
|
+
for (const [name, source] of cases) {
|
|
616
|
+
it(`${name} stays bounded and matches batch`, () => {
|
|
617
|
+
const tree = new TreeBuilder(source.length);
|
|
618
|
+
const parser = new PFMParser(tree);
|
|
619
|
+
parser.init();
|
|
620
|
+
let max_window = 0;
|
|
621
|
+
for (let i = 0; i < source.length; i += 64) {
|
|
622
|
+
parser.feed(source.slice(i, i + 64));
|
|
623
|
+
max_window = Math.max(max_window, (parser as any).source.length);
|
|
624
|
+
}
|
|
625
|
+
parser.finish();
|
|
626
|
+
expect(max_window).toBeLessThan(512);
|
|
627
|
+
expect(tree_diff(parse_batch(source), tree.get_buffer(), source)).toEqual(
|
|
628
|
+
[]
|
|
629
|
+
);
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
describe('feeds skipped while a fence or raw text block waits for its close', () => {
|
|
635
|
+
const body = (n: number, f: (i: number) => string) =>
|
|
636
|
+
Array.from({ length: n }, (_, i) => f(i)).join('\n') + '\n';
|
|
637
|
+
const cases: [string, string][] = [
|
|
638
|
+
[
|
|
639
|
+
'fence',
|
|
640
|
+
'```js\n' + body(40, (i) => `const x${i} = ${i};`) + '```\n\nafter\n',
|
|
641
|
+
],
|
|
642
|
+
[
|
|
643
|
+
'fence with short backtick runs',
|
|
644
|
+
'````\n' +
|
|
645
|
+
body(30, (i) => (i % 5 ? `line ${i}` : '```')) +
|
|
646
|
+
' ``\n `\n````\nafter\n',
|
|
647
|
+
],
|
|
648
|
+
[
|
|
649
|
+
'fence with indented close',
|
|
650
|
+
'```\n' + body(30, (i) => ` code ${i}`) + ' ```\n\nafter\n',
|
|
651
|
+
],
|
|
652
|
+
[
|
|
653
|
+
'fence in list',
|
|
654
|
+
'- item\n ```\n' + body(30, (i) => ` c ${i}`) + ' ```\n- b\n',
|
|
655
|
+
],
|
|
656
|
+
[
|
|
657
|
+
'fence in block quote',
|
|
658
|
+
'> ```\n' + body(30, (i) => `> c ${i}`) + '> ```\n',
|
|
659
|
+
],
|
|
660
|
+
['unclosed fence', '```\n' + body(30, (i) => `c ${i}`)],
|
|
661
|
+
[
|
|
662
|
+
'fence with blank lines',
|
|
663
|
+
'```\n' + body(30, (i) => (i % 3 ? `c ${i}` : '')) + '```\n',
|
|
664
|
+
],
|
|
665
|
+
[
|
|
666
|
+
'script',
|
|
667
|
+
'<script>\n' +
|
|
668
|
+
body(30, (i) => `let x${i} = ${i} > 0;`) +
|
|
669
|
+
'</script>\n\nafter\n',
|
|
670
|
+
],
|
|
671
|
+
[
|
|
672
|
+
'script with a less than',
|
|
673
|
+
'<script>\n' +
|
|
674
|
+
body(30, (i) => (i % 4 ? `let x${i} = ${i};` : `if (a < ${i}) b();`)) +
|
|
675
|
+
'</scr\n</script>\nafter\n',
|
|
676
|
+
],
|
|
677
|
+
[
|
|
678
|
+
'style',
|
|
679
|
+
'<style>\n' + body(30, (i) => `.c${i} > a { color: red }`) + '</style>\n',
|
|
680
|
+
],
|
|
681
|
+
['unclosed script', '<script>\n' + body(30, (i) => `x(${i});`)],
|
|
682
|
+
[
|
|
683
|
+
'script then fence',
|
|
684
|
+
'<script>\nlet a = 1;\n</script>\n\n```\n' +
|
|
685
|
+
body(20, (i) => `c${i}`) +
|
|
686
|
+
'```\n',
|
|
687
|
+
],
|
|
688
|
+
];
|
|
689
|
+
const crlf = (s: string) => s.replace(/\n/g, '\r\n');
|
|
690
|
+
const cr = (s: string) => s.replace(/\n/g, '\r');
|
|
691
|
+
|
|
692
|
+
function feed_counted(source: string, size: number) {
|
|
693
|
+
const tree = new TreeBuilder(source.length);
|
|
694
|
+
const parser = new PFMParser(tree);
|
|
695
|
+
const p = parser as any;
|
|
696
|
+
const skip = p.skip_wait;
|
|
697
|
+
let skipped = 0;
|
|
698
|
+
p.skip_wait = function (chunk: string, len: number) {
|
|
699
|
+
const r = skip.call(this, chunk, len);
|
|
700
|
+
if (r) skipped++;
|
|
701
|
+
return r;
|
|
702
|
+
};
|
|
703
|
+
parser.init();
|
|
704
|
+
for (let i = 0; i < source.length; i += size) {
|
|
705
|
+
parser.feed(source.slice(i, i + size));
|
|
706
|
+
}
|
|
707
|
+
parser.finish();
|
|
708
|
+
return { nodes: tree.get_buffer(), skipped };
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
for (const [name, source] of cases) {
|
|
712
|
+
for (const variant of [source, crlf(source), cr(source)]) {
|
|
713
|
+
const batch = parse_batch(variant);
|
|
714
|
+
for (const size of [1, 2, 3, 7, 64]) {
|
|
715
|
+
const label = `${name} ${JSON.stringify(variant.slice(-6))} chunk ${size}`;
|
|
716
|
+
it(label, () => {
|
|
717
|
+
const { nodes } = feed_counted(variant, size);
|
|
718
|
+
expect(tree_diff(batch, nodes, variant)).toEqual([]);
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
it('skips feeds inside a fence', () => {
|
|
725
|
+
const source = '```\n' + body(40, (i) => `code line ${i}`) + '```\n';
|
|
726
|
+
const { nodes, skipped } = feed_counted(source, 16);
|
|
727
|
+
expect(skipped).toBeGreaterThan(20);
|
|
728
|
+
expect(tree_diff(parse_batch(source), nodes, source)).toEqual([]);
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
it('skips feeds inside a script', () => {
|
|
732
|
+
const source =
|
|
733
|
+
'<script>\n' + body(40, (i) => `let x${i} = ${i};`) + '</script>\n';
|
|
734
|
+
const { nodes, skipped } = feed_counted(source, 16);
|
|
735
|
+
expect(skipped).toBeGreaterThan(20);
|
|
736
|
+
expect(tree_diff(parse_batch(source), nodes, source)).toEqual([]);
|
|
737
|
+
});
|
|
738
|
+
|
|
739
|
+
it('does not skip a chunk holding the fence close', () => {
|
|
740
|
+
const tree = new TreeBuilder(64);
|
|
741
|
+
const parser = new PFMParser(tree);
|
|
742
|
+
parser.init();
|
|
743
|
+
parser.feed('```\nabc\n');
|
|
744
|
+
parser.feed('x\n`');
|
|
745
|
+
parser.feed('``\nafter\n');
|
|
746
|
+
parser.finish();
|
|
747
|
+
const full = '```\nabc\nx\n```\nafter\n';
|
|
748
|
+
expect(tree_diff(parse_batch(full), tree.get_buffer(), full)).toEqual([]);
|
|
749
|
+
});
|
|
750
|
+
});
|
package/test/lists.spec.ts
CHANGED
|
@@ -4,7 +4,8 @@ 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 type { NodeBuffer } from '../src/utils';
|
|
9
10
|
|
|
10
11
|
const this_dir = dirname(fileURLToPath(import.meta.url));
|
|
@@ -586,3 +587,108 @@ describe('Lists', () => {
|
|
|
586
587
|
expect(items.length).toBe(3);
|
|
587
588
|
});
|
|
588
589
|
});
|
|
590
|
+
|
|
591
|
+
type Shape = string | [string, ...Shape[]];
|
|
592
|
+
|
|
593
|
+
function shape(nodes: NodeBuffer, source: string, id = 0): Shape {
|
|
594
|
+
const n = nodes.get_node(id);
|
|
595
|
+
if (n.kind === 'text') return `text:${source.slice(n.value[0], n.value[1])}`;
|
|
596
|
+
const children = n.children
|
|
597
|
+
.map((c: number) => shape(nodes, source, c))
|
|
598
|
+
.filter((c: Shape) => c !== 'line_break');
|
|
599
|
+
if (children.length === 0) return n.kind;
|
|
600
|
+
return [n.kind, ...children];
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
function root_shape(input: string): Shape[] {
|
|
604
|
+
const { nodes, source } = parse_markdown_svelte(input);
|
|
605
|
+
return (shape(nodes, source) as Shape[]).slice(1);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
function incremental_shape(input: string, chunk_size: number): Shape[] {
|
|
609
|
+
const tree = new TreeBuilder(input.length);
|
|
610
|
+
const parser = new PFMParser(tree);
|
|
611
|
+
parser.init();
|
|
612
|
+
for (let i = 0; i < input.length; i += chunk_size) {
|
|
613
|
+
parser.feed(input.slice(i, i + chunk_size));
|
|
614
|
+
}
|
|
615
|
+
parser.finish();
|
|
616
|
+
return (shape(tree.get_buffer(), input) as Shape[]).slice(1);
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
describe('indented lists', () => {
|
|
620
|
+
const siblings: Shape[] = [
|
|
621
|
+
['list', ['list_item', 'text:a'], ['list_item', 'text:b']],
|
|
622
|
+
];
|
|
623
|
+
|
|
624
|
+
const cases: [string, string, Shape[]][] = [
|
|
625
|
+
['two spaces', ' - a\n - b\n', siblings],
|
|
626
|
+
['four spaces', ' - a\n - b\n', siblings],
|
|
627
|
+
['a tab', '\t- a\n\t- b\n', siblings],
|
|
628
|
+
['ordered', ' 1. a\n 2. b\n', siblings],
|
|
629
|
+
['in a block quote', '> - a\n> - b\n', [['block_quote', ...siblings]]],
|
|
630
|
+
[
|
|
631
|
+
'in an html block',
|
|
632
|
+
'<div>\n\n - a\n - b\n\n</div>\n',
|
|
633
|
+
[['html', ...siblings]],
|
|
634
|
+
],
|
|
635
|
+
[
|
|
636
|
+
'in a component',
|
|
637
|
+
'<Item>\n - a\n - b\n</Item>\n',
|
|
638
|
+
[['html', ...siblings]],
|
|
639
|
+
],
|
|
640
|
+
[
|
|
641
|
+
'in a svelte block',
|
|
642
|
+
'{#if x}\n - a\n - b\n{/if}\n',
|
|
643
|
+
[['svelte_block', ['svelte_branch', ...siblings]]],
|
|
644
|
+
],
|
|
645
|
+
[
|
|
646
|
+
'nested relative to the first marker',
|
|
647
|
+
' - a\n - b\n - c\n',
|
|
648
|
+
[
|
|
649
|
+
[
|
|
650
|
+
'list',
|
|
651
|
+
['list_item', 'text:a', ['list', ['list_item', 'text:b']]],
|
|
652
|
+
['list_item', 'text:c'],
|
|
653
|
+
],
|
|
654
|
+
],
|
|
655
|
+
],
|
|
656
|
+
[
|
|
657
|
+
'nested in a block quote',
|
|
658
|
+
'> - a\n> - b\n',
|
|
659
|
+
[
|
|
660
|
+
[
|
|
661
|
+
'block_quote',
|
|
662
|
+
['list', ['list_item', 'text:a', ['list', ['list_item', 'text:b']]]],
|
|
663
|
+
],
|
|
664
|
+
],
|
|
665
|
+
],
|
|
666
|
+
[
|
|
667
|
+
'later paragraph at the list indent leaves the list',
|
|
668
|
+
'<div>\n\n - a\n - b\n\n after\n\n</div>\n',
|
|
669
|
+
[['html', ...siblings, ['paragraph', 'text:after']]],
|
|
670
|
+
],
|
|
671
|
+
];
|
|
672
|
+
|
|
673
|
+
for (const [name, input, expected] of cases) {
|
|
674
|
+
test(name, () => {
|
|
675
|
+
expect(root_shape(input)).toEqual(expected);
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
test(`${name}, fed in chunks`, () => {
|
|
679
|
+
for (const size of [1, 2, 3, 7]) {
|
|
680
|
+
expect(incremental_shape(input, size)).toEqual(expected);
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
test('indent survives a feed window trim', () => {
|
|
686
|
+
// enough text before the list for the window to trim
|
|
687
|
+
const input = 'word '.repeat(400) + '\n\n' + ' - a\n - b\n';
|
|
688
|
+
const expected = root_shape(input);
|
|
689
|
+
expect(expected[1]).toEqual(siblings[0]);
|
|
690
|
+
for (const size of [1, 5, 64]) {
|
|
691
|
+
expect(incremental_shape(input, size)).toEqual(expected);
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { PFMParser } from '../src/main';
|
|
3
|
+
import { TreeBuilder } from '../src/tree_builder';
|
|
4
|
+
import { print_ast } from './print';
|
|
5
|
+
|
|
6
|
+
function parse_with(parser: PFMParser, builder: TreeBuilder, source: string) {
|
|
7
|
+
builder.reset();
|
|
8
|
+
parser.parse(source);
|
|
9
|
+
return print_ast(builder.get_buffer(), source);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function parse_fresh(source: string) {
|
|
13
|
+
const builder = new TreeBuilder(64);
|
|
14
|
+
return parse_with(new PFMParser(builder), builder, source);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// documents that end with parser flags still set
|
|
18
|
+
const LEAKY = ['# ` ', '> # ` ', '- # ` ', '# a\u0000', '## x\u0000y'];
|
|
19
|
+
|
|
20
|
+
const FOLLOWERS = [
|
|
21
|
+
'a\n~~~\nb',
|
|
22
|
+
'Foo\n<b>\nbaz',
|
|
23
|
+
'_a_ and *b*\nnext line',
|
|
24
|
+
'# heading\n\ntext\nmore',
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
describe('a reused parser', () => {
|
|
28
|
+
for (const first of LEAKY) {
|
|
29
|
+
for (const second of FOLLOWERS) {
|
|
30
|
+
it(`parses ${JSON.stringify(second)} after ${JSON.stringify(first)} like a fresh parser`, () => {
|
|
31
|
+
const builder = new TreeBuilder(64);
|
|
32
|
+
const parser = new PFMParser(builder);
|
|
33
|
+
parse_with(parser, builder, first);
|
|
34
|
+
expect(parse_with(parser, builder, second)).toEqual(
|
|
35
|
+
parse_fresh(second)
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|