Changeset 249969 in webkit
- Timestamp:
- Sep 17, 2019, 11:37:07 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 10 added
- 14 edited
- 2 moved
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/inspector/formatting/formatting-html-expected.txt (modified) (2 diffs)
-
LayoutTests/inspector/formatting/formatting-html.html (modified) (2 diffs)
-
LayoutTests/inspector/formatting/formatting-xml-expected.txt (modified) (1 diff)
-
LayoutTests/inspector/formatting/formatting-xml.html (modified) (1 diff)
-
LayoutTests/inspector/formatting/resources/html-tests/auto-close-normal-expected.html (moved) (moved from trunk/LayoutTests/inspector/formatting/resources/html-tests/auto-close-expected.html )
-
LayoutTests/inspector/formatting/resources/html-tests/auto-close-normal.html (moved) (moved from trunk/LayoutTests/inspector/formatting/resources/html-tests/auto-close.html )
-
LayoutTests/inspector/formatting/resources/html-tests/auto-close-special-expected.html (added)
-
LayoutTests/inspector/formatting/resources/html-tests/auto-close-special.html (added)
-
LayoutTests/inspector/formatting/resources/html-tests/list-expected.html (modified) (1 diff)
-
LayoutTests/inspector/formatting/resources/html-tests/list.html (modified) (1 diff)
-
LayoutTests/inspector/formatting/resources/html-tests/not-well-formed-1-expected.html (modified) (1 diff)
-
LayoutTests/inspector/formatting/resources/html-tests/not-well-formed-1.html (modified) (1 diff)
-
LayoutTests/inspector/formatting/resources/html-tests/p-expected.html (added)
-
LayoutTests/inspector/formatting/resources/html-tests/p.html (added)
-
LayoutTests/inspector/formatting/resources/html-tests/table-expected.html (added)
-
LayoutTests/inspector/formatting/resources/html-tests/table.html (added)
-
LayoutTests/inspector/formatting/resources/html-tests/tag-case-expected.html (added)
-
LayoutTests/inspector/formatting/resources/html-tests/tag-case.html (added)
-
LayoutTests/inspector/formatting/resources/xml-tests/tag-case-expected.xml (added)
-
LayoutTests/inspector/formatting/resources/xml-tests/tag-case.xml (added)
-
LayoutTests/inspector/formatting/resources/xml-tests/valid-html-invalid-xml-expected.xml (modified) (1 diff)
-
LayoutTests/inspector/formatting/resources/xml-tests/valid-html-invalid-xml.xml (modified) (1 diff)
-
Source/WebInspectorUI/ChangeLog (modified) (1 diff)
-
Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLFormatter.js (modified) (1 diff)
-
Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLTreeBuilderFormatter.js (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r249963 r249969 1 2019-09-17 Joseph Pecoraro <pecoraro@apple.com> 2 3 Web Inspector: HTML Formatter - better handling for HTML specific tag cases (<p>/<li>) 4 https://bugs.webkit.org/show_bug.cgi?id=201757 5 <rdar://problem/55409987> 6 7 Reviewed by Devin Rousso. 8 9 * inspector/formatting/formatting-html-expected.txt: 10 * inspector/formatting/formatting-html.html: 11 * inspector/formatting/resources/html-tests/auto-close-normal-expected.html: Renamed from LayoutTests/inspector/formatting/resources/html-tests/auto-close-expected.html. 12 * inspector/formatting/resources/html-tests/auto-close-normal.html: Renamed from LayoutTests/inspector/formatting/resources/html-tests/auto-close.html. 13 * inspector/formatting/resources/html-tests/auto-close-special-expected.html: Added. 14 * inspector/formatting/resources/html-tests/auto-close-special.html: Added. 15 * inspector/formatting/resources/html-tests/list-expected.html: 16 * inspector/formatting/resources/html-tests/list.html: 17 * inspector/formatting/resources/html-tests/not-well-formed-1-expected.html: 18 * inspector/formatting/resources/html-tests/not-well-formed-1.html: 19 * inspector/formatting/resources/html-tests/p-expected.html: Added. 20 * inspector/formatting/resources/html-tests/p.html: Added. 21 * inspector/formatting/resources/html-tests/table-expected.html: Added. 22 * inspector/formatting/resources/html-tests/table.html: Added. 23 * inspector/formatting/resources/html-tests/tag-case-expected.html: Added. 24 * inspector/formatting/resources/html-tests/tag-case.html: Added. 25 Tests for HTML specialties. 26 27 * inspector/formatting/formatting-xml-expected.txt: 28 * inspector/formatting/formatting-xml.html: 29 * inspector/formatting/resources/xml-tests/tag-case-expected.xml: Added. 30 * inspector/formatting/resources/xml-tests/tag-case.xml: Added. 31 * inspector/formatting/resources/xml-tests/valid-html-invalid-xml-expected.xml: 32 * inspector/formatting/resources/xml-tests/valid-html-invalid-xml.xml: 33 XML is case-sensitive. Ensure XML doesn't get more of the HTML specialties. 34 1 35 2019-09-17 Antti Koivisto <antti@apple.com> 2 36 -
trunk/LayoutTests/inspector/formatting/formatting-html-expected.txt
r249866 r249969 5 5 -- Running test case: HTMLFormatter 6 6 PASS: attributes.html 7 PASS: auto-close.html 7 PASS: auto-close-normal.html 8 PASS: auto-close-special.html 8 9 PASS: basic-1.html 9 10 PASS: basic-2.html … … 24 25 PASS: not-well-formed-2.html 25 26 PASS: not-well-formed-3.html 27 PASS: p.html 26 28 PASS: self-closing.html 29 PASS: table.html 30 PASS: tag-case.html 27 31 -
trunk/LayoutTests/inspector/formatting/formatting-html.html
r249866 r249969 11 11 addFormattingTests(suite, "text/html", [ 12 12 "resources/html-tests/attributes.html", 13 "resources/html-tests/auto-close.html", 13 "resources/html-tests/auto-close-normal.html", 14 "resources/html-tests/auto-close-special.html", 14 15 "resources/html-tests/basic-1.html", 15 16 "resources/html-tests/basic-2.html", … … 30 31 "resources/html-tests/not-well-formed-2.html", 31 32 "resources/html-tests/not-well-formed-3.html", 33 "resources/html-tests/p.html", 32 34 "resources/html-tests/self-closing.html", 35 "resources/html-tests/table.html", 36 "resources/html-tests/tag-case.html", 33 37 ]); 34 38 -
trunk/LayoutTests/inspector/formatting/formatting-xml-expected.txt
r249867 r249969 7 7 PASS: basic.xml 8 8 PASS: rss.xml 9 PASS: tag-case.xml 9 10 PASS: valid-html-invalid-xml.xml 10 11 PASS: xslt.xml -
trunk/LayoutTests/inspector/formatting/formatting-xml.html
r249867 r249969 13 13 "resources/xml-tests/basic.xml", 14 14 "resources/xml-tests/rss.xml", 15 "resources/xml-tests/tag-case.xml", 15 16 "resources/xml-tests/valid-html-invalid-xml.xml", 16 17 "resources/xml-tests/xslt.xml", -
trunk/LayoutTests/inspector/formatting/resources/html-tests/list-expected.html
r249831 r249969 11 11 12 12 <ul> 13 <li>One 14 <li>Two 15 <li>Three 16 </ul> 17 <ol> 18 <li>One 19 <li>Two 20 <li>Three 21 </ol> 22 23 <!-- Nested --> 24 <ol> 13 25 <li> 14 One 15 <li> 16 Two 17 <li>Three 26 <ul> 27 <li>1 28 <li>2 29 </ul> 30 <li>Test 31 </ol> 32 <ul> 33 <li> 34 <ol> 35 <li>1 36 <li>2 37 </ol> 38 <li>Test 18 39 </ul> 19 40 <ol> 20 41 <li> 21 One 22 <li> 23 Two 24 <li>Three 42 <ol> 43 <li>1 44 <li>2 45 </ol> 46 <li>Test 25 47 </ol> 48 <ul> 49 <li> 50 <ul> 51 <li>1 52 <li>2 53 </ul> 54 <li>Test 55 </ul> -
trunk/LayoutTests/inspector/formatting/resources/html-tests/list.html
r249831 r249969 4 4 <ul><li>One<li>Two<li>Three</ul> 5 5 <ol><li>One<li>Two<li>Three</ol> 6 7 <!-- Nested --> 8 <ol><li><ul><li>1<li>2</ul><li>Test</ol> 9 <ul><li><ol><li>1<li>2</ol><li>Test</ul> 10 <ol><li><ol><li>1<li>2</ol><li>Test</ol> 11 <ul><li><ul><li>1<li>2</ul><li>Test</ul> -
trunk/LayoutTests/inspector/formatting/resources/html-tests/not-well-formed-1-expected.html
r249831 r249969 1 < p>1 <x> 2 2 </br> 3 < p>Test</p>3 <x>Test</x> -
trunk/LayoutTests/inspector/formatting/resources/html-tests/not-well-formed-1.html
r249831 r249969 1 < p></br><p>Test</p>1 <x></br><x>Test</x> -
trunk/LayoutTests/inspector/formatting/resources/xml-tests/valid-html-invalid-xml-expected.xml
r249867 r249969 2 2 <img src="1"> 3 3 <img src="2"> 4 <ol> 5 <li> 6 One 7 <li> 8 Two 9 <li>Three 10 </ol> 4 11 </outer> -
trunk/LayoutTests/inspector/formatting/resources/xml-tests/valid-html-invalid-xml.xml
r249867 r249969 1 <outer><img src="1"><img src="2"></outer> 1 <outer> 2 <img src="1"><img src="2"> 3 <ol><li>One<li>Two<li>Three</ol> 4 </outer> -
trunk/Source/WebInspectorUI/ChangeLog
r249867 r249969 1 2019-09-17 Joseph Pecoraro <pecoraro@apple.com> 2 3 Web Inspector: HTML Formatter - better handling for HTML specific tag cases (<p>/<li>) 4 https://bugs.webkit.org/show_bug.cgi?id=201757 5 <rdar://problem/55409987> 6 7 Reviewed by Devin Rousso. 8 9 * UserInterface/Workers/Formatter/HTMLFormatter.js: 10 (HTMLFormatter.prototype._after): 11 Handle a closing tag with different text than the opening tag. 12 13 * UserInterface/Workers/Formatter/HTMLTreeBuilderFormatter.js: 14 (HTMLTreeBuilderFormatter.prototype._pushParserNodeTopLevel): 15 (HTMLTreeBuilderFormatter.prototype._pushParserNodeStack): 16 (HTMLTreeBuilderFormatter.prototype._implicitlyCloseHTMLNodesForOpenTag): 17 (HTMLTreeBuilderFormatter.prototype._implicitlyCloseTagNamesInsideParentTagNames): 18 (HTMLTreeBuilderFormatter.prototype._indexOfStackNodeMatchingTagNames): 19 Generalize the implicit closing a bit. Allow open tags to implicitly 20 close certain other open tags in the stack. 21 1 22 2019-09-13 Joseph Pecoraro <pecoraro@apple.com> 2 23 -
trunk/Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLFormatter.js
r249867 r249969 290 290 } 291 291 if (!node.implicitClose) { 292 console.assert(node.closeTagName); 292 293 console.assert(node.closeTagPos); 293 this._builder.appendToken("</" + node. name + ">", node.closeTagPos);294 this._builder.appendToken("</" + node.closeTagName + ">", node.closeTagPos); 294 295 } 295 296 this._builder.appendNewline(); -
trunk/Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLTreeBuilderFormatter.js
r249867 r249969 25 25 26 26 // This tree builder attempts to match input text to output DOM node. 27 // This therefore doesn't do HTML5 tree construction like auto-closing27 // This therefore doesn't do HTML5 tree construction like implicitly-closing 28 28 // specific HTML parent nodes depending on being in a particular node, 29 // it only does basic auto-closing. In general this tries to be a29 // it only does basic implicitly-closing. In general this tries to be a 30 30 // whitespace reformatter for input text and not generate the ultimate 31 31 // html tree that a browser would generate. … … 52 52 pushParserNode(parserNode) 53 53 { 54 let containerNode = this._stackOfOpenElements [this._stackOfOpenElements.length - 1];54 let containerNode = this._stackOfOpenElements.lastValue; 55 55 if (!containerNode) 56 56 this._pushParserNodeTopLevel(parserNode); … … 91 91 if (parserNode.type === HTMLParser.NodeType.OpenTag) { 92 92 let node = this._buildDOMNodeFromOpenTag(parserNode); 93 containerNode.children.push(node); 93 let childrenArray = containerNode.children; 94 if (!this._isXML) { 95 this._implicitlyCloseHTMLNodesForOpenTag(parserNode, node); 96 containerNode = this._stackOfOpenElements.lastValue; 97 childrenArray = containerNode ? containerNode.children : this._dom; 98 } 99 childrenArray.push(node); 94 100 if (!this._isEmptyNode(parserNode, node)) 95 101 this._stackOfOpenElements.push(node); … … 98 104 99 105 if (parserNode.type === HTMLParser.NodeType.CloseTag) { 100 let found = false; 101 let nodesToPop = 0; 102 for (let i = this._stackOfOpenElements.length - 1; i >= 0; --i) { 103 nodesToPop++; 104 let stackNode = this._stackOfOpenElements[i]; 105 if (stackNode.name === parserNode.name) { 106 found = true; 107 break; 106 let tagName = this._isXML ? parserNode.name : parserNode.name.toLowerCase(); 107 let matchingOpenTagIndex = this._indexOfStackNodeMatchingTagNames([tagName]); 108 109 // Found a matching tag, implicitly-close nodes. 110 if (matchingOpenTagIndex !== -1) { 111 let nodesToPop = this._stackOfOpenElements.length - matchingOpenTagIndex; 112 for (let i = 0; i < nodesToPop - 1; ++i) { 113 let implicitlyClosingNode = this._stackOfOpenElements.pop(); 114 implicitlyClosingNode.implicitClose = true; 108 115 } 109 } 110 111 // Found a matching tag, auto-close nodes. 112 if (found) { 113 console.assert(nodesToPop > 0); 114 for (let i = 0; i < nodesToPop - 1; ++i) { 115 let autoClosingNode = this._stackOfOpenElements.pop(); 116 autoClosingNode.implicitClose = true; 116 let implicitlyClosingNode = this._stackOfOpenElements.pop(); 117 if (parserNode.pos) { 118 implicitlyClosingNode.closeTagPos = parserNode.pos; 119 implicitlyClosingNode.closeTagName = parserNode.name; 117 120 } 118 let autoClosingNode = this._stackOfOpenElements.pop();119 if (parserNode.pos)120 autoClosingNode.closeTagPos = parserNode.pos;121 121 return; 122 122 } … … 131 131 let node = this._buildSimpleNodeFromParserNode(parserNode); 132 132 containerNode.children.push(node); 133 } 134 135 _implicitlyCloseHTMLNodesForOpenTag(parserNode, node) 136 { 137 if (parserNode.closed) 138 return; 139 140 switch (node.lowercaseName) { 141 // <body> closes <head>. 142 case "body": 143 this._implicitlyCloseTagNamesInsideParentTagNames(["head"]); 144 break; 145 146 // Inside <select>. 147 case "option": 148 this._implicitlyCloseTagNamesInsideParentTagNames(["option"], ["select"]); 149 break; 150 case "optgroup": { 151 let didClose = this._implicitlyCloseTagNamesInsideParentTagNames(["optgroup"], ["select"]);; 152 if (!didClose) 153 this._implicitlyCloseTagNamesInsideParentTagNames(["option"], ["select"]); 154 break; 155 } 156 157 // Inside <ol>/<ul>. 158 case "li": 159 this._implicitlyCloseTagNamesInsideParentTagNames(["li"], ["ol", "ul"]); 160 break; 161 162 // Inside <dl>. 163 case "dd": 164 case "dt": 165 this._implicitlyCloseTagNamesInsideParentTagNames(["dd", "dt"], ["dl"]); 166 break; 167 168 // Inside <table>. 169 case "tr": { 170 let didClose = this._implicitlyCloseTagNamesInsideParentTagNames(["tr"], ["table"]); 171 if (!didClose) 172 this._implicitlyCloseTagNamesInsideParentTagNames(["td", "th"], ["table"]); 173 break; 174 } 175 case "td": 176 case "th": 177 this._implicitlyCloseTagNamesInsideParentTagNames(["td", "th"], ["table"]); 178 break; 179 case "tbody": { 180 let didClose = this._implicitlyCloseTagNamesInsideParentTagNames(["thead"], ["table"]); 181 if (!didClose) 182 didClose = this._implicitlyCloseTagNamesInsideParentTagNames(["tr"], ["table"]); 183 break; 184 } 185 case "tfoot": { 186 let didClose = this._implicitlyCloseTagNamesInsideParentTagNames(["tbody"], ["table"]); 187 if (!didClose) 188 didClose = this._implicitlyCloseTagNamesInsideParentTagNames(["tr"], ["table"]); 189 break; 190 } 191 case "colgroup": 192 this._implicitlyCloseTagNamesInsideParentTagNames(["colgroup"], ["table"]); 193 break; 194 195 // Nodes that implicitly close a <p>. Normally this is only in <body> but we simplify to always. 196 // https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inbody 197 case "address": 198 case "article": 199 case "aside": 200 case "blockquote": 201 case "center": 202 case "details": 203 case "dialog": 204 case "dir": 205 case "div": 206 case "dl": 207 case "fieldset": 208 case "figcaption": 209 case "figure": 210 case "footer": 211 case "form": 212 case "h1": 213 case "h2": 214 case "h3": 215 case "h4": 216 case "h5": 217 case "h6": 218 case "header": 219 case "hgroup": 220 case "hr": 221 case "listing": 222 case "main": 223 case "menu": 224 case "nav": 225 case "ol": 226 case "p": 227 case "plaintext": 228 case "pre": 229 case "section": 230 case "summary": 231 case "table": 232 case "ul": 233 case "xmp": 234 this._implicitlyCloseTagNamesInsideParentTagNames(["p"]); 235 break; 236 } 237 } 238 239 _implicitlyCloseTagNamesInsideParentTagNames(tagNames, containerScopeTagNames) 240 { 241 console.assert(!this._isXML, "Implicitly closing only happens in HTML. Also, names are compared case insensitively which would be invalid for XML."); 242 243 let existingOpenTagIndex = this._indexOfStackNodeMatchingTagNames(tagNames); 244 if (existingOpenTagIndex === -1) 245 return false; 246 247 // Disallow impliticly closing beyond the container tag boundary. 248 if (containerScopeTagNames) { 249 for (let i = existingOpenTagIndex + 1; i < this._stackOfOpenElements.length; ++i) { 250 let stackNode = this._stackOfOpenElements[i]; 251 let name = stackNode.lowercaseName; 252 if (containerScopeTagNames.includes(name)) 253 return false; 254 } 255 } 256 257 // Implicitly close tags. 258 let nodesToPop = this._stackOfOpenElements.length - existingOpenTagIndex; 259 for (let i = 0; i < nodesToPop; ++i) { 260 let implicitlyClosingNode = this._stackOfOpenElements.pop(); 261 implicitlyClosingNode.implicitClose = true; 262 } 263 264 return true; 265 } 266 267 _indexOfStackNodeMatchingTagNames(tagNames) 268 { 269 for (let i = this._stackOfOpenElements.length - 1; i >= 0; --i) { 270 let stackNode = this._stackOfOpenElements[i]; 271 let name = this._isXML ? stackNode.name : stackNode.lowercaseName; 272 if (tagNames.includes(name)) 273 return i; 274 } 275 276 return -1; 133 277 } 134 278
Note:
See TracChangeset
for help on using the changeset viewer.