How to implement Lexical to HTML Converter on the server?

default discord avatar
iokl7 months ago
3

When going through the documentation at

https://payloadcms.com/docs/rich-text/lexical

. There is a line saying: "The lexicalHTML() function creates a new field that automatically converts the referenced lexical richText field into HTML through an afterRead hook."



I'm not sure how to interpret the statement. Does it mean


1. I need to implement a serialization mechanism in

afterRead

.


2. Or, Payload generates the content automatically.



Currently, what I see is this in the API call

nameOfYourRichTextField_html: ""

, meaning no HTML is generated. Am I missing something?

  • default discord avatar
    fanki19957 months ago

    You can use it in your collection as a field. You don't have to write a hook for it.


    But I guess you can't use it in a group, array or collapsible.

  • discord user avatar
    alessiogr
    7 months ago
    through an afterRead hook.

    That just means that behind-the-back, this lexicalHTML feature uses an afterRead hook. It's added automatically, so no action required from your side!



    Only thing you have to do is to make sure that the first argument in the lexicalHTML function matches the field name



    Might not work if the richtext field is in a group/array yet, that's true. Will have to look into that

  • default discord avatar
    iokl7 months ago

    Yes, my rich text is in a group. When I have time, I will play around with the implementation and open a GH issue if needed. In the meantime, I use the front end serializer as it has been working well since Slate.



    The issue for this was opened on GitHub, so I will close this thread:

    https://github.com/payloadcms/payload/issues/4034

    .

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.