Chromium Code Reviews| Index: Source/devtools/front_end/DOMSyntaxHighlighter.js |
| diff --git a/Source/devtools/front_end/DOMSyntaxHighlighter.js b/Source/devtools/front_end/DOMSyntaxHighlighter.js |
| index 4ae97ebadcb8801c0f427929a1ad674301d0d2d2..1e389a24422fcade2dca2c54af688fbae8720d5a 100644 |
| --- a/Source/devtools/front_end/DOMSyntaxHighlighter.js |
| +++ b/Source/devtools/front_end/DOMSyntaxHighlighter.js |
| @@ -33,7 +33,9 @@ |
| */ |
| WebInspector.DOMSyntaxHighlighter = function(mimeType, stripExtraWhitespace) |
| { |
| - this._tokenizer = WebInspector.SourceTokenizer.Registry.getInstance().getTokenizer(mimeType); |
| + if (!WebInspector.CodeMirrorUtils) |
|
vsevik
2013/08/12 16:36:57
This is confusing, please remove.
|
| + loadScript("CodeMirrorTextEditor.js"); |
| + this._mimeType = mimeType; |
| this._stripExtraWhitespace = stripExtraWhitespace; |
| } |
| @@ -41,7 +43,7 @@ WebInspector.DOMSyntaxHighlighter.prototype = { |
| createSpan: function(content, className) |
| { |
| var span = document.createElement("span"); |
| - span.className = "webkit-" + className; |
| + span.className = "cm-" + className; |
| if (this._stripExtraWhitespace && className !== "whitespace") |
| content = content.replace(/^[\n\r]*/, "").replace(/\s*$/, ""); |
| span.appendChild(document.createTextNode(content)); |
| @@ -50,36 +52,29 @@ WebInspector.DOMSyntaxHighlighter.prototype = { |
| syntaxHighlightNode: function(node) |
| { |
| - this._tokenizer.condition = this._tokenizer.createInitialCondition(); |
| var lines = node.textContent.split("\n"); |
| node.removeChildren(); |
| + var tokenize = WebInspector.CodeMirrorUtils.createTokenizer(this._mimeType); |
| for (var i = lines[0].length ? 0 : 1; i < lines.length; ++i) { |
| var line = lines[i]; |
| var plainTextStart = 0; |
| - this._tokenizer.line = line; |
| - var column = 0; |
| - do { |
| - var newColumn = this._tokenizer.nextToken(column); |
| - var tokenType = this._tokenizer.tokenType; |
| + tokenize(line, function(token, tokenType, column, newColumn) { |
|
vsevik
2013/08/12 16:36:57
Please extract function
|
| if (tokenType) { |
| if (column > plainTextStart) { |
| var plainText = line.substring(plainTextStart, column); |
| node.appendChild(document.createTextNode(plainText)); |
| } |
| - var token = line.substring(column, newColumn); |
| node.appendChild(this.createSpan(token, tokenType)); |
| plainTextStart = newColumn; |
| } |
| - column = newColumn; |
| - } while (column < line.length) |
| - |
| + }.bind(this)); |
| if (plainTextStart < line.length) { |
| var plainText = line.substring(plainTextStart, line.length); |
| node.appendChild(document.createTextNode(plainText)); |
| } |
| if (i < lines.length - 1) |
| - node.appendChild(document.createElement("br")); |
| + node.appendChild(document.createElement("br")); |
| } |
| } |
| } |