处理<pre><code> in contenteditable elements

时间:2018-09-22 22:36:03

标签: javascript

I'm building a little content editor in one of my webpage.

This editor would allow users to insert and edit code blocks, put between <pre><code> tags.

Here's my issue: when I create a pre + code element, when the user press enter, the styling is forwarded to the new line.

I want either:

  • The pre + code tags not to be forwarded when pressing enter

  • The possibility to remove both <pre><code> tags — I've tried to create an "erase" button, that would launch document.execCommand("formatBlock", false, "div"), but it only "erases" the pre tag, and keeps the code (so the line is still in a code tag).

Here's a fiddle that shows this: https://jsfiddle.net/colinfay/xpvt214o/839588/

Any help would be welcome.

0 个答案:

没有答案