| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @constructor | 32 * @constructor |
| 33 */ | 33 */ |
| 34 WebInspector.DOMSyntaxHighlighter = function(mimeType, stripExtraWhitespace) | 34 WebInspector.DOMSyntaxHighlighter = function(mimeType, stripExtraWhitespace) |
| 35 { | 35 { |
| 36 this._tokenizer = WebInspector.SourceTokenizer.Registry.getInstance().getTok
enizer(mimeType); | 36 loadScript("CodeMirrorTextEditor.js"); |
| 37 this._mimeType = mimeType; |
| 37 this._stripExtraWhitespace = stripExtraWhitespace; | 38 this._stripExtraWhitespace = stripExtraWhitespace; |
| 38 } | 39 } |
| 39 | 40 |
| 40 WebInspector.DOMSyntaxHighlighter.prototype = { | 41 WebInspector.DOMSyntaxHighlighter.prototype = { |
| 41 createSpan: function(content, className) | 42 createSpan: function(content, className) |
| 42 { | 43 { |
| 43 var span = document.createElement("span"); | 44 var span = document.createElement("span"); |
| 44 span.className = "webkit-" + className; | 45 span.className = "cm-" + className; |
| 45 if (this._stripExtraWhitespace && className !== "whitespace") | 46 if (this._stripExtraWhitespace && className !== "whitespace") |
| 46 content = content.replace(/^[\n\r]*/, "").replace(/\s*$/, ""); | 47 content = content.replace(/^[\n\r]*/, "").replace(/\s*$/, ""); |
| 47 span.appendChild(document.createTextNode(content)); | 48 span.appendChild(document.createTextNode(content)); |
| 48 return span; | 49 return span; |
| 49 }, | 50 }, |
| 50 | 51 |
| 51 syntaxHighlightNode: function(node) | 52 syntaxHighlightNode: function(node) |
| 52 { | 53 { |
| 53 this._tokenizer.condition = this._tokenizer.createInitialCondition(); | |
| 54 var lines = node.textContent.split("\n"); | 54 var lines = node.textContent.split("\n"); |
| 55 node.removeChildren(); | 55 node.removeChildren(); |
| 56 | 56 |
| 57 var tokenize = WebInspector.CodeMirrorUtils.createTokenizer(this._mimeTy
pe); |
| 57 for (var i = lines[0].length ? 0 : 1; i < lines.length; ++i) { | 58 for (var i = lines[0].length ? 0 : 1; i < lines.length; ++i) { |
| 58 var line = lines[i]; | 59 var line = lines[i]; |
| 59 var plainTextStart = 0; | 60 var plainTextStart = 0; |
| 60 this._tokenizer.line = line; | 61 function processToken(token, tokenType, column, newColumn) |
| 61 var column = 0; | 62 { |
| 62 do { | |
| 63 var newColumn = this._tokenizer.nextToken(column); | |
| 64 var tokenType = this._tokenizer.tokenType; | |
| 65 if (tokenType) { | 63 if (tokenType) { |
| 66 if (column > plainTextStart) { | 64 if (column > plainTextStart) { |
| 67 var plainText = line.substring(plainTextStart, column); | 65 var plainText = line.substring(plainTextStart, column); |
| 68 node.appendChild(document.createTextNode(plainText)); | 66 node.appendChild(document.createTextNode(plainText)); |
| 69 } | 67 } |
| 70 var token = line.substring(column, newColumn); | |
| 71 node.appendChild(this.createSpan(token, tokenType)); | 68 node.appendChild(this.createSpan(token, tokenType)); |
| 72 plainTextStart = newColumn; | 69 plainTextStart = newColumn; |
| 73 } | 70 } |
| 74 column = newColumn; | 71 } |
| 75 } while (column < line.length) | 72 tokenize(line, processToken.bind(this)); |
| 76 | 73 if (plainTextStart < line.length) { |
| 77 if (plainTextStart < line.length) { | 74 var plainText = line.substring(plainTextStart, line.length); |
| 78 var plainText = line.substring(plainTextStart, line.length); | 75 node.appendChild(document.createTextNode(plainText)); |
| 79 node.appendChild(document.createTextNode(plainText)); | 76 } |
| 80 } | 77 if (i < lines.length - 1) |
| 81 if (i < lines.length - 1) | 78 node.appendChild(document.createElement("br")); |
| 82 node.appendChild(document.createElement("br")); | |
| 83 } | 79 } |
| 84 } | 80 } |
| 85 } | 81 } |
| OLD | NEW |