[whatwg] Request for feedback: supported elements for formatBlock

Aryeh Gregor Simetrical+w3c at gmail.com
Mon May 23 14:37:10 PDT 2011


execCommand("formatBlock", false, "<foo>") has the effect of replacing
the block elements with the given tag.  For instance,
execCommand("formatBlock", false, "<p>") executed on <h1>foo</h1>
turns it into <p>foo</p>.  However, browsers vary in what elements
they accept as arguments, more or less as follows:

* Everyone supports address, div, h*, p, pre
* Everyone but IE supports blockquote
* Everyone but Opera supports dd, dt
* Only IE supports ol, ul
* Only Firefox and Chrome support dl
* Only Chrome supports article, aside, footer, header, hgroup, nav, section
* HTML5 mandates support for address, article, aside, blockquote, div,
footer, h*, header, hgroup, nav, p, pre, section (which is the same as
Chrome but minus dl/dt/dd)

The issue with all the non-IE browsers is that they support a bunch of
things that make sense to nest within one another, and formatBlock
doesn't work for nesting.  So for instance, if I do
execCommand("formatBlock", false, "blockquote") on
<p>foo</p><p>bar</p>, what's the result?  Firefox produces
<blockquote><p>foo</p><p>bar</p></blockquote>, Chrome produces
<blockquote>foo<br>bar</blockquote>, and Opera produces
<blockquote>foo</blockquote><blockquote>bar</blockquote>.

Firefox's output makes the most sense, but then formatBlock is no
longer toggling the block type, it's adding an extra wrapper to what
you already have.  Then how do you remove it?
execCommand("formatBlock", false, "p") does nothing, and
execCommand("formatBlock", false, "blockquote") nests another
blockquote.  You have to use outdent, but in that case, why didn't you
just use indent to start with?  And how would it generalize to things
like article or aside?  If formatBlock supported them in the way
Firefox supports blockquote, you could add them using execCommand()
but not remove them.

As for Chrome or Opera, their way of doing things might make sense in
some cases for blockquote, but usually you want the way indent behaves
instead.  If I select two paragraphs and want to put a blockquote
around them, normally I want a two-paragraph blockquote, not a
two-line blockquote or two blockquotes.  It doesn't make any sense at
all for things like article -- you want
<article><p>foo</p><p>bar</p></article>, not
<article>foo<br>bar</article> and certainly not
<article>foo</article><article>bar</article>.

So my current spec
<http://aryeh.name/gitweb.cgi?p=editcommands;a=blob_plain;f=editcommands.html;hb=4a898d7#the-formatblock-command>
supports only address, div, h*, p, and pre.  I don't think it makes
sense to support things like blockquote (or article, aside, etc.)
which are expected to have other block elements nested inside them.
Those should have separate commands (as should dl/dt/dd, probably).
But if anyone else feels otherwise, please say so.


More information about the whatwg mailing list