Excessive HTML output with formatted text.
I am working with lexical and needs to save output from it in html content to be slim as possible. I've extended TextNode as pointed in documentation (replaced strong -> b and em with i) and that works well.
What bother me is way how lexical handles node/tag wrapping as described below:
- Add some text to editor - > Lorem . Then we save content by using generateHtmlFromNodes that results in Lorem output
- Select whole word and add bold style to it ->
<b>Lorem</b>
and that is also correct 3. Problem appears when we want to style text further. Let's add italic to letter inside "r", then we get
<b>Lo</b><b><i>r</i></b><b>em</b>
. Thats excessive. Would it be better to be
<b>Lo<i>r</i>em</b>
? I've got same results with default TextNode implementation.
Is there a way to make output more compact?
Generally, I think this is as simple as it can be whilst avoiding bugs, especially when you have overlapping styles.
It introduces a lot of complexity to have to maintain a stack when recursing up and down a DOM tree, constantly checking to see if you're in a b tag or i tag. Having smaller ranges with fewer nested styles addresses some of those issues.
If you want to normalize and simplify the HTML afterwards, the user can do that themselves on export.
I've extended TextNode as pointed in documentation (replaced strong -> b and em with i) and that works well.
Can you please provide where exactly in the documentation, or maybe the steps to replace strong tag with b tag ?