test that makes regexp replacement fail in footnote (non-leaf atom) #6

Merged
massifrg merged 1 commit from dev into main 2024-07-14 18:28:26 +02:00
massifrg commented 2024-07-12 17:32:14 +02:00 (Migrated from github.com)

(This is not really a PR, at least not in this form, but it seemed the best way to show you my code)

I made a test that shows a failure of replaceCurrent in a footnote (non-leaf inline atom node).

I made also a counter-test that shows that the same search does not fail in a normal paragraph node.

I observed it first in my code, where I'm using an adapted version of prosemirror-search, because I use prosemirror through tiptap, and there's no prosemirror-search in tiptap yet.

So I had to understand whether it was my code's fault.

BTW, I had to make a builder for the footnote node, because prosemirror-test-builder is based on schema-basic.
If you plan to include it in prosemirror-test-builder, I can contribute a code stub as a PR, leaving the refinements to you.

(This is not really a PR, at least not in this form, but it seemed the best way to show you my code) I made a test that shows a failure of [replaceCurrent](https://github.com/ProseMirror/prosemirror-search/blob/91463ed1b1e9e166688f6cb186e968e9dcacc3e7/src/search.ts#L173) in a footnote (non-leaf inline atom node). I made also a counter-test that shows that the same search does not fail in a normal paragraph node. I observed it first in my code, where I'm using an adapted version of prosemirror-search, because I use prosemirror through tiptap, and there's no prosemirror-search in tiptap yet. So I had to understand whether it was my code's fault. BTW, I had to make a builder for the footnote node, because prosemirror-test-builder is based on schema-basic. If you plan to include it in prosemirror-test-builder, I can contribute a code stub as a PR, leaving the refinements to you.
marijnh commented 2024-07-14 18:28:58 +02:00 (Migrated from github.com)

Thanks for the test case! Attached patch should help.

Thanks for the test case! Attached patch should help.
massifrg commented 2024-07-15 11:59:20 +02:00 (Migrated from github.com)

Thank you @marijnh.

Unfortunately my use case is nastier, because my footnotes don't contain text, but blocks (in Pandoc's internal model, a Note contains Blocks). So the footnote spec should be:

{
        group: "inline",
        content: "block*",
        inline: true,
        atom: true,
        toDOM: () => ["footnote", 0],
        parseDOM: [{tag: "footnote"}]
      }

I'm playing a bit with the code to see if I can make it work.

I saw your patch goes up one level of depth if the $from.node is an inline.
In my case I have a paragraph, that contains a footnote (inline atom with content), that contains a block (say a paragraph), that contains inlines, where the text to be replaced lives.

The case you patched is:

paragraph, isInline == false
footnote, isInline == true
text, isInline == true

My nastier case is:

paragraph, isInline == false
footnote, isInline == true
paragraph, isInline == false
text, isInline == true
Thank you @marijnh. Unfortunately my use case is nastier, because my footnotes don't contain text, but blocks (in Pandoc's internal model, a `Note` contains `Block`s). So the footnote spec should be: ```ts { group: "inline", content: "block*", inline: true, atom: true, toDOM: () => ["footnote", 0], parseDOM: [{tag: "footnote"}] } ``` I'm playing a bit with the code to see if I can make it work. I saw your patch goes up one level of depth if the `$from.node` is an inline. In my case I have a paragraph, that contains a footnote (inline atom with content), that contains a block (say a paragraph), that contains inlines, where the text to be replaced lives. The case you patched is: ``` paragraph, isInline == false footnote, isInline == true text, isInline == true ``` My nastier case is: ``` paragraph, isInline == false footnote, isInline == true paragraph, isInline == false text, isInline == true ```
massifrg commented 2024-07-15 12:07:44 +02:00 (Migrated from github.com)

Looks like I found a solution. PR is arriving...

Looks like I found a solution. PR is arriving...
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
prosemirror/prosemirror-search!6
No description provided.