Refactor prohibited paragraph children a bit
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Tue, 31 May 2011 12:50:46 -0600
changeset 212 bc759ec88e62
parent 211 725c3edf27ce
child 213 4a5af8f2e33e
Refactor prohibited paragraph children a bit
editcommands.html
implementation.js
source.html
--- a/editcommands.html	Tue May 31 11:54:08 2011 -0600
+++ b/editcommands.html	Tue May 31 12:50:46 2011 -0600
@@ -38,7 +38,7 @@
 <body class=draft>
 <div class=head id=head>
 <h1>HTML Editing Commands</h1>
-<h2 class="no-num no-toc" id=work-in-progress-&mdash;-last-update-30-may-2011>Work in Progress &mdash; Last Update 30 May 2011</h2>
+<h2 class="no-num no-toc" id=work-in-progress-&mdash;-last-update-31-may-2011>Work in Progress &mdash; Last Update 31 May 2011</h2>
 <dl>
  <dt>Editor
  <dd>Aryeh Gregor &lt;ayg+spec@aryeh.name&gt;
@@ -376,13 +376,16 @@
 that editing commands will only modify the editing host's contents and not the
 editing host itself.
 
-<p>The <dfn id=prohibited-paragraph-children>prohibited paragraph children</dfn> are "address", "article",
+<p>A <dfn id=prohibited-paragraph-child-name>prohibited paragraph child name</dfn> is "address", "article",
 "aside", "blockquote", "center", "details", "dd", "dir", "div", "dl", "dt",
 "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4",
 "h5", "h6", "header", "hgroup", "hr", "li", "listing", "menu", "nav", "ol",
-"p", "plaintext", "pre", "section", "summary", "table", "ul", and "xmp".
-<!-- These are all the things that will close a <p> if found as a child.  I
-think. -->
+"p", "plaintext", "pre", "section", "summary", "table", "ul", or "xmp".
+
+<p>A <dfn id=prohibited-paragraph-child>prohibited paragraph child</dfn> is an <a href=#html-element>HTML element</a>
+whose <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-element-local-name title=concept-element-local-name>local name</a> is a <a href=#prohibited-paragraph-child-name>prohibited paragraph child name</a>.
+<!-- These are all the things that will close a <p> if found as a descendant.
+I think. -->
 
 <p>A <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-node title=concept-node>node</a> or string <var title="">child</var> is an <dfn id=allowed-child>allowed child</dfn> of a
 <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-node title=concept-node>node</a> or string <var title="">parent</var> if the following algorithm returns true:
@@ -444,9 +447,9 @@
     <a>foo<table><td><a>bar</a></td></table>baz</a>, but it's invalid in those
     cases too, so no need for complication. -->
 
-    <li>If <var title="">child</var> is one of the <a href=#prohibited-paragraph-children>prohibited paragraph
-    children</a> and <var title="">parent</var> or some <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-ancestor title=concept-tree-ancestor>ancestor</a> of
-    <var title="">parent</var> is a <code class=external data-anolis-spec=html title="the p element"><a href=http://www.whatwg.org/html/#the-p-element>p</a></code>, return false.
+    <li>If <var title="">child</var> is a <a href=#prohibited-paragraph-child-name>prohibited paragraph child name</a>
+    and <var title="">parent</var> or some <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-ancestor title=concept-tree-ancestor>ancestor</a> of <var title="">parent</var> is a <code class=external data-anolis-spec=html title="the p element"><a href=http://www.whatwg.org/html/#the-p-element>p</a></code>,
+    return false.
     <!-- This generally cannot be serialized either. -->
 
     <li>If <var title="">child</var> is "h1", "h2", "h3", "h4", "h5", or "h6", and
@@ -500,7 +503,7 @@
     <tr><td>h1, h2, h3, h4, h5, h6 <td>h1, h2, h3, h4, h5, h6
     <tr><td>li <td>li
     <tr><td>nobr <td>nobr
-    <tr><td>p <td>All <a href=#prohibited-paragraph-children>prohibited paragraph children</a>
+    <tr><td>p <td>All <a href=#prohibited-paragraph-child-name title="prohibited paragraph child name">prohibited paragraph child names</a>
     <tr><td>td, th <td>caption, col, colgroup, tbody, td, tfoot, th, thead, tr
   </table>
 
@@ -1019,9 +1022,8 @@
   <li>Let <var title="">start block</var> be the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-start title=concept-range-start>start</a> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-boundary-point-node title=concept-boundary-point-node>node</a> of
   <var title="">range</var>.
 
-  <li>While <var title="">start block</var> is not an <a href=#html-element>HTML element</a> or its
-  <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-element-local-name title=concept-element-local-name>local name</a> is not a <a href=#prohibited-paragraph-children title="prohibited paragraph children">prohibited
-  paragraph child</a>, set <var title="">start block</var> to its <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-parent title=concept-tree-parent>parent</a>.
+  <li>While <var title="">start block</var> is not a <a href=#prohibited-paragraph-child>prohibited paragraph
+  child</a>, set <var title="">start block</var> to its <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-parent title=concept-tree-parent>parent</a>.
 
   <p class=XXX>I'm uncertain about the use of prohibited paragraph children
   here.  I'm using it mostly because it's convenient and seems relatively
@@ -1030,9 +1032,8 @@
   <li>Let <var title="">end block</var> be the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-end title=concept-range-end>end</a> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-boundary-point-node title=concept-boundary-point-node>node</a> of
   <var title="">range</var>.
 
-  <li>While <var title="">end block</var> is not an <a href=#html-element>HTML element</a> or its
-  <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-element-local-name title=concept-element-local-name>local name</a> is not a <a href=#prohibited-paragraph-children title="prohibited paragraph children">prohibited
-  paragraph child</a>, set <var title="">end block</var> to its <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-parent title=concept-tree-parent>parent</a>.
+  <li>While <var title="">end block</var> is not a <a href=#prohibited-paragraph-child>prohibited paragraph
+  child</a>, set <var title="">end block</var> to its <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-parent title=concept-tree-parent>parent</a>.
 
   <li>Call <code class=external data-anolis-spec=domrange title=dom-Range-deleteContents><a href=http://html5.org/specs/dom-range.html#dom-range-deletecontents>deleteContents()</a></code> on <var title="">range</var>.
 
--- a/implementation.js	Tue May 31 11:54:08 2011 -0600
+++ b/implementation.js	Tue May 31 12:50:46 2011 -0600
@@ -828,18 +828,18 @@
 	// "Let start block be the start node of range."
 	var startBlock = range.startContainer;
 
