@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/plugins.spec.ts
CHANGED
|
@@ -1,34 +1,31 @@
|
|
|
1
|
-
import { describe, it, expect } from
|
|
2
|
-
import { parse_markdown_svelte, NodeKind } from
|
|
3
|
-
import type { ParsePlugin } from
|
|
4
|
-
import { TreeBuilder } from
|
|
5
|
-
import { PluginDispatcher } from
|
|
6
|
-
import { SourceTextSource, WireTextSource } from
|
|
7
|
-
import { PFMParser, WireEmitter } from
|
|
8
|
-
import { WireTreeBuilder } from
|
|
9
|
-
import { NodeBuffer, kind_to_string, string_to_kind } from
|
|
10
|
-
import { UndoLog, UndoEntryKind, ATTR_DID_NOT_EXIST } from
|
|
11
|
-
import { NodeView, ViewCache } from
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
expect(string_to_kind(
|
|
17
|
-
expect(string_to_kind(
|
|
18
|
-
expect(string_to_kind(
|
|
19
|
-
expect(string_to_kind(
|
|
20
|
-
expect(string_to_kind(
|
|
21
|
-
expect(string_to_kind(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("round-trips with kind_to_string", () => {
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { parse_markdown_svelte, NodeKind } from '../src/main';
|
|
3
|
+
import type { ParsePlugin } from '../src/plugin_types';
|
|
4
|
+
import { TreeBuilder } from '../src/tree_builder';
|
|
5
|
+
import { PluginDispatcher } from '../src/plugin_dispatch';
|
|
6
|
+
import { SourceTextSource, WireTextSource } from '../src/node_view';
|
|
7
|
+
import { PFMParser, WireEmitter } from '../src/main';
|
|
8
|
+
import { WireTreeBuilder } from '../src/wire_tree_builder';
|
|
9
|
+
import { NodeBuffer, kind_to_string, string_to_kind } from '../src/utils';
|
|
10
|
+
import { UndoLog, UndoEntryKind, ATTR_DID_NOT_EXIST } from '../src/undo_log';
|
|
11
|
+
import { NodeView, ViewCache } from '../src/node_view';
|
|
12
|
+
|
|
13
|
+
describe('string_to_kind', () => {
|
|
14
|
+
it('maps all known node types', () => {
|
|
15
|
+
expect(string_to_kind('root')).toBe(NodeKind.root);
|
|
16
|
+
expect(string_to_kind('heading')).toBe(NodeKind.heading);
|
|
17
|
+
expect(string_to_kind('paragraph')).toBe(NodeKind.paragraph);
|
|
18
|
+
expect(string_to_kind('link')).toBe(NodeKind.link);
|
|
19
|
+
expect(string_to_kind('code_fence')).toBe(NodeKind.code_fence);
|
|
20
|
+
expect(string_to_kind('emphasis')).toBe(NodeKind.emphasis);
|
|
21
|
+
expect(string_to_kind('import_statement')).toBe(NodeKind.import_statement);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('returns undefined for unknown types', () => {
|
|
25
|
+
expect(string_to_kind('nonexistent')).toBeUndefined();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('round-trips with kind_to_string', () => {
|
|
32
29
|
for (let i = 0; i <= 34; i++) {
|
|
33
30
|
const name = kind_to_string(i as NodeKind);
|
|
34
31
|
expect(string_to_kind(name)).toBe(i);
|
|
@@ -36,20 +33,19 @@ describe("string_to_kind", () => {
|
|
|
36
33
|
});
|
|
37
34
|
});
|
|
38
35
|
|
|
39
|
-
|
|
40
|
-
describe(
|
|
41
|
-
|
|
42
|
-
it("allocates without parent linking", () => {
|
|
36
|
+
describe('NodeBuffer extensions', () => {
|
|
37
|
+
describe('push_unlinked', () => {
|
|
38
|
+
it('allocates without parent linking', () => {
|
|
43
39
|
const buf = new NodeBuffer(16);
|
|
44
40
|
const idx = buf.push_unlinked(NodeKind.paragraph, 0);
|
|
45
|
-
expect(buf.
|
|
46
|
-
expect(buf.
|
|
47
|
-
expect(buf.
|
|
41
|
+
expect(buf.kind_at(idx)).toBe(NodeKind.paragraph);
|
|
42
|
+
expect(buf.parent_at(idx)).toBe(0xffffffff);
|
|
43
|
+
expect(buf.first_child_at(0)).toBe(0xffffffff);
|
|
48
44
|
});
|
|
49
45
|
});
|
|
50
46
|
|
|
51
|
-
describe(
|
|
52
|
-
it(
|
|
47
|
+
describe('wrap_children', () => {
|
|
48
|
+
it('wraps existing children under a new node', () => {
|
|
53
49
|
const buf = new NodeBuffer(16);
|
|
54
50
|
// push two children under root
|
|
55
51
|
const a = buf.push(NodeKind.paragraph, 0, 0);
|
|
@@ -59,26 +55,26 @@ describe("NodeBuffer extensions", () => {
|
|
|
59
55
|
const wrapper = buf.wrap_children(0, NodeKind.block_quote);
|
|
60
56
|
|
|
61
57
|
// wrapper is sole child of root
|
|
62
|
-
expect(buf.
|
|
63
|
-
expect(buf.
|
|
58
|
+
expect(buf.first_child_at(0)).toBe(wrapper);
|
|
59
|
+
expect(buf.last_child_at(0)).toBe(wrapper);
|
|
64
60
|
|
|
65
61
|
// a and b are children of wrapper
|
|
66
|
-
expect(buf.
|
|
67
|
-
expect(buf.
|
|
68
|
-
expect(buf.
|
|
69
|
-
expect(buf.
|
|
62
|
+
expect(buf.parent_at(a)).toBe(wrapper);
|
|
63
|
+
expect(buf.parent_at(b)).toBe(wrapper);
|
|
64
|
+
expect(buf.first_child_at(wrapper)).toBe(a);
|
|
65
|
+
expect(buf.last_child_at(wrapper)).toBe(b);
|
|
70
66
|
});
|
|
71
67
|
|
|
72
|
-
it(
|
|
68
|
+
it('works with no existing children', () => {
|
|
73
69
|
const buf = new NodeBuffer(16);
|
|
74
70
|
const wrapper = buf.wrap_children(0, NodeKind.paragraph);
|
|
75
71
|
|
|
76
|
-
expect(buf.
|
|
77
|
-
expect(buf.
|
|
78
|
-
expect(buf.
|
|
72
|
+
expect(buf.first_child_at(0)).toBe(wrapper);
|
|
73
|
+
expect(buf.last_child_at(0)).toBe(wrapper);
|
|
74
|
+
expect(buf.first_child_at(wrapper)).toBe(0xffffffff);
|
|
79
75
|
});
|
|
80
76
|
|
|
81
|
-
it(
|
|
77
|
+
it('preserves sibling chain order', () => {
|
|
82
78
|
const buf = new NodeBuffer(16);
|
|
83
79
|
const a = buf.push(NodeKind.text, 0, 0);
|
|
84
80
|
const b = buf.push(NodeKind.text, 5, 0);
|
|
@@ -87,55 +83,54 @@ describe("NodeBuffer extensions", () => {
|
|
|
87
83
|
const wrapper = buf.wrap_children(0, NodeKind.emphasis);
|
|
88
84
|
|
|
89
85
|
// sibling chain: a -> b -> c
|
|
90
|
-
expect(buf.
|
|
91
|
-
expect(buf.
|
|
92
|
-
expect(buf.
|
|
86
|
+
expect(buf.next_at(a)).toBe(b);
|
|
87
|
+
expect(buf.next_at(b)).toBe(c);
|
|
88
|
+
expect(buf.next_at(c)).toBe(0xffffffff);
|
|
93
89
|
});
|
|
94
90
|
});
|
|
95
91
|
});
|
|
96
92
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
it("records and revokes attr set", () => {
|
|
93
|
+
describe('UndoLog', () => {
|
|
94
|
+
it('records and revokes attr set', () => {
|
|
100
95
|
const buf = new NodeBuffer(16);
|
|
101
96
|
const idx = buf.push(NodeKind.heading, 0, 0);
|
|
102
|
-
buf.set_metadata(idx, { id:
|
|
97
|
+
buf.set_metadata(idx, { id: 'original' });
|
|
103
98
|
|
|
104
99
|
const undo = new UndoLog();
|
|
105
100
|
undo.set_active_node(idx);
|
|
106
|
-
undo.record_attr_set(idx,
|
|
101
|
+
undo.record_attr_set(idx, 'id', 'original');
|
|
107
102
|
undo.clear_active_node();
|
|
108
103
|
|
|
109
104
|
// simulate mutation
|
|
110
105
|
const meta = buf.metadata_at(idx)!;
|
|
111
|
-
meta.id =
|
|
106
|
+
meta.id = 'changed';
|
|
112
107
|
buf.set_metadata(idx, meta);
|
|
113
108
|
|
|
114
|
-
expect(buf.metadata_at(idx)!.id).toBe(
|
|
109
|
+
expect(buf.metadata_at(idx)!.id).toBe('changed');
|
|
115
110
|
|
|
116
111
|
// revoke
|
|
117
112
|
undo.revoke(idx, buf);
|
|
118
|
-
expect(buf.metadata_at(idx)!.id).toBe(
|
|
113
|
+
expect(buf.metadata_at(idx)!.id).toBe('original');
|
|
119
114
|
});
|
|
120
115
|
|
|
121
|
-
it(
|
|
116
|
+
it('records and revokes attr set on non-existent key', () => {
|
|
122
117
|
const buf = new NodeBuffer(16);
|
|
123
118
|
const idx = buf.push(NodeKind.heading, 0, 0);
|
|
124
119
|
|
|
125
120
|
const undo = new UndoLog();
|
|
126
121
|
undo.set_active_node(idx);
|
|
127
|
-
undo.record_attr_set(idx,
|
|
122
|
+
undo.record_attr_set(idx, 'id', ATTR_DID_NOT_EXIST);
|
|
128
123
|
undo.clear_active_node();
|
|
129
124
|
|
|
130
125
|
// simulate mutation
|
|
131
|
-
buf.set_metadata(idx, { id:
|
|
126
|
+
buf.set_metadata(idx, { id: 'new' });
|
|
132
127
|
|
|
133
128
|
// revoke
|
|
134
129
|
undo.revoke(idx, buf);
|
|
135
130
|
expect(buf.metadata_at(idx)!.id).toBeUndefined();
|
|
136
131
|
});
|
|
137
132
|
|
|
138
|
-
it(
|
|
133
|
+
it('records and revokes type change', () => {
|
|
139
134
|
const buf = new NodeBuffer(16);
|
|
140
135
|
const idx = buf.push(NodeKind.heading, 0, 0);
|
|
141
136
|
|
|
@@ -145,15 +140,15 @@ describe("UndoLog", () => {
|
|
|
145
140
|
undo.clear_active_node();
|
|
146
141
|
|
|
147
142
|
// simulate type change
|
|
148
|
-
buf.
|
|
149
|
-
expect(buf.
|
|
143
|
+
buf.set_kind(idx, NodeKind.paragraph);
|
|
144
|
+
expect(buf.kind_at(idx)).toBe(NodeKind.paragraph);
|
|
150
145
|
|
|
151
146
|
// revoke
|
|
152
147
|
undo.revoke(idx, buf);
|
|
153
|
-
expect(buf.
|
|
148
|
+
expect(buf.kind_at(idx)).toBe(NodeKind.heading);
|
|
154
149
|
});
|
|
155
150
|
|
|
156
|
-
it(
|
|
151
|
+
it('commit discards the log', () => {
|
|
157
152
|
const buf = new NodeBuffer(16);
|
|
158
153
|
const idx = buf.push(NodeKind.heading, 0, 0);
|
|
159
154
|
|
|
@@ -162,16 +157,16 @@ describe("UndoLog", () => {
|
|
|
162
157
|
undo.record_type_change(idx, NodeKind.heading);
|
|
163
158
|
undo.clear_active_node();
|
|
164
159
|
|
|
165
|
-
buf.
|
|
160
|
+
buf.set_kind(idx, NodeKind.paragraph);
|
|
166
161
|
|
|
167
162
|
// commit (not revoke)
|
|
168
163
|
undo.commit(idx);
|
|
169
164
|
// type change is permanent
|
|
170
|
-
expect(buf.
|
|
165
|
+
expect(buf.kind_at(idx)).toBe(NodeKind.paragraph);
|
|
171
166
|
expect(undo.has(idx)).toBe(false);
|
|
172
167
|
});
|
|
173
168
|
|
|
174
|
-
it(
|
|
169
|
+
it('revokes in reverse order', () => {
|
|
175
170
|
const buf = new NodeBuffer(16);
|
|
176
171
|
const idx = buf.push(NodeKind.heading, 0, 0);
|
|
177
172
|
buf.set_metadata(idx, {});
|
|
@@ -180,18 +175,18 @@ describe("UndoLog", () => {
|
|
|
180
175
|
undo.set_active_node(idx);
|
|
181
176
|
|
|
182
177
|
// first mutation: set id
|
|
183
|
-
undo.record_attr_set(idx,
|
|
184
|
-
buf.metadata_at(idx)!.id =
|
|
178
|
+
undo.record_attr_set(idx, 'id', ATTR_DID_NOT_EXIST);
|
|
179
|
+
buf.metadata_at(idx)!.id = 'first';
|
|
185
180
|
buf.set_metadata(idx, buf.metadata_at(idx)!);
|
|
186
181
|
|
|
187
182
|
// second mutation: overwrite id
|
|
188
|
-
undo.record_attr_set(idx,
|
|
189
|
-
buf.metadata_at(idx)!.id =
|
|
183
|
+
undo.record_attr_set(idx, 'id', 'first');
|
|
184
|
+
buf.metadata_at(idx)!.id = 'second';
|
|
190
185
|
buf.set_metadata(idx, buf.metadata_at(idx)!);
|
|
191
186
|
|
|
192
187
|
undo.clear_active_node();
|
|
193
188
|
|
|
194
|
-
expect(buf.metadata_at(idx)!.id).toBe(
|
|
189
|
+
expect(buf.metadata_at(idx)!.id).toBe('second');
|
|
195
190
|
|
|
196
191
|
// revoke should restore to before any mutation
|
|
197
192
|
undo.revoke(idx, buf);
|
|
@@ -199,15 +194,14 @@ describe("UndoLog", () => {
|
|
|
199
194
|
});
|
|
200
195
|
});
|
|
201
196
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const result = parse_markdown_svelte("# Hello\n\nWorld\n");
|
|
197
|
+
describe('parse plugins', () => {
|
|
198
|
+
it('no-op when no plugins provided', () => {
|
|
199
|
+
const result = parse_markdown_svelte('# Hello\n\nWorld\n');
|
|
206
200
|
const root = result.nodes.get_node(0);
|
|
207
201
|
expect(root.children.length).toBeGreaterThan(0);
|
|
208
202
|
});
|
|
209
203
|
|
|
210
|
-
it(
|
|
204
|
+
it('fires open handler on matching node type', () => {
|
|
211
205
|
const seen: string[] = [];
|
|
212
206
|
const plugin: ParsePlugin = {
|
|
213
207
|
heading: {
|
|
@@ -217,11 +211,11 @@ describe("parse plugins", () => {
|
|
|
217
211
|
},
|
|
218
212
|
};
|
|
219
213
|
|
|
220
|
-
parse_markdown_svelte(
|
|
221
|
-
expect(seen).toEqual([
|
|
214
|
+
parse_markdown_svelte('# Hello\n\n## World\n', { plugins: [plugin] });
|
|
215
|
+
expect(seen).toEqual(['heading', 'heading']);
|
|
222
216
|
});
|
|
223
217
|
|
|
224
|
-
it(
|
|
218
|
+
it('fires close callback on node close', () => {
|
|
225
219
|
const open_types: string[] = [];
|
|
226
220
|
const close_types: string[] = [];
|
|
227
221
|
|
|
@@ -236,32 +230,30 @@ describe("parse plugins", () => {
|
|
|
236
230
|
},
|
|
237
231
|
};
|
|
238
232
|
|
|
239
|
-
parse_markdown_svelte(
|
|
240
|
-
expect(open_types).toEqual([
|
|
241
|
-
expect(close_types).toEqual([
|
|
233
|
+
parse_markdown_svelte('# Hello\n', { plugins: [plugin] });
|
|
234
|
+
expect(open_types).toEqual(['heading']);
|
|
235
|
+
expect(close_types).toEqual(['heading']);
|
|
242
236
|
});
|
|
243
237
|
|
|
244
|
-
it(
|
|
238
|
+
it('sets attrs on nodes', () => {
|
|
245
239
|
const plugin: ParsePlugin = {
|
|
246
240
|
heading: {
|
|
247
241
|
parse(node) {
|
|
248
|
-
node.attrs.id =
|
|
242
|
+
node.attrs.id = 'test-heading';
|
|
249
243
|
},
|
|
250
244
|
},
|
|
251
245
|
};
|
|
252
246
|
|
|
253
|
-
const result = parse_markdown_svelte(
|
|
247
|
+
const result = parse_markdown_svelte('# Hello\n', {
|
|
254
248
|
plugins: [plugin],
|
|
255
249
|
});
|
|
256
250
|
const root = result.nodes.get_node(0);
|
|
257
251
|
const heading_idx = root.children[0];
|
|
258
|
-
expect(result.nodes.metadata_at(heading_idx)?.id).toBe(
|
|
259
|
-
"test-heading",
|
|
260
|
-
);
|
|
252
|
+
expect(result.nodes.metadata_at(heading_idx)?.id).toBe('test-heading');
|
|
261
253
|
});
|
|
262
254
|
|
|
263
|
-
it(
|
|
264
|
-
let text =
|
|
255
|
+
it('reads text_content in close callback', () => {
|
|
256
|
+
let text = '';
|
|
265
257
|
const plugin: ParsePlugin = {
|
|
266
258
|
heading: {
|
|
267
259
|
parse(node) {
|
|
@@ -272,11 +264,11 @@ describe("parse plugins", () => {
|
|
|
272
264
|
},
|
|
273
265
|
};
|
|
274
266
|
|
|
275
|
-
parse_markdown_svelte(
|
|
276
|
-
expect(text).toBe(
|
|
267
|
+
parse_markdown_svelte('# Hello World\n', { plugins: [plugin] });
|
|
268
|
+
expect(text).toBe('Hello World');
|
|
277
269
|
});
|
|
278
270
|
|
|
279
|
-
it(
|
|
271
|
+
it('reads heading depth', () => {
|
|
280
272
|
const depths: (number | undefined)[] = [];
|
|
281
273
|
const plugin: ParsePlugin = {
|
|
282
274
|
heading: {
|
|
@@ -286,35 +278,35 @@ describe("parse plugins", () => {
|
|
|
286
278
|
},
|
|
287
279
|
};
|
|
288
280
|
|
|
289
|
-
parse_markdown_svelte(
|
|
281
|
+
parse_markdown_svelte('# H1\n\n## H2\n\n### H3\n', {
|
|
290
282
|
plugins: [plugin],
|
|
291
283
|
});
|
|
292
284
|
expect(depths).toEqual([1, 2, 3]);
|
|
293
285
|
});
|
|
294
286
|
|
|
295
|
-
it(
|
|
296
|
-
let parent_type =
|
|
287
|
+
it('traverses to parent', () => {
|
|
288
|
+
let parent_type = '';
|
|
297
289
|
const plugin: ParsePlugin = {
|
|
298
290
|
heading: {
|
|
299
291
|
parse(node) {
|
|
300
|
-
parent_type = node.parent?.type ??
|
|
292
|
+
parent_type = node.parent?.type ?? 'none';
|
|
301
293
|
},
|
|
302
294
|
},
|
|
303
295
|
};
|
|
304
296
|
|
|
305
|
-
parse_markdown_svelte(
|
|
306
|
-
expect(parent_type).toBe(
|
|
297
|
+
parse_markdown_svelte('# Hello\n', { plugins: [plugin] });
|
|
298
|
+
expect(parent_type).toBe('root');
|
|
307
299
|
});
|
|
308
300
|
|
|
309
|
-
it(
|
|
301
|
+
it('multiple plugins compose on same node type', () => {
|
|
310
302
|
const log: string[] = [];
|
|
311
303
|
|
|
312
304
|
const plugin_a: ParsePlugin = {
|
|
313
305
|
heading: {
|
|
314
306
|
parse(node) {
|
|
315
307
|
node.attrs.from_a = true;
|
|
316
|
-
log.push(
|
|
317
|
-
return () => log.push(
|
|
308
|
+
log.push('a-open');
|
|
309
|
+
return () => log.push('a-close');
|
|
318
310
|
},
|
|
319
311
|
},
|
|
320
312
|
};
|
|
@@ -325,21 +317,16 @@ describe("parse plugins", () => {
|
|
|
325
317
|
// second plugin can see first plugin's mutations
|
|
326
318
|
log.push(`b-open:from_a=${node.attrs.from_a}`);
|
|
327
319
|
node.attrs.from_b = true;
|
|
328
|
-
return () => log.push(
|
|
320
|
+
return () => log.push('b-close');
|
|
329
321
|
},
|
|
330
322
|
},
|
|
331
323
|
};
|
|
332
324
|
|
|
333
|
-
const result = parse_markdown_svelte(
|
|
325
|
+
const result = parse_markdown_svelte('# Hello\n', {
|
|
334
326
|
plugins: [plugin_a, plugin_b],
|
|
335
327
|
});
|
|
336
328
|
|
|
337
|
-
expect(log).toEqual([
|
|
338
|
-
"a-open",
|
|
339
|
-
"b-open:from_a=true",
|
|
340
|
-
"a-close",
|
|
341
|
-
"b-close",
|
|
342
|
-
]);
|
|
329
|
+
expect(log).toEqual(['a-open', 'b-open:from_a=true', 'a-close', 'b-close']);
|
|
343
330
|
|
|
344
331
|
// both mutations present
|
|
345
332
|
const root = result.nodes.get_node(0);
|
|
@@ -349,7 +336,7 @@ describe("parse plugins", () => {
|
|
|
349
336
|
expect(meta?.from_b).toBe(true);
|
|
350
337
|
});
|
|
351
338
|
|
|
352
|
-
it(
|
|
339
|
+
it('handles multiple different node types', () => {
|
|
353
340
|
const types_seen: string[] = [];
|
|
354
341
|
|
|
355
342
|
const plugin: ParsePlugin = {
|
|
@@ -365,11 +352,11 @@ describe("parse plugins", () => {
|
|
|
365
352
|
},
|
|
366
353
|
};
|
|
367
354
|
|
|
368
|
-
parse_markdown_svelte(
|
|
369
|
-
expect(types_seen).toEqual([
|
|
355
|
+
parse_markdown_svelte('# Hello\n\nWorld\n', { plugins: [plugin] });
|
|
356
|
+
expect(types_seen).toEqual(['heading', 'paragraph']);
|
|
370
357
|
});
|
|
371
358
|
|
|
372
|
-
it(
|
|
359
|
+
it('ignores unregistered node types', () => {
|
|
373
360
|
let called = false;
|
|
374
361
|
const plugin: ParsePlugin = {
|
|
375
362
|
heading: {
|
|
@@ -380,19 +367,19 @@ describe("parse plugins", () => {
|
|
|
380
367
|
};
|
|
381
368
|
|
|
382
369
|
// no headings in this input
|
|
383
|
-
parse_markdown_svelte(
|
|
370
|
+
parse_markdown_svelte('Just a paragraph\n', { plugins: [plugin] });
|
|
384
371
|
expect(called).toBe(false);
|
|
385
372
|
});
|
|
386
373
|
});
|
|
387
374
|
|
|
388
|
-
describe(
|
|
389
|
-
it(
|
|
375
|
+
describe('parse plugins: sequential', () => {
|
|
376
|
+
it('runs sequential plugins after fused plugins', () => {
|
|
390
377
|
const log: string[] = [];
|
|
391
378
|
|
|
392
379
|
const fused: ParsePlugin = {
|
|
393
380
|
heading: {
|
|
394
381
|
parse() {
|
|
395
|
-
log.push(
|
|
382
|
+
log.push('fused');
|
|
396
383
|
},
|
|
397
384
|
},
|
|
398
385
|
};
|
|
@@ -401,54 +388,54 @@ describe("parse plugins: sequential", () => {
|
|
|
401
388
|
sequential: true,
|
|
402
389
|
heading: {
|
|
403
390
|
parse() {
|
|
404
|
-
log.push(
|
|
391
|
+
log.push('sequential');
|
|
405
392
|
},
|
|
406
393
|
},
|
|
407
394
|
};
|
|
408
395
|
|
|
409
|
-
parse_markdown_svelte(
|
|
396
|
+
parse_markdown_svelte('# Hello\n', {
|
|
410
397
|
plugins: [fused, sequential],
|
|
411
398
|
});
|
|
412
|
-
expect(log).toEqual([
|
|
399
|
+
expect(log).toEqual(['fused', 'sequential']);
|
|
413
400
|
});
|
|
414
401
|
|
|
415
|
-
it(
|
|
402
|
+
it('sequential plugin sees fused mutations', () => {
|
|
416
403
|
const fused: ParsePlugin = {
|
|
417
404
|
heading: {
|
|
418
405
|
parse(node) {
|
|
419
|
-
node.attrs.fused_id =
|
|
406
|
+
node.attrs.fused_id = 'from-fused';
|
|
420
407
|
},
|
|
421
408
|
},
|
|
422
409
|
};
|
|
423
410
|
|
|
424
|
-
let seen_id =
|
|
411
|
+
let seen_id = '';
|
|
425
412
|
const sequential: ParsePlugin = {
|
|
426
413
|
sequential: true,
|
|
427
414
|
heading: {
|
|
428
415
|
parse(node) {
|
|
429
|
-
seen_id = node.attrs.fused_id ??
|
|
416
|
+
seen_id = node.attrs.fused_id ?? 'not-found';
|
|
430
417
|
},
|
|
431
418
|
},
|
|
432
419
|
};
|
|
433
420
|
|
|
434
|
-
parse_markdown_svelte(
|
|
421
|
+
parse_markdown_svelte('# Hello\n', {
|
|
435
422
|
plugins: [fused, sequential],
|
|
436
423
|
});
|
|
437
|
-
expect(seen_id).toBe(
|
|
424
|
+
expect(seen_id).toBe('from-fused');
|
|
438
425
|
});
|
|
439
426
|
});
|
|
440
427
|
|
|
441
|
-
describe(
|
|
442
|
-
it(
|
|
428
|
+
describe('parse plugins: structural mutations', () => {
|
|
429
|
+
it('append adds a child node', () => {
|
|
443
430
|
const plugin: ParsePlugin = {
|
|
444
431
|
heading: {
|
|
445
432
|
parse(node) {
|
|
446
|
-
node.append(
|
|
433
|
+
node.append('text');
|
|
447
434
|
},
|
|
448
435
|
},
|
|
449
436
|
};
|
|
450
437
|
|
|
451
|
-
const result = parse_markdown_svelte(
|
|
438
|
+
const result = parse_markdown_svelte('# Hello\n', {
|
|
452
439
|
plugins: [plugin],
|
|
453
440
|
});
|
|
454
441
|
const root = result.nodes.get_node(0);
|
|
@@ -457,48 +444,46 @@ describe("parse plugins: structural mutations", () => {
|
|
|
457
444
|
expect(heading.children.length).toBeGreaterThan(0);
|
|
458
445
|
});
|
|
459
446
|
|
|
460
|
-
it(
|
|
447
|
+
it('prepend adds a first child node', () => {
|
|
461
448
|
const plugin: ParsePlugin = {
|
|
462
449
|
heading: {
|
|
463
450
|
parse(node) {
|
|
464
|
-
const prepended = node.prepend(
|
|
451
|
+
const prepended = node.prepend('text');
|
|
465
452
|
prepended.attrs.marker = true;
|
|
466
453
|
},
|
|
467
454
|
},
|
|
468
455
|
};
|
|
469
456
|
|
|
470
|
-
const result = parse_markdown_svelte(
|
|
457
|
+
const result = parse_markdown_svelte('# Hello\n', {
|
|
471
458
|
plugins: [plugin],
|
|
472
459
|
});
|
|
473
460
|
const root = result.nodes.get_node(0);
|
|
474
461
|
const heading = result.nodes.get_node(root.children[0]);
|
|
475
462
|
// first child should have our marker attr
|
|
476
463
|
if (heading.children.length > 0) {
|
|
477
|
-
const first_child_meta = result.nodes.metadata_at(
|
|
478
|
-
heading.children[0],
|
|
479
|
-
);
|
|
464
|
+
const first_child_meta = result.nodes.metadata_at(heading.children[0]);
|
|
480
465
|
expect(first_child_meta?.marker).toBe(true);
|
|
481
466
|
}
|
|
482
467
|
});
|
|
483
468
|
|
|
484
|
-
it(
|
|
485
|
-
let wrapper_type =
|
|
469
|
+
it('wrap_inner wraps existing children', () => {
|
|
470
|
+
let wrapper_type = '';
|
|
486
471
|
const plugin: ParsePlugin = {
|
|
487
472
|
heading: {
|
|
488
473
|
parse(node) {
|
|
489
|
-
const wrapper = node.wrap_inner(
|
|
474
|
+
const wrapper = node.wrap_inner('link');
|
|
490
475
|
wrapper_type = wrapper.type;
|
|
491
476
|
return () => {
|
|
492
|
-
wrapper.attrs.href =
|
|
477
|
+
wrapper.attrs.href = '#test';
|
|
493
478
|
};
|
|
494
479
|
},
|
|
495
480
|
},
|
|
496
481
|
};
|
|
497
482
|
|
|
498
|
-
const result = parse_markdown_svelte(
|
|
483
|
+
const result = parse_markdown_svelte('# Hello\n', {
|
|
499
484
|
plugins: [plugin],
|
|
500
485
|
});
|
|
501
|
-
expect(wrapper_type).toBe(
|
|
486
|
+
expect(wrapper_type).toBe('link');
|
|
502
487
|
|
|
503
488
|
const root = result.nodes.get_node(0);
|
|
504
489
|
const heading = result.nodes.get_node(root.children[0]);
|
|
@@ -509,23 +494,23 @@ describe("parse plugins: structural mutations", () => {
|
|
|
509
494
|
|
|
510
495
|
// link should have href attr
|
|
511
496
|
const link_meta = result.nodes.metadata_at(heading.children[0]);
|
|
512
|
-
expect(link_meta?.href).toBe(
|
|
497
|
+
expect(link_meta?.href).toBe('#test');
|
|
513
498
|
});
|
|
514
499
|
});
|
|
515
500
|
|
|
516
|
-
describe(
|
|
501
|
+
describe('parse plugins: the heading auto-link example from PLUGINS.md', () => {
|
|
517
502
|
function slugify(text: string): string {
|
|
518
503
|
return text
|
|
519
504
|
.toLowerCase()
|
|
520
|
-
.replace(/[^\w]+/g,
|
|
521
|
-
.replace(/^-+|-+$/g,
|
|
505
|
+
.replace(/[^\w]+/g, '-')
|
|
506
|
+
.replace(/^-+|-+$/g, '');
|
|
522
507
|
}
|
|
523
508
|
|
|
524
|
-
it(
|
|
509
|
+
it('wraps heading content in a link with slug-based href', () => {
|
|
525
510
|
const plugin: ParsePlugin = {
|
|
526
511
|
heading: {
|
|
527
512
|
parse(node) {
|
|
528
|
-
const link = node.wrap_inner(
|
|
513
|
+
const link = node.wrap_inner('link');
|
|
529
514
|
return () => {
|
|
530
515
|
const slug = slugify(node.text_content);
|
|
531
516
|
node.attrs.id = slug;
|
|
@@ -535,7 +520,7 @@ describe("parse plugins: the heading auto-link example from PLUGINS.md", () => {
|
|
|
535
520
|
},
|
|
536
521
|
};
|
|
537
522
|
|
|
538
|
-
const result = parse_markdown_svelte(
|
|
523
|
+
const result = parse_markdown_svelte('# Hello World\n\n## Second\n', {
|
|
539
524
|
plugins: [plugin],
|
|
540
525
|
});
|
|
541
526
|
|
|
@@ -544,54 +529,51 @@ describe("parse plugins: the heading auto-link example from PLUGINS.md", () => {
|
|
|
544
529
|
// find headings in root children (skip line_breaks/blank lines)
|
|
545
530
|
const headings = root.children
|
|
546
531
|
.map((idx) => result.nodes.get_node(idx))
|
|
547
|
-
.filter((n) => n.kind ===
|
|
532
|
+
.filter((n) => n.kind === 'heading');
|
|
548
533
|
|
|
549
534
|
expect(headings.length).toBe(2);
|
|
550
535
|
|
|
551
536
|
// first heading
|
|
552
537
|
const h1 = headings[0];
|
|
553
|
-
expect(h1.metadata.id).toBe(
|
|
538
|
+
expect(h1.metadata.id).toBe('hello-world');
|
|
554
539
|
const link1 = result.nodes.get_node(h1.children[0]);
|
|
555
|
-
expect(link1.kind).toBe(
|
|
556
|
-
expect(link1.metadata.href).toBe(
|
|
540
|
+
expect(link1.kind).toBe('link');
|
|
541
|
+
expect(link1.metadata.href).toBe('#hello-world');
|
|
557
542
|
|
|
558
543
|
// second heading
|
|
559
544
|
const h2 = headings[1];
|
|
560
|
-
expect(h2.metadata.id).toBe(
|
|
545
|
+
expect(h2.metadata.id).toBe('second');
|
|
561
546
|
const link2 = result.nodes.get_node(h2.children[0]);
|
|
562
|
-
expect(link2.kind).toBe(
|
|
563
|
-
expect(link2.metadata.href).toBe(
|
|
547
|
+
expect(link2.kind).toBe('link');
|
|
548
|
+
expect(link2.metadata.href).toBe('#second');
|
|
564
549
|
});
|
|
565
550
|
});
|
|
566
551
|
|
|
567
|
-
describe(
|
|
552
|
+
describe('parse plugins: wire path (WireEmitter → WireTreeBuilder)', () => {
|
|
568
553
|
function slugify(text: string): string {
|
|
569
554
|
return text
|
|
570
555
|
.toLowerCase()
|
|
571
|
-
.replace(/[^\w]+/g,
|
|
572
|
-
.replace(/^-+|-+$/g,
|
|
556
|
+
.replace(/[^\w]+/g, '-')
|
|
557
|
+
.replace(/^-+|-+$/g, '');
|
|
573
558
|
}
|
|
574
559
|
|
|
575
|
-
it(
|
|
560
|
+
it('simple attrs on strong_emphasis through wire pipeline', () => {
|
|
576
561
|
const plugin: ParsePlugin = {
|
|
577
562
|
strong_emphasis: {
|
|
578
563
|
parse(node) {
|
|
579
|
-
node.attrs.id =
|
|
564
|
+
node.attrs.id = 'boo';
|
|
580
565
|
},
|
|
581
566
|
},
|
|
582
567
|
};
|
|
583
568
|
|
|
584
|
-
const source =
|
|
569
|
+
const source = 'hello *world*\n';
|
|
585
570
|
const emitter = new WireEmitter();
|
|
586
571
|
const parser = new PFMParser(emitter);
|
|
587
572
|
emitter.set_source(source);
|
|
588
573
|
parser.parse(source);
|
|
589
574
|
const batches = emitter.flush();
|
|
590
575
|
|
|
591
|
-
const dispatcher = new PluginDispatcher(
|
|
592
|
-
[plugin],
|
|
593
|
-
new WireTextSource([]),
|
|
594
|
-
);
|
|
576
|
+
const dispatcher = new PluginDispatcher([plugin], new WireTextSource([]));
|
|
595
577
|
const builder = new WireTreeBuilder(128, dispatcher);
|
|
596
578
|
builder.apply(batches);
|
|
597
579
|
|
|
@@ -606,14 +588,14 @@ describe("parse plugins: wire path (WireEmitter → WireTreeBuilder)", () => {
|
|
|
606
588
|
}
|
|
607
589
|
}
|
|
608
590
|
expect(strong_idx).not.toBe(-1);
|
|
609
|
-
expect(buf.metadata_at(strong_idx)).toEqual({ id:
|
|
591
|
+
expect(buf.metadata_at(strong_idx)).toEqual({ id: 'boo' });
|
|
610
592
|
});
|
|
611
593
|
|
|
612
|
-
it(
|
|
594
|
+
it('autolink works through wire pipeline', () => {
|
|
613
595
|
const plugin: ParsePlugin = {
|
|
614
596
|
heading: {
|
|
615
597
|
parse(node) {
|
|
616
|
-
const link = node.wrap_inner(
|
|
598
|
+
const link = node.wrap_inner('link');
|
|
617
599
|
return () => {
|
|
618
600
|
const slug = slugify(node.text_content);
|
|
619
601
|
node.attrs.id = slug;
|
|
@@ -623,7 +605,7 @@ describe("parse plugins: wire path (WireEmitter → WireTreeBuilder)", () => {
|
|
|
623
605
|
},
|
|
624
606
|
};
|
|
625
607
|
|
|
626
|
-
const source =
|
|
608
|
+
const source = '# Hello World\n';
|
|
627
609
|
|
|
628
610
|
// wire pipeline: parser → WireEmitter → batches → WireTreeBuilder
|
|
629
611
|
const emitter = new WireEmitter();
|
|
@@ -643,25 +625,25 @@ describe("parse plugins: wire path (WireEmitter → WireTreeBuilder)", () => {
|
|
|
643
625
|
|
|
644
626
|
// find heading
|
|
645
627
|
const heading_idx = root.children.find(
|
|
646
|
-
(i: number) => buf.kind_at(i) === NodeKind.heading
|
|
628
|
+
(i: number) => buf.kind_at(i) === NodeKind.heading
|
|
647
629
|
)!;
|
|
648
630
|
expect(heading_idx).toBeDefined();
|
|
649
631
|
|
|
650
632
|
const heading = buf.get_node(heading_idx);
|
|
651
|
-
expect(heading.metadata.id).toBe(
|
|
633
|
+
expect(heading.metadata.id).toBe('hello-world');
|
|
652
634
|
|
|
653
635
|
// heading's first child should be a link
|
|
654
636
|
expect(heading.children.length).toBeGreaterThan(0);
|
|
655
637
|
const link = buf.get_node(heading.children[0]);
|
|
656
|
-
expect(link.kind).toBe(
|
|
657
|
-
expect(link.metadata.href).toBe(
|
|
638
|
+
expect(link.kind).toBe('link');
|
|
639
|
+
expect(link.metadata.href).toBe('#hello-world');
|
|
658
640
|
});
|
|
659
641
|
|
|
660
|
-
it(
|
|
642
|
+
it('autolink works with incremental feeding', () => {
|
|
661
643
|
const plugin: ParsePlugin = {
|
|
662
644
|
heading: {
|
|
663
645
|
parse(node) {
|
|
664
|
-
const link = node.wrap_inner(
|
|
646
|
+
const link = node.wrap_inner('link');
|
|
665
647
|
return () => {
|
|
666
648
|
const slug = slugify(node.text_content);
|
|
667
649
|
node.attrs.id = slug;
|
|
@@ -671,7 +653,7 @@ describe("parse plugins: wire path (WireEmitter → WireTreeBuilder)", () => {
|
|
|
671
653
|
},
|
|
672
654
|
};
|
|
673
655
|
|
|
674
|
-
const source =
|
|
656
|
+
const source = '# Hello World\n';
|
|
675
657
|
|
|
676
658
|
// incremental wire pipeline: feed char by char
|
|
677
659
|
const emitter = new WireEmitter();
|
|
@@ -681,7 +663,7 @@ describe("parse plugins: wire path (WireEmitter → WireTreeBuilder)", () => {
|
|
|
681
663
|
const dispatcher = new PluginDispatcher([plugin], new WireTextSource([]));
|
|
682
664
|
const builder = new WireTreeBuilder(128, dispatcher);
|
|
683
665
|
|
|
684
|
-
let accumulated =
|
|
666
|
+
let accumulated = '';
|
|
685
667
|
for (let i = 0; i < source.length; i++) {
|
|
686
668
|
accumulated += source[i];
|
|
687
669
|
emitter.set_source(accumulated);
|
|
@@ -701,21 +683,21 @@ describe("parse plugins: wire path (WireEmitter → WireTreeBuilder)", () => {
|
|
|
701
683
|
const root = buf.get_node(0);
|
|
702
684
|
|
|
703
685
|
const heading_idx = root.children.find(
|
|
704
|
-
(i: number) => buf.kind_at(i) === NodeKind.heading
|
|
686
|
+
(i: number) => buf.kind_at(i) === NodeKind.heading
|
|
705
687
|
)!;
|
|
706
688
|
const heading = buf.get_node(heading_idx);
|
|
707
|
-
expect(heading.metadata.id).toBe(
|
|
689
|
+
expect(heading.metadata.id).toBe('hello-world');
|
|
708
690
|
|
|
709
691
|
const link = buf.get_node(heading.children[0]);
|
|
710
|
-
expect(link.kind).toBe(
|
|
711
|
-
expect(link.metadata.href).toBe(
|
|
692
|
+
expect(link.kind).toBe('link');
|
|
693
|
+
expect(link.metadata.href).toBe('#hello-world');
|
|
712
694
|
});
|
|
713
695
|
|
|
714
|
-
it(
|
|
696
|
+
it('structural mutations are unwound when node is revoked during streaming', () => {
|
|
715
697
|
const plugin: ParsePlugin = {
|
|
716
698
|
strong_emphasis: {
|
|
717
699
|
parse(node) {
|
|
718
|
-
node.prepend(
|
|
700
|
+
node.prepend('link', { id: 'HELLO' });
|
|
719
701
|
},
|
|
720
702
|
},
|
|
721
703
|
};
|
|
@@ -723,20 +705,17 @@ describe("parse plugins: wire path (WireEmitter → WireTreeBuilder)", () => {
|
|
|
723
705
|
// "*h" opens strong_emphasis (pending), plugin prepends a link.
|
|
724
706
|
// "*hello\n\n" causes revocation, the * was not valid emphasis.
|
|
725
707
|
// the prepended link must be cleaned up.
|
|
726
|
-
const source =
|
|
708
|
+
const source = '*hello\n\n';
|
|
727
709
|
|
|
728
710
|
const emitter = new WireEmitter();
|
|
729
711
|
const parser = new PFMParser(emitter);
|
|
730
712
|
parser.init();
|
|
731
713
|
|
|
732
|
-
const dispatcher = new PluginDispatcher(
|
|
733
|
-
[plugin],
|
|
734
|
-
new WireTextSource([]),
|
|
735
|
-
);
|
|
714
|
+
const dispatcher = new PluginDispatcher([plugin], new WireTextSource([]));
|
|
736
715
|
const builder = new WireTreeBuilder(128, dispatcher);
|
|
737
716
|
|
|
738
717
|
// feed char by char to trigger incremental open → revoke
|
|
739
|
-
let accumulated =
|
|
718
|
+
let accumulated = '';
|
|
740
719
|
for (let i = 0; i < source.length; i++) {
|
|
741
720
|
accumulated += source[i];
|
|
742
721
|
emitter.set_source(accumulated);
|
|
@@ -758,7 +737,7 @@ describe("parse plugins: wire path (WireEmitter → WireTreeBuilder)", () => {
|
|
|
758
737
|
let found_hello = false;
|
|
759
738
|
for (let i = 0; i < buf.size; i++) {
|
|
760
739
|
const meta = buf.metadata_at(i);
|
|
761
|
-
if (meta?.id ===
|
|
740
|
+
if (meta?.id === 'HELLO' && buf.parent_at(i) !== 0xffffffff) {
|
|
762
741
|
found_hello = true;
|
|
763
742
|
}
|
|
764
743
|
}
|
|
@@ -766,46 +745,43 @@ describe("parse plugins: wire path (WireEmitter → WireTreeBuilder)", () => {
|
|
|
766
745
|
|
|
767
746
|
// the paragraph's children should form a valid sibling chain
|
|
768
747
|
const para_idx = root.children.find(
|
|
769
|
-
(i: number) => buf.kind_at(i) === NodeKind.paragraph
|
|
748
|
+
(i: number) => buf.kind_at(i) === NodeKind.paragraph
|
|
770
749
|
);
|
|
771
750
|
expect(para_idx).toBeDefined();
|
|
772
751
|
const para = buf.get_node(para_idx!);
|
|
773
752
|
expect(para.children.length).toBeGreaterThan(0);
|
|
774
753
|
|
|
775
754
|
// walk the sibling chain to verify integrity
|
|
776
|
-
let child = buf.
|
|
755
|
+
let child = buf.first_child_at(para_idx!);
|
|
777
756
|
let count = 0;
|
|
778
|
-
while (child !== 0xffffffff && buf.
|
|
757
|
+
while (child !== 0xffffffff && buf.parent_at(child) === para_idx!) {
|
|
779
758
|
count++;
|
|
780
|
-
child = buf.
|
|
759
|
+
child = buf.next_at(child);
|
|
781
760
|
}
|
|
782
761
|
expect(count).toBe(para.children.length);
|
|
783
762
|
});
|
|
784
763
|
|
|
785
|
-
it(
|
|
764
|
+
it('cross-node wrap_inner redirects children of the wrapped node', () => {
|
|
786
765
|
// plugin wraps parent's children from a child handler.
|
|
787
766
|
// children arriving AFTER the wrap should land inside the wrapper.
|
|
788
767
|
const plugin: ParsePlugin = {
|
|
789
768
|
strong_emphasis: {
|
|
790
769
|
parse(node) {
|
|
791
|
-
node.parent?.wrap_inner(
|
|
770
|
+
node.parent?.wrap_inner('link', { href: '#wrapped' });
|
|
792
771
|
},
|
|
793
772
|
},
|
|
794
773
|
};
|
|
795
774
|
|
|
796
|
-
const source =
|
|
775
|
+
const source = 'This *works* fine\n';
|
|
797
776
|
|
|
798
777
|
const emitter = new WireEmitter();
|
|
799
778
|
const parser = new PFMParser(emitter);
|
|
800
779
|
parser.init();
|
|
801
780
|
|
|
802
|
-
const dispatcher = new PluginDispatcher(
|
|
803
|
-
[plugin],
|
|
804
|
-
new WireTextSource([]),
|
|
805
|
-
);
|
|
781
|
+
const dispatcher = new PluginDispatcher([plugin], new WireTextSource([]));
|
|
806
782
|
const builder = new WireTreeBuilder(128, dispatcher);
|
|
807
783
|
|
|
808
|
-
let accumulated =
|
|
784
|
+
let accumulated = '';
|
|
809
785
|
for (let i = 0; i < source.length; i++) {
|
|
810
786
|
accumulated += source[i];
|
|
811
787
|
emitter.set_source(accumulated);
|
|
@@ -824,7 +800,7 @@ describe("parse plugins: wire path (WireEmitter → WireTreeBuilder)", () => {
|
|
|
824
800
|
|
|
825
801
|
// find paragraph
|
|
826
802
|
const para_idx = root.children.find(
|
|
827
|
-
(i: number) => buf.kind_at(i) === NodeKind.paragraph
|
|
803
|
+
(i: number) => buf.kind_at(i) === NodeKind.paragraph
|
|
828
804
|
)!;
|
|
829
805
|
const para = buf.get_node(para_idx);
|
|
830
806
|
|
|
@@ -832,7 +808,7 @@ describe("parse plugins: wire path (WireEmitter → WireTreeBuilder)", () => {
|
|
|
832
808
|
expect(para.children.length).toBe(1);
|
|
833
809
|
const link_idx = para.children[0];
|
|
834
810
|
expect(buf.kind_at(link_idx)).toBe(NodeKind.link);
|
|
835
|
-
expect(buf.metadata_at(link_idx)?.href).toBe(
|
|
811
|
+
expect(buf.metadata_at(link_idx)?.href).toBe('#wrapped');
|
|
836
812
|
|
|
837
813
|
// the link should contain: text "This ", strong "works", text " fine"
|
|
838
814
|
const link = buf.get_node(link_idx);
|
|
@@ -843,31 +819,28 @@ describe("parse plugins: wire path (WireEmitter → WireTreeBuilder)", () => {
|
|
|
843
819
|
expect(buf.kind_at(link.children[2])).toBe(NodeKind.text);
|
|
844
820
|
});
|
|
845
821
|
|
|
846
|
-
it(
|
|
822
|
+
it('cross-node wrap_inner redirect is cleaned up on revocation', () => {
|
|
847
823
|
// if the handler node is revoked, the cross-node wrap_inner
|
|
848
824
|
// should be undone and the redirect removed.
|
|
849
825
|
const plugin: ParsePlugin = {
|
|
850
826
|
strong_emphasis: {
|
|
851
827
|
parse(node) {
|
|
852
|
-
node.parent?.wrap_inner(
|
|
828
|
+
node.parent?.wrap_inner('link', { href: '#wrapped' });
|
|
853
829
|
},
|
|
854
830
|
},
|
|
855
831
|
};
|
|
856
832
|
|
|
857
833
|
// "*hello\n\n", strong_emphasis is revoked (unclosed)
|
|
858
|
-
const source =
|
|
834
|
+
const source = '*hello\n\n';
|
|
859
835
|
|
|
860
836
|
const emitter = new WireEmitter();
|
|
861
837
|
const parser = new PFMParser(emitter);
|
|
862
838
|
parser.init();
|
|
863
839
|
|
|
864
|
-
const dispatcher = new PluginDispatcher(
|
|
865
|
-
[plugin],
|
|
866
|
-
new WireTextSource([]),
|
|
867
|
-
);
|
|
840
|
+
const dispatcher = new PluginDispatcher([plugin], new WireTextSource([]));
|
|
868
841
|
const builder = new WireTreeBuilder(128, dispatcher);
|
|
869
842
|
|
|
870
|
-
let accumulated =
|
|
843
|
+
let accumulated = '';
|
|
871
844
|
for (let i = 0; i < source.length; i++) {
|
|
872
845
|
accumulated += source[i];
|
|
873
846
|
emitter.set_source(accumulated);
|
|
@@ -887,10 +860,7 @@ describe("parse plugins: wire path (WireEmitter → WireTreeBuilder)", () => {
|
|
|
887
860
|
// no link wrapper should remain in the tree
|
|
888
861
|
let found_link = false;
|
|
889
862
|
for (let i = 0; i < buf.size; i++) {
|
|
890
|
-
if (
|
|
891
|
-
buf.kind_at(i) === NodeKind.link &&
|
|
892
|
-
buf._parents[i] !== 0xffffffff
|
|
893
|
-
) {
|
|
863
|
+
if (buf.kind_at(i) === NodeKind.link && buf.parent_at(i) !== 0xffffffff) {
|
|
894
864
|
found_link = true;
|
|
895
865
|
}
|
|
896
866
|
}
|
|
@@ -898,7 +868,7 @@ describe("parse plugins: wire path (WireEmitter → WireTreeBuilder)", () => {
|
|
|
898
868
|
|
|
899
869
|
// paragraph should have text children directly (no wrapper)
|
|
900
870
|
const para_idx = root.children.find(
|
|
901
|
-
(i: number) => buf.kind_at(i) === NodeKind.paragraph
|
|
871
|
+
(i: number) => buf.kind_at(i) === NodeKind.paragraph
|
|
902
872
|
)!;
|
|
903
873
|
expect(para_idx).toBeDefined();
|
|
904
874
|
const para = buf.get_node(para_idx);
|