Skip to content

fix(richtext-lexical): fix picture closing tag in html converter #13100

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cdelacombaz
Copy link

Fixing invalid html from convertLexicalToHTML with UploadConverter

What?

When using the convertLexicalToHTML function to convert richtext into html, the resulting html is incorrect when an upload is present.

Why?

The error is within the UploadHTMLConverter, as you can see in my commits.

The picture closing tag has a Dollar sign in it </picture$>, which is invalid html. This results in the picture not closing at the right place. The picture element is not only wrapping the img tag, but also all following content of that richtext field.

I suppose that dollar sign ended up there due to auto rename tags from IDE.

import { convertLexicalToHTML } from "@payloadcms/richtext-lexical/html";
const html = convertLexicalToHTML({ data: content });

Example before fix

<div class="payload-richtext">
  <h2>Title</h2>
  <p>description</p>
  <picture>
      <img alt="media.png" height="400" src="https://some.url/storage/v1/object/public/media/media.png" width="684">
    <p>Some more text</p>
  </picture>
</div>

Example after fix

<div class="payload-richtext">
  <h2>Title</h2>
  <p>description</p>
  <picture>
      <img alt="media.png" height="400" src="https://some.url/storage/v1/object/public/media/media.png" width="684">
  </picture>
  <p>Some more text</p>
</div>

The picture closing tag has a Dollar sign in it. Probably due to auto rename tags from IDE ? When richtext is converted, the picture tag doesn't close at the right place, as it is incorrect html. Instead, the picture element wraps all other tags instead of only wrapping the img tag.
@cdelacombaz cdelacombaz requested a review from AlessioGr as a code owner July 9, 2025 09:47
@cdelacombaz cdelacombaz changed the title fix(richtext-lexical): Fix picture closing tag in html converter fix(richtext-lexical): fix picture closing tag in html converter Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant