Breaking out and/or removing a paragraph in a contenteditable block
I have recently been playing with contenteditable quite a lot. I've knocked up a simple editor prototype which I'm fairly happy with. There is one thing that's puzzling me.
If I have a paragraph and my cursor (caret) is inside it like so:
<p>some text |</p>
How do I break out of the paragraph? Is there a key combination or a execCommand that can be used to break out of it开发者_运维问答 on the next line?
If I place the cursor (caret) at the end of the paragraph and press enter a new empty p
tag is generated. This is fine normally when writing text blocks. But say I want to insert an image or codeblock. I don't want this to be inside a p
tag but I can't see a way to break out.
I've tried highlighting the whole p block and then use:
document.execCommand('removeFormat', false, null);
Which works for other inline formatting (e.g. bold) but doesn't do anything in this case.
Here is a JsFiddle example, that might make more sense.
Thanks
精彩评论