#Is it possible to add classes to the HTML that's g...
13 messages · Page 1 of 1 (latest)
Help is on the way! To mark it as solved, use the /solve command. In the meantime, here are some existing threads that may help you:
Documentation:
@weak ridge Is your goal to be able to style the HTML inside the editor itself? Or the html outputted if you convert it to html
My goal is to be able to style the outputted HTML
How are you outputting html currently?
I'm outputting the HTML from the collection using the HTMLCoverterFeature and the LexicalHTML field
In this case, if you want to add custom classes to the outputted html (or modify the outputted html in any way), you can add a custom HTML Converter for that node instead of using the one which is included by default
To do that, you are able to specify a list of your own, custom HTML converters in the props of HTMLConverterFeature({}),
You can re-use the default ones, then add your custom one at the end
HTMLConverterFeature({
converters: [
...consolidateHTMLConverters({ editorConfig }),
YourCustomConverterHere
]
})
Kinda like this
Ah I see. Thanks @karmic hull
You're welcome!
I think I could call this manually on a node too if I wanted instead of making it part of the collection config
For example if I had a custom endpoint and wanted to convert the node at the time I request the collection
Regarding the code I sent, forget what I sent, this would be better:
HTMLConverterFeature({
converters: ({ defaultConverters }) => [
...defaultConverters,
YourCustomConverterHere
]
})
I think I could call this manually on a node too if I wanted instead of making it part of the collection config
For example if I had a custom endpoint and wanted to convert the node at the time I request the collection
Sure, you absolutely can! You can also call the HTML converter manually (see https://payloadcms.com/docs/rich-text/lexical#creating-your-own-html-converter)
Adding a HTML Converter for that node would definitely be the easiest option though. HTML Converters are super simple - it's just a function which accepts the node as input, and returns the HTML string as output ^^