Changeset 249867 in webkit
- Timestamp:
- Sep 13, 2019, 7:16:00 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 13 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r249866 r249867 1 2019-09-13 Joseph Pecoraro <pecoraro@apple.com> 2 3 Web Inspector: HTML Formatter - XML mode 4 https://bugs.webkit.org/show_bug.cgi?id=201758 5 6 Reviewed by Devin Rousso. 7 8 * inspector/formatting/formatting-xml-expected.txt: Added. 9 * inspector/formatting/formatting-xml.html: Added. 10 * inspector/formatting/resources/formatting-utilities.js: 11 (TestPage.registerInitializer.async.runFormattingTest): 12 * inspector/formatting/resources/xml-tests/atom-expected.xml: Added. 13 * inspector/formatting/resources/xml-tests/atom.xml: Added. 14 * inspector/formatting/resources/xml-tests/basic-expected.xml: Added. 15 * inspector/formatting/resources/xml-tests/basic.xml: Added. 16 * inspector/formatting/resources/xml-tests/rss-expected.xml: Added. 17 * inspector/formatting/resources/xml-tests/rss.xml: Added. 18 * inspector/formatting/resources/xml-tests/valid-html-invalid-xml-expected.xml: Added. 19 * inspector/formatting/resources/xml-tests/valid-html-invalid-xml.xml: Added. 20 * inspector/formatting/resources/xml-tests/xslt-expected.xml: Added. 21 * inspector/formatting/resources/xml-tests/xslt.xml: Added. 22 1 23 2019-09-13 Joseph Pecoraro <pecoraro@apple.com> 2 24 -
trunk/LayoutTests/inspector/formatting/resources/formatting-utilities.js
r249831 r249867 52 52 workerProxy.formatHTML(testText, indentString, callback); 53 53 break; 54 case "text/xml": 55 workerProxy.formatXML(testText, indentString, callback); 56 break; 54 57 } 55 58 }); -
trunk/Source/WebInspectorUI/ChangeLog
r249866 r249867 1 2019-09-13 Joseph Pecoraro <pecoraro@apple.com> 2 3 Web Inspector: HTML Formatter - XML mode 4 https://bugs.webkit.org/show_bug.cgi?id=201758 5 6 Reviewed by Devin Rousso. 7 8 * Tools/HTMLFormatter/index.html: 9 * Tools/SourceMaps/index.html: 10 Update Tools to more easily test XML. 11 12 * UserInterface/Proxies/FormatterWorkerProxy.js: 13 (WI.FormatterWorkerProxy.prototype.formatXML): 14 * UserInterface/Views/TextEditor.js: 15 (WI.TextEditor.prototype.hasFormatter): 16 (WI.TextEditor.prototype._startWorkerPrettyPrint): 17 Allow formatting XML content. 18 19 * UserInterface/Workers/Formatter/FormatterWorker.js: 20 (FormatterWorker.prototype.formatHTML): 21 (FormatterWorker.prototype.formatXML): 22 Expose "formatXML". 23 24 * UserInterface/Workers/Formatter/HTMLFormatter.js: 25 (HTMLFormatter.let.dom): 26 (HTMLFormatter): 27 (HTMLFormatter.prototype._shouldHaveNoChildren): 28 (HTMLFormatter.prototype._before): 29 (HTMLFormatter.prototype._after): 30 * UserInterface/Workers/Formatter/HTMLParser.js: 31 (HTMLParser.prototype.parseDocument): 32 * UserInterface/Workers/Formatter/HTMLTreeBuilderFormatter.js: 33 (HTMLTreeBuilderFormatter.prototype._isEmptyNode): 34 Give the HTMLFormatter and related classes an XML mode that 35 has less of the smarts of XML. 36 1 37 2019-09-13 Joseph Pecoraro <pecoraro@apple.com> 2 38 -
trunk/Source/WebInspectorUI/Tools/HTMLFormatter/index.html
r249831 r249867 41 41 <option value="self">Self</option> 42 42 </select> 43 <select id="source-type"> 44 <option value="text/html">HTML</option> 45 <option value="text/xml">XML</option> 46 </select> 43 47 <button id="format">Format</button> 44 48 <button id="select-output">Select Output</button> … … 61 65 // Elements. 62 66 const populatePicker = document.getElementById("populate"); 67 const sourceTypePicker = document.getElementById("source-type"); 63 68 const timeOutput = document.getElementById("time"); 64 69 const prettyPre = document.getElementById("pretty"); … … 87 92 88 93 // Time the formatter. 94 let sourceType = sourceTypePicker.value === "text/html" ? HTMLFormatter.SourceType.HTML : HTMLFormatter.SourceType.XML; 89 95 let startTime = Date.now(); 90 let formatter = new HTMLFormatter(cm.getValue() );96 let formatter = new HTMLFormatter(cm.getValue(), sourceType); 91 97 let endTime = Date.now(); 92 98 … … 94 100 let debugText = ""; 95 101 try { 102 let options = {isXML: sourceType === HTMLFormatter.SourceType.XML}; 96 103 let parser = new HTMLParser; 97 104 let treeBuilder = new HTMLTreeBuilderDebug; 98 parser.parseDocument(cm.getValue(), treeBuilder );105 parser.parseDocument(cm.getValue(), treeBuilder, options); 99 106 debugText = treeBuilder.debugText; 100 107 } catch (error) { … … 178 185 let content = cm.getValue(); 179 186 let populate = populatePicker.value; 180 window.location.search = `?content=${encodeURIComponent(content)}&populate=${encodeURIComponent(populate)}`; 187 let sourceType = sourceTypePicker.value; 188 window.location.search = `?content=${encodeURIComponent(content)}&populate=${encodeURIComponent(populate)}&sourceType=${encodeURIComponent(sourceType)}`; 181 189 }); 182 190 … … 241 249 }); 242 250 251 // Parser mode picker. 252 sourceTypePicker.addEventListener("change", (event) => { 253 cm.setOption("mode", sourceTypePicker.value); 254 refresh(); 255 }); 256 243 257 // Restore better initial value from query string. 244 258 (function() { … … 256 270 updateContentFromPicker(); 257 271 } 272 if (queryParams.sourceType) { 273 sourceTypePicker.value = queryParams.sourceType; 274 cm.setOption("mode", sourceTypePicker.value); 275 } 258 276 if (queryParams.content) 259 277 cm.setValue(queryParams.content); -
trunk/Source/WebInspectorUI/Tools/SourceMaps/index.html
r249831 r249867 34 34 <option>javascript</option> 35 35 <option>css</option> 36 <option>xml</option> 36 37 </select> 37 38 <button id="format">Format</button> … … 198 199 workerProxy.formatCSS(inputCM.getValue(), indentString, includeSourceMapData, formatResult); 199 200 break; 201 case "xml": 202 workerProxy.formatXML(inputCM.getValue(), indentString, includeSourceMapData, formatResult); 203 break; 200 204 } 201 205 … … 236 240 const simpleJS = `(function(){let a=1;return a+1;})();`; 237 241 const simpleCSS = `body{color:red;background:blue}*{color:green}`; 242 const simpleXML = `<?xml version="1.0" encoding="iso8859-5"?><outer><inner attr="value">1</inner></outer>`; 238 243 239 244 // Populate picker … … 252 257 mode = "text/css"; 253 258 content = simpleCSS; 259 break; 260 case "xml": 261 mode = "text/xml"; 262 content = simpleXML; 254 263 break; 255 264 default: -
trunk/Source/WebInspectorUI/UserInterface/Proxies/FormatterWorkerProxy.js
r249831 r249867 61 61 } 62 62 63 formatXML(sourceText, indentString, includeSourceMapData) 64 { 65 this.performAction("formatXML", ...arguments); 66 } 67 63 68 // Public 64 69 -
trunk/Source/WebInspectorUI/UserInterface/Views/TextEditor.js
r249831 r249867 183 183 { 184 184 let mode = this._codeMirror.getMode().name; 185 return mode === "javascript" || mode === "css" || mode === "htmlmixed" ;185 return mode === "javascript" || mode === "css" || mode === "htmlmixed" || mode === "xml"; 186 186 } 187 187 … … 906 906 case "htmlmixed": 907 907 workerProxy.formatHTML(sourceText, indentString, includeSourceMapData, formatCallback); 908 break; 909 case "xml": 910 workerProxy.formatXML(sourceText, indentString, includeSourceMapData, formatCallback); 908 911 break; 909 912 default: -
trunk/Source/WebInspectorUI/UserInterface/Workers/Formatter/FormatterWorker.js
r249831 r249867 111 111 let result = {formattedText: null}; 112 112 const builder = null; 113 let formatter = new HTMLFormatter(sourceText, builder, indentString); 113 const sourceType = HTMLFormatter.SourceType.HTML; 114 let formatter = new HTMLFormatter(sourceText, sourceType, builder, indentString); 115 if (formatter.success) { 116 result.formattedText = formatter.formattedText; 117 if (includeSourceMapData) 118 result.sourceMapData = formatter.sourceMapData; 119 } 120 return result; 121 } 122 123 formatXML(sourceText, indentString, includeSourceMapData) 124 { 125 let result = {formattedText: null}; 126 const builder = null; 127 const sourceType = HTMLFormatter.SourceType.XML; 128 let formatter = new HTMLFormatter(sourceText, sourceType, builder, indentString); 114 129 if (formatter.success) { 115 130 result.formattedText = formatter.formattedText; -
trunk/Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLFormatter.js
r249831 r249867 26 26 HTMLFormatter = class HTMLFormatter 27 27 { 28 constructor(sourceText, builder, indentString = " ") 29 { 28 constructor(sourceText, sourceType, builder, indentString = " ") 29 { 30 console.assert(typeof sourceText === "string"); 31 console.assert(Object.values(HTMLFormatter.SourceType).includes(sourceType)); 32 33 this._sourceType = sourceType; 34 30 35 this._success = false; 31 36 32 37 let dom = (function() { 33 38 try { 39 let options = { 40 isXML: sourceType === HTMLFormatter.SourceType.XML, 41 }; 34 42 let parser = new HTMLParser; 35 let treeBuilder = new HTMLTreeBuilderFormatter ;36 parser.parseDocument(sourceText, treeBuilder );43 let treeBuilder = new HTMLTreeBuilderFormatter(options); 44 parser.parseDocument(sourceText, treeBuilder, options); 37 45 return treeBuilder.dom; 38 46 } catch (e) { … … 106 114 _shouldHaveNoChildren(node) 107 115 { 108 return HTMLTreeBuilderFormatter.TagNamesWithoutChildren.has(node.lowercaseName); 116 switch (this._sourceType) { 117 case HTMLFormatter.SourceType.HTML: 118 return HTMLTreeBuilderFormatter.TagNamesWithoutChildren.has(node.lowercaseName); 119 case HTMLFormatter.SourceType.XML: 120 return false; 121 } 122 123 console.assert(false, "Unknown source type", this._sourceType); 124 return false; 109 125 } 110 126 … … 197 213 198 214 if (!node.__inlineContent) { 199 if (node.lowercaseName !== "html" )215 if (node.lowercaseName !== "html" || this._sourceType === HTMLFormatter.SourceType.XML) 200 216 this._builder.indent(); 201 217 this._builder.appendNewline(); … … 269 285 return; 270 286 if (!node.__inlineContent) { 271 if (node.lowercaseName !== "html" )287 if (node.lowercaseName !== "html" || this._sourceType === HTMLFormatter.SourceType.XML) 272 288 this._builder.dedent(); 273 289 this._builder.appendNewline(); … … 358 374 } 359 375 }; 376 377 HTMLFormatter.SourceType = { 378 HTML: "html", 379 XML: "xml", 380 }; -
trunk/Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLParser.js
r249866 r249867 28 28 // Public 29 29 30 parseDocument(sourceText, treeBuilder )30 parseDocument(sourceText, treeBuilder, {isXML} = {}) 31 31 { 32 32 console.assert(typeof sourceText === "string"); … … 40 40 this._data = sourceText; 41 41 this._bogusCommentOpener = null; 42 this._isXML = !!isXML; 42 43 43 44 if (this._treeBuilder.begin) … … 449 450 // Custom mode for some elements. 450 451 if (node.type === HTMLParser.NodeType.OpenTag) { 451 if ( node.name.toLowerCase() === "script")452 if (!this._isXML && node.name.toLowerCase() === "script") 452 453 this._mode = HTMLParser.Mode.ScriptData; 453 454 } -
trunk/Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLTreeBuilderFormatter.js
r249831 r249867 30 30 // whitespace reformatter for input text and not generate the ultimate 31 31 // html tree that a browser would generate. 32 // 33 // When run with the XML option, all HTML specific cases are disabled. 32 34 33 35 HTMLTreeBuilderFormatter = class HTMLTreeBuilderFormatter 34 36 { 37 constructor({isXML} = {}) 38 { 39 this._isXML = !!isXML; 40 } 41 35 42 // Public 36 43 … … 131 138 return true; 132 139 133 if ( HTMLTreeBuilderFormatter.TagNamesWithoutChildren.has(node.lowercaseName))140 if (!this._isXML && HTMLTreeBuilderFormatter.TagNamesWithoutChildren.has(node.lowercaseName)) 134 141 return true; 135 142
Note:
See TracChangeset
for help on using the changeset viewer.