W3C home > Mailing lists > Public > whatwg@whatwg.org > May 2011

[whatwg] Pressing Enter in contenteditable: <p> or <br> or <div>?

From: Markus Ernst <derernst@gmx.ch>
Date: Tue, 17 May 2011 09:26:59 +0200
Message-ID: <4DD22343.4080904@gmx.ch>
Am 13.05.2011 12:00 schrieb Michael A. Puls II:
> On Thu, 12 May 2011 16:28:47 -0400, Aryeh Gregor
> <Simetrical+w3c at gmail.com> wrote:
>> Another problem with <p> is that it's very easy to create
>> unserializable DOMs with it. I've seen cases where at least some
>> browsers will put things inside <p> that will break out of the <p>,
>> and I've done it myself by mistake too.
>
> I think the browser/editor just shouldn't allow that in this case. (Not
> saying that it's easy to enforce it though.)

As an author or CMS implementor I'd be happy to see UAs solve this for 
me, creating a valid sequence of paragraphs.

OTOH, if you use <div>s in order to keep the output serializable, this 
might lead to kind of messy code.

Imagine a content of the contenteditable element like:

<div><div><p>Foo</p></div></div>
<div><p>Bar</p></div>

The user puts the caret to the end of the first line and clicks Enter. 
With a strict <p>/<br> behavior, this is a well-defined action, adding a 
new paragraph resp. inserting a newline. But if you go with <div>s, this 
will possibly mess up the code in a way that is hard to fix (though it 
is valid and serializable HTML).
Received on Tuesday, 17 May 2011 00:26:59 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:33 UTC