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

prosemirrorToYXmlFragment losing <a> link around <img> tags #165

Open
bosschaert opened this issue Aug 16, 2024 · 0 comments
Open

prosemirrorToYXmlFragment losing <a> link around <img> tags #165

bosschaert opened this issue Aug 16, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@bosschaert
Copy link

bosschaert commented Aug 16, 2024

Describe the bug
When I pass prosemirrorToYXmlFragment a JSON representation of a HTML document that wraps an <img> with a <a> link tag, the link is dropped, which basically means that a clickable image that navigates elsewhere becomes just a static image.

To Reproduce
Execute the following code:

import { JSDOM } from 'jsdom';
import { DOMParser } from 'prosemirror-model';
import { schema as baseSchema } from 'prosemirror-schema-basic';
import { prosemirrorToYXmlFragment, yXmlFragmentToProseMirrorRootNode } from 'y-prosemirror';

...

const html = `
<body>
  <main><a href="www.yeehaa.com" title="abc"><img src="http://www.foo.com/myimg.jpg"></a></main>
</body>
`;
console.log('Input', html);

const ydoc = new Y.Doc();
const jsdom = new JSDOM(html);
const json = DOMParser.fromSchema(baseSchema).parse(jsdom.window.document);
console.log('Before', json.toString());
prosemirrorToYXmlFragment(json, ydoc.getXmlFragment('prosemirror'));
console.log('YDoc', ydoc.getXmlFragment('prosemirror').toJSON());

const json2 = yXmlFragmentToProseMirrorRootNode(ydoc.getXmlFragment('prosemirror'), baseSchema);
console.log('After', json2.toString());

This logs the following output:

Input 
<body>
  <main><a href="www.yeehaa.com" title="abc"><img src="http://www.foo.com/myimg.jpg"></a></main>
</body>

Before doc(paragraph(link(image)))

YDoc <paragraph><image src="http://www.foo.com/myimg.jpg"></image></paragraph>

After doc(paragraph(image))

We can see that the Before log message contains a link component, and the After log message doesn't, which is wrong. It can also be seen that the YDoc serialization is missing the link.

As a sanity check, if I change the HTML to the following, things work as expected:

Input 
<body>
  <main><a href="www.yeehaa.com" title="abc">blahblah</a></main>
</body>


Before doc(paragraph(link("blahblah")))

YDoc <paragraph><link href="www.yeehaa.com" title="abc">blahblah</link></paragraph>

After doc(paragraph(link("blahblah")))

Expected behavior
The link defined in the tag should not be disappearing.

Environment Information

  • Node.js - 21.7.1
  • y-prosemirror - 1.2.12
  • prose-mirror-model - 1.22.3
  • prosemirror-schema-basic - 1.2.3
  • yjs 13.6.18

This issue is possibly related to #138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants