Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

customHTMLRenderer strangely broken in viewer (3.0.2) #3298

Open
lborgman opened this issue Feb 20, 2025 · 3 comments
Open

customHTMLRenderer strangely broken in viewer (3.0.2) #3298

lborgman opened this issue Feb 20, 2025 · 3 comments
Labels

Comments

@lborgman
Copy link

lborgman commented Feb 20, 2025

Describe the bug

In the editor customHTMLRenderer works as expected and gives this result for me:

<p>before <a href="mm4i-search:interesting" style="color:red">find</a> after</p>

But in the viewer I instead get this very strange result:

<p data-nodeid="7">before <a href="mm4i-search:interesting" style="color:red" data-nodeid="11"></a>find<a 
    href="mm4i-search:interesting" style="color:red" data-nodeid="11"></a> after</p>

The HTML code is copied directly from Developer tools in Google Chrome today (which I just updated).

To Reproduce

const mm4iRenderer = {
    link(node, context) {
        console.log({ node });
        const { origin } = context;
        const url = node.destination;
        const isAlfa = url.startsWith("mm4i-search:");
        console.warn("mm4iRenderer link", url, isAlfa);
        if (isAlfa) {
            const linkAttrs = { href: url };
            linkAttrs.style = "color:red";
            console.log("after red", linkAttrs);
            return [
                { type: 'openTag', tagName: 'a', attributes: linkAttrs },
                { type: 'closeTag', tagName: 'a' }
            ];
        }
        return origin();
    }
}

Expected behavior

See above.

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: chrome
  • Version: 3.0.2
@lborgman lborgman added the Bug label Feb 20, 2025
@lborgman
Copy link
Author

For the moment I will use a workaround:

  • use the editor instead
  • hide irrelevant parts
  • add a shield that takes care of pointerdown events

It looks like it is about 50 lines of code.

@lborgman
Copy link
Author

lborgman commented Feb 20, 2025

While implementing this I just saw something that might be relevant for the bug.
Searching the ww mode element there are three :

2: <a href="mm4i-search:interesting" style="color:red" data-nodeid="5"></a>
1: <a href="mm4i-search:interesting" style="color:red">find</a>

Two of them are those empty <a>:s I mentioned before.

This suggests to me there is a bug either in Prose-mirror or in Chromes handling of "contenteditable".

@lborgman
Copy link
Author

I decided not to use customHTMLRenderer. In my case I can get the same result with some CSS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant