I'm building a contenteditable editor which involves multiple rows of contenteditable divs
I want to turn this:
Lorem <b>Ipsum</b><b> Dolor</b> Sit Amet
into this:
Lorem <b>Ipsum Dolor</b> Sit Amet
I'm building a contenteditable editor which involves multiple rows of contenteditable divs
I want to turn this:
Lorem <b>Ipsum</b><b> Dolor</b> Sit Amet
into this:
Lorem <b>Ipsum Dolor</b> Sit Amet
For further actions, you may consider blocking this person and/or reporting abuse
David Ruiz -
Hakkı Cengiz -
Abhishek Kumar -
Fenriuz -
Once suspended, itsarnavb will not be able to comment or publish posts until their suspension is removed.
Once unsuspended, itsarnavb will be able to comment and publish posts again.
Once unpublished, all posts by itsarnavb will become hidden and only accessible to themselves.
If itsarnavb is not suspended, they can still re-publish their posts from their dashboard.
Once unpublished, this post will become invisible to the public and only accessible to Arnav Bansal.
They can still re-publish the post if they are not suspended.
Thanks for keeping DEV Community safe. Here is what you can do to flag itsarnavb:
Unflagging itsarnavb will restore default visibility to their posts.
Top comments (8)
Using Regex to parse and manipulate HTML is a recipe for disaster. There are too many edge cases you have to account for.
If you really want to "optimize" the HTML, you may end up having to parse HTML into some kind of AST and work from there. But this is probably more complex than the editor itself you want to build.
But parsing html with regex is fun...
Not as much as having dinner at home. ;)
Simply remove any occurence of "
</b><b>
":"Lorem <b>Ipsum</b><b> Dolor</b> Sit Amet".replace("</b><b>", "")
Would be good to do this in a regex that also looks for whitespace between the two tags.
I thought about that as well, but then you'd change the content (if only ever so slightly) for a trivial QoL improvement
If you use a capture group, you could put every bit of whitepace back.
Regardless of the Element, are you always going to see two elements together? More importantly what is the implications of not doing as you propose. If you can do no work that's counterintuitively better than fixing something that might not need a fix.