-	// "While start block is not an HTML element or its local name is not a
-	// prohibited paragraph child, set start block to its parent."
-	while (!isHtmlElement(startBlock, prohibitedParagraphChildren)) {
+	// "While start block is not a prohibited paragraph child, set start block
+	// to its parent."
+	while (!isProhibitedParagraphChild(startBlock)) {
 		startBlock = startBlock.parentNode;
 	}
 
 	// "Let end block be the end node of range."
 	var endBlock = range.endContainer;
 
-	// "While end block is not an HTML element or its local name is not a
-	// prohibited paragraph child, set end block to its parent."
-	while (!isHtmlElement(endBlock, prohibitedParagraphChildren)) {
+	// "While end block is not a prohibited paragraph child, set end block to
+	// its parent."
+	while (!isProhibitedParagraphChild(endBlock)) {
 		endBlock = endBlock.parentNode;
 	}
 
@@ -972,17 +972,23 @@
 		&& getEditingHostOf(node1) == getEditingHostOf(node2);
 }
 
-// "The prohibited paragraph children are "address", "article", "aside",
+// "A prohibited paragraph child name is "address", "article", "aside",
 // "blockquote", "center", "details", "dd", "dir", "div", "dl", "dt",
 // "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3",
 // "h4", "h5", "h6", "header", "hgroup", "hr", "li", "listing", "menu", "nav",
-// "ol", "p", "plaintext", "pre", "section", "summary", "table", "ul", and
+// "ol", "p", "plaintext", "pre", "section", "summary", "table", "ul", or
 // "xmp"."
-var prohibitedParagraphChildren = ["address", "article", "aside", "blockquote",
-	"center", "details", "dd", "dir", "div", "dl", "dt", "fieldset",
-	"figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5",
-	"h6", "header", "hgroup", "hr", "li", "listing", "menu", "nav", "ol", "p",
-	"plaintext", "pre", "section", "summary", "table", "ul", "xmp"];
+var prohibitedParagraphChildNames = ["address", "article", "aside",
+	"blockquote", "center", "details", "dd", "dir", "div", "dl", "dt",
+	"fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3",
+	"h4", "h5", "h6", "header", "hgroup", "hr", "li", "listing", "menu", "nav",
+	"ol", "p", "plaintext", "pre", "section", "summary", "table", "ul", "xmp"];
+
+// "A prohibited paragraph child is an HTML element whose local name is a
+// prohibited paragraph child name."
+function isProhibitedParagraphChild(node) {
+	return isHtmlElement(node, prohibitedParagraphChildNames);
+}
 
 function isAllowedChild(child, parent_) {
 	// "If parent is "colgroup", "table", "tbody", "tfoot", "thead", "tr", or
@@ -1030,8 +1036,8 @@
 		// "If child is "a", and parent or some ancestor of parent is an a,
 		// return false."
 		//
-		// "If child is one of the prohibited paragraph children and parent or
-		// some ancestor of parent is a p, return false."
+		// "If child is a prohibited paragraph child name and parent or some
+		// ancestor of parent is a p, return false."
 		//
 		// "If child is "h1", "h2", "h3", "h4", "h5", or "h6", and parent or
 		// some ancestor of parent is an HTML element with local name "h1",
@@ -1041,7 +1047,7 @@
 			if (child == "a" && isHtmlElement(ancestor, "a")) {
 				return false;
 			}
-			if (prohibitedParagraphChildren.indexOf(child) != -1
+			if (prohibitedParagraphChildNames.indexOf(child) != -1
 			&& isHtmlElement(ancestor, "p")) {
 				return false;
 			}
@@ -1113,7 +1119,7 @@
 		[["h1", "h2", "h3", "h4", "h5", "h6"], ["h1", "h2", "h3", "h4", "h5", "h6"]],
 		[["li"], ["li"]],
 		[["nobr"], ["nobr"]],
-		[["p"], prohibitedParagraphChildren],
+		[["p"], prohibitedParagraphChildNames],
 		[["td", "th"], ["caption", "col", "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"]],
 	];
 	for (var i = 0; i < table.length; i++) {
--- a/source.html	Tue May 31 11:54:08 2011 -0600
+++ b/source.html	Tue May 31 12:50:46 2011 -0600
@@ -332,13 +332,16 @@
 that editing commands will only modify the editing host's contents and not the
 editing host itself.
 
-<p>The <dfn>prohibited paragraph children</dfn> are "address", "article",
+<p>A <dfn>prohibited paragraph child name</dfn> is "address", "article",
 "aside", "blockquote", "center", "details", "dd", "dir", "div", "dl", "dt",
 "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4",
 "h5", "h6", "header", "hgroup", "hr", "li", "listing", "menu", "nav", "ol",
-"p", "plaintext", "pre", "section", "summary", "table", "ul", and "xmp".
-<!-- These are all the things that will close a <p> if found as a child.  I
-think. -->
+"p", "plaintext", "pre", "section", "summary", "table", "ul", or "xmp".
+
+<p>A <dfn>prohibited paragraph child</dfn> is an <span>HTML element</span>
+whose [[localname]] is a <span>prohibited paragraph child name</span>.
+<!-- These are all the things that will close a <p> if found as a descendant.
+I think. -->
 
 <p>A [[node]] or string <var>child</var> is an <dfn>allowed child</dfn> of a
 [[node]] or string <var>parent</var> if the following algorithm returns true:
@@ -400,9 +403,9 @@
     <a>foo<table><td><a>bar</a></td></table>baz</a>, but it's invalid in those
     cases too, so no need for complication. -->
 
-    <li>If <var>child</var> is one of the <span>prohibited paragraph
-    children</span> and <var>parent</var> or some [[ancestor]] of
-    <var>parent</var> is a [[p]], return false.
+    <li>If <var>child</var> is a <span>prohibited paragraph child name</span>
+    and <var>parent</var> or some [[ancestor]] of <var>parent</var> is a [[p]],
+    return false.
     <!-- This generally cannot be serialized either. -->
 
     <li>If <var>child</var> is "h1", "h2", "h3", "h4", "h5", or "h6", and
@@ -456,7 +459,7 @@
     <tr><td>h1, h2, h3, h4, h5, h6 <td>h1, h2, h3, h4, h5, h6
     <tr><td>li <td>li
     <tr><td>nobr <td>nobr
-    <tr><td>p <td>All <span>prohibited paragraph children</span>
+    <tr><td>p <td>All <span title="prohibited paragraph child name">prohibited paragraph child names</span>
     <tr><td>td, th <td>caption, col, colgroup, tbody, td, tfoot, th, thead, tr
   </table>
 
@@ -989,9 +992,8 @@
   <li>Let <var>start block</var> be the [[rangestart]] [[bpnode]] of
   <var>range</var>.
 
-  <li>While <var>start block</var> is not an <span>HTML element</span> or its
-  [[localname]] is not a <span title="prohibited paragraph children">prohibited
-  paragraph child</span>, set <var>start block</var> to its [[parent]].
+  <li>While <var>start block</var> is not a <span>prohibited paragraph
+  child</span>, set <var>start block</var> to its [[parent]].
 
   <p class=XXX>I'm uncertain about the use of prohibited paragraph children
   here.  I'm using it mostly because it's convenient and seems relatively
@@ -1000,9 +1002,8 @@
   <li>Let <var>end block</var> be the [[rangeend]] [[bpnode]] of
   <var>range</var>.
 
-  <li>While <var>end block</var> is not an <span>HTML element</span> or its
-  [[localname]] is not a <span title="prohibited paragraph children">prohibited
-  paragraph child</span>, set <var>end block</var> to its [[parent]].
+  <li>While <var>end block</var> is not a <span>prohibited paragraph
+  child</span>, set <var>end block</var> to its [[parent]].
 
   <li>Call <code data-anolis-spec=domrange
   title=dom-Range-deleteContents>deleteContents()</code> on <var>range</var>.