Bug 201758 - Web Inspector: HTML Formatter - XML mode
Summary: Web Inspector: HTML Formatter - XML mode
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Joseph Pecoraro
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-09-13 02:21 PDT by Joseph Pecoraro
Modified: 2019-09-13 19:17 PDT (History)
4 users (show)

See Also:


Attachments
[PATCH] Proposed Fix (214.07 KB, patch)
2019-09-13 14:27 PDT, Joseph Pecoraro
hi: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2019-09-13 02:21:36 PDT
HTML Formatter - XML mode

- Handle CodeMirror "xml" mode.
- Turn off any of the HTML special casing in XML mode
Comment 1 Joseph Pecoraro 2019-09-13 14:27:30 PDT
Created attachment 378754 [details]
[PATCH] Proposed Fix

This makes me think maybe we should avoid indenting in CDATA...
Comment 2 Devin Rousso 2019-09-13 17:57:57 PDT
Comment on attachment 378754 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=378754&action=review

r=me, I thought that XML would be simple, but not this simple! :D

> Source/WebInspectorUI/UserInterface/Views/TextEditor.js:185
> +        return mode === "javascript" || mode === "css" || mode === "htmlmixed" || mode === "xml";

Just curious, which mode does SVG fall under?

> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLFormatter.js:28
> +    constructor(sourceText, mode, builder, indentString = "    ")

Can we name this `sourceType` to match the JSFormatter?

> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLFormatter.js:39
> +                let options = {xml: mode === HTMLFormatter.Mode.XML};

Style: given that this isn’t very “simple” (e.g. not just adding a key or remapping a variable) or “short” , I’d prefer this on multiple lines for readability.

> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLFormatter.js:120
> +            console.assert(false, "Unknown mode", mode);

I personally prefer putting these types of “not reached” outside of the switch-case altogether and in order to have it be less indented and therefore possibly more visible.

Also `mode` isn’t defined so this would throw an error :(

> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLParser.js:30
> +    parseDocument(sourceText, treeBuilder, {xml} = {})

`isXML`?

> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLParser.js:42
> +        this._xml = xml || false;

Rather than have a fallback, since we expect a boolean, can we just `!!isXML’`?

> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLTreeBuilderFormatter.js:37
> +    constructor({xml} = {})

Ditto

> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLTreeBuilderFormatter.js:39
> +        this._xml = xml || false;

Ditto
Comment 3 Joseph Pecoraro 2019-09-13 19:11:55 PDT
Comment on attachment 378754 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=378754&action=review

>> Source/WebInspectorUI/UserInterface/Views/TextEditor.js:185
>> +        return mode === "javascript" || mode === "css" || mode === "htmlmixed" || mode === "xml";
> 
> Just curious, which mode does SVG fall under?

If the MIME type is "image/svg+xml" then...

`htmlmixed`, but only because we special case it in CodeMirrorAdditions.js:

    var extraHTMLTypes = ["application/xhtml+xml", "image/svg+xml"];
    extraHTMLTypes.forEach(function(type) {
        CodeMirror.defineMIME(type, "htmlmixed");
    });

Otherwise I suspect it would have fallen to "application/xml" / "xml" in CodeMirror proper (codemirror.js):

    function resolveMode(spec) {
        ...
      } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
        return resolveMode("application/xml")
        ...
    }

>> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLFormatter.js:28
>> +    constructor(sourceText, mode, builder, indentString = "    ")
> 
> Can we name this `sourceType` to match the JSFormatter?

Nice! "mode" was getting overloaded.

>> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLFormatter.js:120
>> +            console.assert(false, "Unknown mode", mode);
> 
> I personally prefer putting these types of “not reached” outside of the switch-case altogether and in order to have it be less indented and therefore possibly more visible.
> 
> Also `mode` isn’t defined so this would throw an error :(

Nice

>> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLParser.js:30
>> +    parseDocument(sourceText, treeBuilder, {xml} = {})
> 
> `isXML`?

Sounds good, I debated this myself but though `_xml` read better. I'll change it to `_isXML` and likewise the option.

>> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLParser.js:42
>> +        this._xml = xml || false;
> 
> Rather than have a fallback, since we expect a boolean, can we just `!!isXML’`?

Sounds good.
Comment 4 Joseph Pecoraro 2019-09-13 19:16:35 PDT
https://trac.webkit.org/r249867
Comment 5 Radar WebKit Bug Importer 2019-09-13 19:17:20 PDT
<rdar://problem/55360465>
Comment 6 Radar WebKit Bug Importer 2019-09-13 19:17:21 PDT
<rdar://problem/55360466>