0

I have got a question on how to customize serialization. For my current project, I need to insert html into the editor with custom <style> tags included. I would like to include const testHTMLString = `<a href="test.com" target="_blank" style="color:red;" >Test link</a>` into lexical editor while keeping the styles.

So my question is: Can I somehow keep the inline styles or code some workaround when doing insertNodes?

I have followed this guide: Serialization: HTML -> Lexical

My procedure: My parsed DOM looks like this...

<head></head><body><a href="test.com" target="_blank" style="color:red;">Test link</a></body>

... and gets translated into the following node:

{
  "__type": "link",
  "__parent": "root",
  "__key": "2",
  "__children": [
    "3"
  ],
  "__format": 0,
  "__indent": 0,
  "__dir": null,
  "__url": "test.com",
  "__target": "_blank",
  // NO __styles whatsoever here, which I need!
  "__rel": null
}

My expectation: Lexical editor showing text in red color.

My outcome: Text styled as default link styling in blue color.

enter image description here

0 Answers0