How to unwrap editor DOM `pre` element?

I have a code syntax highlighting addon and want to add an editor button to toggle code highlighting.

How it works is the user selects some text and clicks the button, which either wraps it in <pre><code>..</code></code> or unwraps it. I implemented wrapping using document.execCommand("insertHTML", false, pre.outerHTML);, but I’m stuck on how to unwrap it.

The display page uses Svelte, so I can’t edit the DOM directly. What I’d like is a vanilla javascript function that takes the text selection from the editor and removes the parent <pre><code>..</code></pre> tags. I tried document.execCommand("removeFormat", false, null); but this doesn’t remove the <pre>..</pre> tag.

Any pointers? (I know nothing about Svelte.)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.