RESOLVED FIXED201757
Web Inspector: HTML Formatter - better handling for HTML specific tag cases (<p>/<li>)
https://bugs.webkit.org/show_bug.cgi?id=201757
Summary Web Inspector: HTML Formatter - better handling for HTML specific tag cases (...
Joseph Pecoraro
Reported 2019-09-13 02:20:39 PDT
HTML Formatter - better handling for HTML specific tag cases (<p>/<li>) Cases like: <ul> <li>one <li>two <li>Three </ul> Or: <div> <p>Test <p>Test </div> Currently display poorly
Attachments
[PATCH] Proposed Fix (23.70 KB, patch)
2019-09-13 17:18 PDT, Joseph Pecoraro
no flags
[PATCH] Proposed Fix (23.71 KB, patch)
2019-09-13 19:21 PDT, Joseph Pecoraro
no flags
[PATCH] Proposed Fix (25.82 KB, patch)
2019-09-16 12:24 PDT, Joseph Pecoraro
hi: review+
Joseph Pecoraro
Comment 1 2019-09-13 17:18:29 PDT Comment hidden (obsolete)
Joseph Pecoraro
Comment 2 2019-09-13 19:21:52 PDT
Created attachment 378772 [details] [PATCH] Proposed Fix Unblocked.
Joseph Pecoraro
Comment 3 2019-09-13 19:24:15 PDT Comment hidden (obsolete)
Devin Rousso
Comment 4 2019-09-14 02:12:40 PDT Comment hidden (obsolete)
Joseph Pecoraro
Comment 5 2019-09-16 12:18:06 PDT
Comment on attachment 378766 [details] [PATCH] Proposed Fix View in context: https://bugs.webkit.org/attachment.cgi?id=378766&action=review >> Source/WebInspectorUI/ChangeLog:10 >> + Handle a closing tag with different text than the opening tag. > > When can this happen? Example `<div>Test</DIV>`. In HTML the opening div gets closed. In xml it is case sensitive so behaves differently. > Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLTreeBuilderFormatter.js:74 > + if (!this._xml) > + this._autoCloseHTMLNodesForOpenTag(parserNode, node); I actually suspect this can't happen because there is no parent to auto-close at this level. So I should be able to remove this. >> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLTreeBuilderFormatter.js:98 >> + containerNode = this._stackOfOpenElements[this._stackOfOpenElements.length - 1]; > > `this._stackOfOpenElements.lastValue`? Sure. FormatterWorker has WorkerUtilities.js which has "lastValue". I assumed Workers didn't have the Utilities.js equivalents! >> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLTreeBuilderFormatter.js:137 >> + _autoCloseHTMLNodesForOpenTag(parserNode, node) > > We only seem to use `node` for the `lowercaseName`. Could we just pass that in instead and make the signature slightly easier to read? I'd rather we pass both nodes since the nodes are the entire context. >> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLTreeBuilderFormatter.js:172 >> + this._autoCloseNodesExistingOpenTagWithName(["tr"], ["table"]); > > Shouldn’t this also close td/th too? Good point. I've made this like `optgroup`. First attempt to close a `tr` scoped to a `table`. If that did not close something, close `th`/`td` within the `table`. >> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLTreeBuilderFormatter.js:240 >> + for (let i = existingOpenTagIndex + 1; i < this._stackOfOpenElements.length; ++i) { > > Shouldn’t we be searching for nodes _before_ `existingOpenTagIndex`. I thought this was a stack, so wouldn’t the container node be at an earlier/smaller index? The efficient way to use an Array as a stack is to use the end of the stack as the top of the stack. `pop` is much cheaper than `unshift` since no elements in the array need to move on every operation. >> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLTreeBuilderFormatter.js:242 >> + console.assert(!this._xml); > > Can we move this assert outside? I wanted the assert next to the `lowercaseName` call so that it is obvious to anyone reading it that this lowercaseName call is okay because we are not XML. I'll move the assert and put a message in the assertion instead.
Joseph Pecoraro
Comment 6 2019-09-16 12:24:25 PDT
Created attachment 378877 [details] [PATCH] Proposed Fix
Radar WebKit Bug Importer
Comment 7 2019-09-16 12:31:51 PDT
Devin Rousso
Comment 8 2019-09-16 21:36:07 PDT
Comment on attachment 378877 [details] [PATCH] Proposed Fix View in context: https://bugs.webkit.org/attachment.cgi?id=378877&action=review r=me, nice work! > LayoutTests/inspector/formatting/resources/html-tests/auto-close-special.html:2 > +<head><title>Title</title> Can we omit the `</title>` to ensure that the `<body>` still closes the `<head>` even if there are other open tags "in between"? > Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLTreeBuilderFormatter.js:241 > + console.assert(!this._isXML, "Implicitly closing only happens in HTML. Also, names are compared case insensitively which would be invalid for XML"); NIT: missing "." at the end :(
Joseph Pecoraro
Comment 9 2019-09-17 11:37:38 PDT
Note You need to log in before you can comment on or make changes to this bug.