Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @param {string} wikiMarkupText | 7 * @param {string} wikiMarkupText |
| 8 */ | 8 */ |
| 9 WebInspector.WikiParser = function(wikiMarkupText) | 9 WebInspector.WikiParser = function(wikiMarkupText) |
| 10 { | 10 { |
| 11 this._position = 0; | 11 var text = wikiMarkupText.replace(/</g, "<") |
|
lushnikov
2014/09/09 12:40:46
lets extract this into utilities?
iliia
2014/09/09 14:29:18
Done.
| |
| 12 this._wikiMarkupText = wikiMarkupText; | 12 .replace(/>/g, ">") |
| 13 .replace(/:/g, ":") | |
| 14 .replace(/"/g, "\"") | |
| 15 .replace(/</g, "<") | |
| 16 .replace(/>/g, ">") | |
| 17 .replace(/&/g, "&"); | |
| 18 this._tokenizer = new WebInspector.WikiParser.Tokenizer(text); | |
| 13 this._document = this._parse(); | 19 this._document = this._parse(); |
| 14 /** @type {?WebInspector.WikiParser.Tokenizer} */ | |
| 15 this._tokenizer; | |
| 16 } | 20 } |
| 17 | 21 |
| 18 /** | 22 /** |
| 19 * @package | |
| 20 * @enum {string} | |
| 21 */ | |
| 22 WebInspector.WikiParser.State = { | |
| 23 Error: "Error", | |
| 24 FirstOpen: "FirstOpen", | |
| 25 SecondOpen: "SecondOpen", | |
| 26 Title: "Title", | |
| 27 PropertyName: "PropertyName", | |
| 28 PropertyValue: "PropertyValue", | |
| 29 FirstClose: "FirstClose", | |
| 30 SecondClose: "SecondClose" | |
| 31 } | |
| 32 | |
| 33 /** | |
| 34 * @package | |
| 35 * @enum {string} | |
| 36 */ | |
| 37 WebInspector.WikiParser.LinkStates = { | |
| 38 Error: "Error", | |
| 39 LinkUrl: "LinkUrl", | |
| 40 LinkName: "LinkName" | |
| 41 } | |
| 42 | |
| 43 /** | |
| 44 * @package | |
| 45 * @enum {string} | |
| 46 */ | |
| 47 WebInspector.WikiParser.HtmlStates = { | |
| 48 Error: "Error", | |
| 49 Entry: "Entry", | |
| 50 InsideTag: "InsideTag", | |
| 51 Exit: "Exit" | |
| 52 } | |
| 53 | |
| 54 /** | |
| 55 * @package | |
| 56 * @enum {string} | |
| 57 */ | |
| 58 WebInspector.WikiParser.ValueState = { | |
| 59 Error: "Error", | |
| 60 Outside: "Outside", | |
| 61 InsideSquare: "InsideSquare" | |
| 62 } | |
| 63 | |
| 64 /** | |
| 65 * @package | 23 * @package |
| 66 * @enum {string} | 24 * @enum {string} |
| 67 */ | 25 */ |
| 68 WebInspector.WikiParser.TokenType = { | 26 WebInspector.WikiParser.TokenType = { |
| 27 Text: "Text", | |
| 28 Table: "Table", | |
| 29 OpeningBraces: "OpeningBraces", | |
| 30 ClosingBraces: "ClosingBraces", | |
| 31 Exclamation: "Exclamation", | |
| 32 OpeningBrackets: "OpeningBrackets", | |
| 33 ClosingBrackets: "ClosingBrackets", | |
| 34 EqualSign: "EqualSign", | |
| 35 EqualSignInBraces: "EqualSignInBraces", | |
| 36 VerticalLine: "VerticalLine", | |
| 69 TripleQuotes: "TripleQuotes", | 37 TripleQuotes: "TripleQuotes", |
| 70 OpeningBrackets: "OpeningBrackets", | |
| 71 OpeningCodeTag: "OpeningCodeTag", | 38 OpeningCodeTag: "OpeningCodeTag", |
| 72 ClosingBrackets: "ClosingBrackets", | |
| 73 ClosingCodeTag: "ClosingCodeTag", | 39 ClosingCodeTag: "ClosingCodeTag", |
| 74 Bullet: "Bullet", | 40 Bullet: "Bullet", |
| 75 Text: "Text", | |
| 76 VerticalLine: "VerticalLine", | |
| 77 LineEnd: "LineEnd", | 41 LineEnd: "LineEnd", |
| 78 CodeBlock: "CodeBlock" | 42 CodeBlock: "CodeBlock", |
| 43 Space: "Space" | |
| 79 } | 44 } |
| 80 | 45 |
| 81 /** | 46 /** |
| 82 * @constructor | 47 * @constructor |
| 83 * @param {string} result | 48 * @param {string} result |
| 84 * @param {!WebInspector.WikiParser.TokenType} type | 49 * @param {!WebInspector.WikiParser.TokenType} type |
| 85 */ | 50 */ |
| 86 WebInspector.WikiParser.Token = function(result, type) | 51 WebInspector.WikiParser.Token = function(result, type) |
| 87 { | 52 { |
| 88 this._value = result; | 53 this._value = result; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 107 } | 72 } |
| 108 } | 73 } |
| 109 | 74 |
| 110 /** | 75 /** |
| 111 * @constructor | 76 * @constructor |
| 112 * @param {string} str | 77 * @param {string} str |
| 113 */ | 78 */ |
| 114 WebInspector.WikiParser.Tokenizer = function(str) | 79 WebInspector.WikiParser.Tokenizer = function(str) |
| 115 { | 80 { |
| 116 this._text = str; | 81 this._text = str; |
| 82 this._token = this._internalNextToken(); | |
| 117 } | 83 } |
| 118 | 84 |
| 119 WebInspector.WikiParser.Tokenizer.prototype = { | 85 WebInspector.WikiParser.Tokenizer.prototype = { |
| 120 /** | 86 /** |
| 121 * @return {!WebInspector.WikiParser.Token} | 87 * @return {!WebInspector.WikiParser.Token} |
| 122 */ | 88 */ |
| 123 _nextToken: function() | 89 peekToken: function() |
| 90 { | |
| 91 return this._token; | |
| 92 }, | |
| 93 | |
| 94 /** | |
| 95 * @return {!WebInspector.WikiParser.Token} | |
| 96 */ | |
| 97 nextToken: function() | |
| 98 { | |
| 99 var token = this._token; | |
| 100 this._token = this._internalNextToken(); | |
| 101 return token; | |
| 102 }, | |
| 103 | |
| 104 /** | |
| 105 * @return {!WebInspector.WikiParser.Token} | |
| 106 */ | |
| 107 _internalNextToken: function() | |
| 124 { | 108 { |
| 125 if (WebInspector.WikiParser.newLineWithSpace.test(this._text)) { | 109 if (WebInspector.WikiParser.newLineWithSpace.test(this._text)) { |
| 126 var result = WebInspector.WikiParser.newLineWithSpace.exec(this._tex t); | 110 var result = WebInspector.WikiParser.newLineWithSpace.exec(this._tex t); |
| 127 var begin = result.index + result[0].length; | 111 var begin = result.index + result[0].length - 1; |
|
lushnikov
2014/09/09 12:40:46
where does this -1 come from?
iliia
2014/09/09 14:29:18
it's a space after new line in the beginning.
On 2
| |
| 128 var end = this._text.length; | 112 var end = this._text.length; |
| 129 var lineEnd = WebInspector.WikiParser.newLineWithoutSpace.exec(this. _text); | 113 var lineEnd = WebInspector.WikiParser.newLineWithoutSpace.exec(this. _text); |
| 130 if (lineEnd) | 114 if (lineEnd) |
| 131 end = lineEnd.index; | 115 end = lineEnd.index; |
| 132 var token = this._text.substring(begin, end).replace(/\n */g, "\n"); | 116 var token = this._text.substring(begin, end).replace(/\n /g, "\n").r eplace(/{{=}}/g, "="); |
| 133 this._text = this._text.substring(end + 1); | 117 this._text = this._text.substring(end + 1); |
| 134 return new WebInspector.WikiParser.Token(token, WebInspector.WikiPar ser.TokenType.CodeBlock); | 118 return new WebInspector.WikiParser.Token(token, WebInspector.WikiPar ser.TokenType.CodeBlock); |
| 135 } | 119 } |
| 136 | 120 |
| 137 for (var i = 0; i < WebInspector.WikiParser._tokenDescriptors.length; ++ i) { | 121 for (var i = 0; i < WebInspector.WikiParser._tokenDescriptors.length; ++ i) { |
| 138 var result = WebInspector.WikiParser._tokenDescriptors[i].regex.exec (this._text); | 122 var result = WebInspector.WikiParser._tokenDescriptors[i].regex.exec (this._text); |
| 139 if (result) { | 123 if (result) { |
| 140 this._text = this._text.substring(result.index + result[0].lengt h); | 124 this._text = this._text.substring(result.index + result[0].lengt h); |
| 141 return new WebInspector.WikiParser.Token(result[0], WebInspector .WikiParser._tokenDescriptors[i].type); | 125 return new WebInspector.WikiParser.Token(result[0], WebInspector .WikiParser._tokenDescriptors[i].type); |
| 142 } | 126 } |
| 143 } | 127 } |
| 144 | 128 |
| 145 for (var lastIndex = 0; lastIndex < this._text.length; ++lastIndex) { | 129 for (var lastIndex = 0; lastIndex < this._text.length; ++lastIndex) { |
| 146 var testString = this._text.substring(lastIndex); | 130 var testString = this._text.substring(lastIndex); |
| 147 for (var i = 0; i < WebInspector.WikiParser._tokenDescriptors.length ; ++i) { | 131 for (var i = 0; i < WebInspector.WikiParser._tokenDescriptors.length ; ++i) { |
| 148 if (WebInspector.WikiParser._tokenDescriptors[i].regex.test(test String)) { | 132 if (WebInspector.WikiParser._tokenDescriptors[i].regex.test(test String)) { |
| 149 var token = this._text.substring(0, lastIndex); | 133 var token = this._text.substring(0, lastIndex); |
| 150 this._text = this._text.substring(lastIndex); | 134 this._text = this._text.substring(lastIndex); |
| 151 return new WebInspector.WikiParser.Token(token, WebInspector .WikiParser.TokenType.Text); | 135 return new WebInspector.WikiParser.Token(token, WebInspector .WikiParser.TokenType.Text); |
| 152 } | 136 } |
| 153 } | 137 } |
| 154 } | 138 } |
| 155 | 139 |
| 156 var token = this._text; | 140 var token = this._text; |
| 157 this._text = ""; | 141 this._text = ""; |
| 158 return new WebInspector.WikiParser.Token(token, WebInspector.WikiParser. TokenType.Text); | 142 return new WebInspector.WikiParser.Token(token, WebInspector.WikiParser. TokenType.Text); |
| 159 }, | 143 }, |
| 160 | 144 |
| 161 /** | 145 /** |
| 146 * @return {?WebInspector.WikiParser.TokenType} | |
| 147 */ | |
| 148 secondToken: function() | |
| 149 { | |
| 150 var tokenizer = new WebInspector.WikiParser.Tokenizer(this._text); | |
| 151 if (tokenizer.hasMoreTokens()) | |
| 152 return tokenizer.nextToken().type(); | |
| 153 return null; | |
| 154 }, | |
| 155 | |
| 156 /** | |
| 162 * @return {boolean} | 157 * @return {boolean} |
| 163 */ | 158 */ |
| 164 _hasMoreTokens: function() | 159 hasMoreTokens: function() |
| 165 { | 160 { |
| 166 return !!this._text.length; | 161 return !!this._text.length; |
| 167 } | 162 } |
| 168 } | 163 } |
| 169 | 164 |
| 165 WebInspector.WikiParser.table = /^{{{!}}/; | |
| 166 WebInspector.WikiParser.exclamation = /^{{!}}/; | |
| 167 WebInspector.WikiParser.openingBraces = /^{{/; | |
| 168 WebInspector.WikiParser.equalSign = /^=/; | |
| 169 WebInspector.WikiParser.equalSignInBraces = /^{{=}}/; | |
| 170 WebInspector.WikiParser.closingBraces = /^\s*}}/; | |
| 171 WebInspector.WikiParser.oneOpeningBracketWithSpace = /^\n* \[/; | |
| 172 WebInspector.WikiParser.twoOpeningBracketsWithSpace = /^\n* \[\[/; | |
| 173 WebInspector.WikiParser.oneClosingBracket = /^\n*\]/; | |
| 174 WebInspector.WikiParser.twoClosingBrackets = /^\n*\]\]/; | |
| 175 WebInspector.WikiParser.tripleQuotes = /^\n*'''/; | |
| 176 WebInspector.WikiParser.openingCodeTag = /^<\s*code\s*>/; | |
| 177 WebInspector.WikiParser.closingCodeTag = /^<\s*\/\s*code\s*>/; | |
| 178 WebInspector.WikiParser.closingBullet = /^\*/; | |
| 179 WebInspector.WikiParser.lineEnd = /^\n/; | |
| 180 WebInspector.WikiParser.verticalLine = /^\n*\|/; | |
| 181 WebInspector.WikiParser.newLineWithSpace = /^\n [^ ]/; | |
| 182 WebInspector.WikiParser.newLineWithoutSpace = /\n[^ ]/; | |
| 183 WebInspector.WikiParser.space = /^ /; | |
| 184 | |
| 185 /** | |
| 186 * @constructor | |
| 187 * @param {!RegExp} regex | |
| 188 * @param {!WebInspector.WikiParser.TokenType} type | |
| 189 */ | |
| 190 WebInspector.WikiParser.TokenDescriptor = function(regex, type) | |
| 191 { | |
| 192 this.regex = regex; | |
| 193 this.type = type; | |
| 194 } | |
| 195 | |
| 196 WebInspector.WikiParser._tokenDescriptors = [ | |
| 197 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.exclamat ion, WebInspector.WikiParser.TokenType.Exclamation), | |
| 198 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.equalSig nInBraces, WebInspector.WikiParser.TokenType.EqualSignInBraces), | |
| 199 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.equalSig n, WebInspector.WikiParser.TokenType.EqualSign), | |
| 200 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.table, W ebInspector.WikiParser.TokenType.Table), | |
| 201 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.openingB races, WebInspector.WikiParser.TokenType.OpeningBraces), | |
| 202 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.vertical Line, WebInspector.WikiParser.TokenType.VerticalLine), | |
| 203 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingB races, WebInspector.WikiParser.TokenType.ClosingBraces), | |
| 204 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.twoOpeni ngBracketsWithSpace, WebInspector.WikiParser.TokenType.OpeningBrackets), | |
| 205 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.twoClosi ngBrackets, WebInspector.WikiParser.TokenType.ClosingBrackets), | |
| 206 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.oneOpeni ngBracketWithSpace, WebInspector.WikiParser.TokenType.OpeningBrackets), | |
| 207 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.oneClosi ngBracket, WebInspector.WikiParser.TokenType.ClosingBrackets), | |
| 208 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.newLineW ithSpace, WebInspector.WikiParser.TokenType.CodeBlock), | |
| 209 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.tripleQu otes, WebInspector.WikiParser.TokenType.TripleQuotes), | |
| 210 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.openingC odeTag, WebInspector.WikiParser.TokenType.OpeningCodeTag), | |
| 211 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingC odeTag, WebInspector.WikiParser.TokenType.ClosingCodeTag), | |
| 212 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingB ullet, WebInspector.WikiParser.TokenType.Bullet), | |
| 213 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.lineEnd, WebInspector.WikiParser.TokenType.LineEnd)//, | |
| 214 //new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.space, WebInspector.WikiParser.TokenType.Space) | |
| 215 ] | |
| 216 | |
| 170 WebInspector.WikiParser.prototype = { | 217 WebInspector.WikiParser.prototype = { |
| 171 /** | 218 /** |
| 172 * @return {!Object} | 219 * @return {!Object} |
| 173 */ | 220 */ |
| 174 document: function() | 221 document: function() |
| 175 { | 222 { |
| 176 return this._document; | 223 return this._document; |
| 177 }, | 224 }, |
| 178 | 225 |
| 179 /** | 226 /** |
| 180 * @return {!Object} | 227 * @return {!Object} |
| 181 */ | 228 */ |
| 182 _parse: function() | 229 _parse: function() |
| 183 { | 230 { |
| 184 var obj = {}; | 231 var obj = {}; |
| 185 this._wikiMarkupText = this._wikiMarkupText.replace(/</g, "<") | 232 while (this._tokenizer.hasMoreTokens()) { |
| 186 .replace(/>/g, ">") | |
| 187 .replace(/:/g, ":") | |
| 188 .replace(/"/g, "\"") | |
| 189 .replace(/</g, "<") | |
| 190 .replace(/>/g, ">") | |
| 191 .replace(/{{=}}/g, "=") | |
| 192 .replace(/{{!}}/g, "|") | |
| 193 .replace(/&/g, "&"); | |
| 194 while (this._position < this._wikiMarkupText.length) { | |
| 195 var field = this._parseField(); | 233 var field = this._parseField(); |
| 196 for (var key in field) { | 234 for (var key in field) { |
| 197 console.assert(typeof obj[key] === "undefined", "Duplicate key: " + key); | 235 console.assert(typeof obj[key] === "undefined", "Duplicate key: " + key); |
| 198 obj[key] = field[key]; | 236 obj[key] = field[key]; |
| 199 } | 237 } |
| 200 } | 238 } |
| 201 return obj; | 239 return obj; |
| 202 }, | 240 }, |
| 203 | 241 |
| 204 /** | 242 /** |
| 243 * @return {?Object} | |
|
lushnikov
2014/09/09 12:40:46
it never returns null. Why nullable? also, it shou
iliia
2014/09/09 14:29:17
Then it will be Object.<string, string | Array.<st
| |
| 244 */ | |
| 245 _parseField: function() | |
| 246 { | |
| 247 var field = {}; | |
| 248 if (!this._tokenizer.hasMoreTokens() || this._tokenizer.nextToken().type () !== WebInspector.WikiParser.TokenType.OpeningBraces) | |
| 249 return field; | |
| 250 | |
| 251 var title = this._deleteTrailingSpaces(this._parseTitle()); | |
| 252 if (!title.length) | |
| 253 return field; | |
| 254 field[title] = {}; | |
| 255 if (this._tokenizer.peekToken().type() === WebInspector.WikiParser.Token Type.ClosingBraces) { | |
| 256 this._tokenizer.nextToken(); | |
| 257 return field; | |
| 258 } | |
| 259 if (!this._tokenizer.secondToken() || this._tokenizer.secondToken() !== WebInspector.WikiParser.TokenType.EqualSign) { | |
| 260 var propertyValue = this._parseString(); | |
| 261 field[title] = propertyValue; | |
| 262 } else { | |
| 263 while (this._tokenizer.hasMoreTokens()) { | |
|
lushnikov
2014/09/09 12:40:46
can we extract this whole while into a separate fu
iliia
2014/09/09 14:29:17
Yes, but I'm out of names for these functions :(
O
iliia
2014/09/09 14:29:18
Done.
| |
| 264 var propertyName = this._parseName(); | |
| 265 var token = this._tokenizer.peekToken(); | |
| 266 switch (token.type()) { | |
| 267 case WebInspector.WikiParser.TokenType.OpeningBraces: | |
| 268 field[title][propertyName] = this._parseArray(); | |
| 269 break; | |
| 270 case WebInspector.WikiParser.TokenType.LineEnd: | |
| 271 this._tokenizer.nextToken(); | |
| 272 break; | |
| 273 case WebInspector.WikiParser.TokenType.ClosingBraces: | |
| 274 this._tokenizer.nextToken(); | |
| 275 return field; | |
| 276 break; | |
|
lushnikov
2014/09/09 12:40:46
remove
iliia
2014/09/09 14:29:17
why don't we need this break?
On 2014/09/09 12:40:
| |
| 277 default: | |
| 278 if (propertyName === "Code") | |
| 279 field[title][propertyName] = this._parseExampleCode(); | |
| 280 else | |
| 281 field[title][propertyName] = this._parseString(); | |
| 282 } | |
| 283 } | |
| 284 } | |
| 285 var token = this._tokenizer.nextToken(); | |
| 286 if (token.type() !== WebInspector.WikiParser.TokenType.ClosingBraces) | |
| 287 throw new Error("Two closing braces expected; found " + token.value( )); | |
| 288 | |
| 289 return field; | |
| 290 }, | |
| 291 | |
| 292 /** | |
| 293 * @return {!Array.<?Object>} | |
|
lushnikov
2014/09/09 12:40:46
why nullable?
iliia
2014/09/09 14:29:17
Done.
| |
| 294 */ | |
| 295 _parseArray: function() | |
| 296 { | |
| 297 var array = []; | |
| 298 while (this._tokenizer.peekToken().type() === WebInspector.WikiParser.To kenType.OpeningBraces) | |
| 299 array.push(this._parseField()); | |
|
lushnikov
2014/09/09 12:40:46
this cyclic recursion looks odd. I believe we can
iliia
2014/09/09 14:29:18
why?
we must read all of internal blocks here with
| |
| 300 if (this._tokenizer.peekToken().type() === WebInspector.WikiParser.Token Type.VerticalLine) | |
| 301 this._tokenizer.nextToken(); | |
| 302 return array; | |
| 303 }, | |
| 304 | |
| 305 /** | |
| 205 * @return {string} | 306 * @return {string} |
| 206 */ | 307 */ |
| 207 _parseValue: function() { | 308 _parseTitle: function() |
| 208 var states = WebInspector.WikiParser.ValueState; | 309 { |
| 209 var state = states.Outside; | 310 var title = ""; |
| 210 var value = ""; | 311 while (this._tokenizer.hasMoreTokens()) { |
| 211 while (this._position < this._wikiMarkupText.length) { | 312 var token = this._tokenizer.peekToken(); |
| 212 switch (state) { | 313 switch (token.type()) { |
| 213 case states.Outside: | 314 case WebInspector.WikiParser.TokenType.ClosingBraces: |
| 214 if (this._wikiMarkupText[this._position] === "|" || (this._wikiM arkupText[this._position] === "}" && this._wikiMarkupText[this._position + 1] == = "}")) | 315 return title; |
| 215 return value; | 316 case WebInspector.WikiParser.TokenType.VerticalLine: |
| 216 switch (this._wikiMarkupText[this._position]) { | 317 this._tokenizer.nextToken(); |
| 217 case "<": | 318 return title; |
| 218 var indexClose = this._wikiMarkupText.indexOf(">", this._pos ition); | 319 case WebInspector.WikiParser.TokenType.Text: |
| 219 if (indexClose !== -1) { | 320 case WebInspector.WikiParser.TokenType.Space: |
| 220 value += this._wikiMarkupText.substring(this._position, indexClose + 1); | 321 title += this._tokenizer.nextToken().value(); |
| 221 this._position = indexClose; | |
| 222 } | |
| 223 break; | |
| 224 case "[": | |
| 225 state = states.InsideSquare; | |
| 226 value += this._wikiMarkupText[this._position]; | |
| 227 break; | |
| 228 default: | |
| 229 value += this._wikiMarkupText[this._position]; | |
| 230 } | |
| 231 break; | 322 break; |
| 232 case states.InsideSquare: | 323 default: |
| 233 if (this._wikiMarkupText[this._position] === "[") { | 324 throw new Error("Can't parse Title, unexpected token " + token.v alue()); |
|
lushnikov
2014/09/09 12:40:46
"Title could not be parsed. Unexpected token: " +
iliia
2014/09/09 14:29:18
Done.
| |
| 234 var indexClose = this._wikiMarkupText.indexOf("]]", this._po sition); | |
| 235 if (indexClose !== -1) { | |
| 236 value += this._wikiMarkupText.substring(this._position, indexClose + 2); | |
| 237 this._position = indexClose + 1; | |
| 238 } | |
| 239 } else { | |
| 240 var indexClose = this._wikiMarkupText.indexOf("]", this._pos ition); | |
| 241 if (indexClose !== -1) { | |
| 242 value += this._wikiMarkupText.substring(this._position, indexClose + 1); | |
| 243 this._position = indexClose; | |
| 244 } | |
| 245 } | |
| 246 state = states.Outside; | |
| 247 break; | |
| 248 } | 325 } |
| 249 this._position++; | |
| 250 } | 326 } |
| 251 return value; | 327 return title; |
| 252 }, | 328 }, |
| 253 | 329 |
| 254 /** | 330 /** |
| 255 * @return {!Object} | 331 * @return {string} |
| 256 */ | 332 */ |
| 257 _parseField: function() | 333 _parseName: function() |
| 258 { | 334 { |
| 259 var obj = {}; | 335 var name = ""; |
| 260 var title = ""; | 336 while (this._tokenizer.hasMoreTokens()) { |
| 261 var propertyName = ""; | 337 var token = this._tokenizer.peekToken(); |
| 262 var propertyValue = ""; | 338 switch (token.type()) { |
| 263 var states = WebInspector.WikiParser.State; | 339 case WebInspector.WikiParser.TokenType.ClosingBraces: |
| 264 var state = states.FirstOpen; | 340 return name; |
| 265 while (this._position < this._wikiMarkupText.length) { | 341 case WebInspector.WikiParser.TokenType.EqualSign: |
| 266 var skipIncrement = false; | 342 this._tokenizer.nextToken(); |
| 267 switch (state) { | 343 return name; |
| 268 case states.FirstOpen: | 344 case WebInspector.WikiParser.TokenType.VerticalLine: |
| 269 if (this._wikiMarkupText[this._position] === "{") | 345 case WebInspector.WikiParser.TokenType.Space: |
| 270 state = states.SecondOpen; | 346 case WebInspector.WikiParser.TokenType.Text: |
| 271 else | 347 name += this._tokenizer.nextToken().value(); |
| 272 state = states.Error; | |
| 273 break; | 348 break; |
| 274 case states.SecondOpen: | 349 default: |
| 275 if (this._wikiMarkupText[this._position] === "{") | 350 throw new Error("Can't parse name, unexpected token " + token.va lue()); |
|
lushnikov
2014/09/09 12:40:46
"Name could not be parsed. Unexpected token: " + t
iliia
2014/09/09 14:29:18
Done.
| |
| 276 state = states.Title; | |
| 277 else | |
| 278 state = states.Error; | |
| 279 break; | |
| 280 case states.Title: | |
| 281 if (this._wikiMarkupText[this._position] === "|") { | |
| 282 title = this._deleteTrailingSpaces(title); | |
| 283 if (title !== "") | |
| 284 obj[title] = {}; | |
| 285 state = states.PropertyName; | |
| 286 } else if (this._wikiMarkupText[this._position] === "}") { | |
| 287 title = this._deleteTrailingSpaces(title); | |
| 288 if (title !== "") | |
| 289 obj[title] = {}; | |
| 290 state = states.FirstClose; | |
| 291 } else { | |
| 292 title += (this._wikiMarkupText[this._position] === "\n" ? "" : this._wikiMarkupText[this._position]); | |
| 293 } | |
| 294 break; | |
| 295 case states.PropertyName: | |
| 296 if (this._wikiMarkupText[this._position] === "=") { | |
| 297 state = states.PropertyValue; | |
| 298 this._deleteTrailingSpaces(propertyName); | |
| 299 if (propertyName !== "") | |
| 300 obj[title][propertyName] = []; | |
| 301 } else { | |
| 302 if (this._wikiMarkupText[this._position] === "}") { | |
| 303 propertyName = this._deleteTrailingSpaces(propertyName); | |
| 304 obj[title] = propertyName; | |
| 305 state = states.FirstClose; | |
| 306 } else { | |
| 307 propertyName += this._wikiMarkupText[this._position]; | |
| 308 } | |
| 309 } | |
| 310 break; | |
| 311 case states.PropertyValue: | |
| 312 if (this._wikiMarkupText[this._position] === "{" && this._wikiMa rkupText[this._position + 1] === "{") { | |
| 313 propertyValue = this._parseField(); | |
| 314 obj[title][propertyName].push(propertyValue); | |
| 315 propertyValue = ""; | |
| 316 skipIncrement = true; | |
| 317 } else if (this._wikiMarkupText[this._position] === "|") { | |
| 318 propertyValue = this._deleteTrailingSpaces(propertyValue); | |
| 319 if (propertyValue !== "") | |
| 320 obj[title][propertyName] = propertyValue; | |
| 321 | |
| 322 state = states.PropertyName; | |
| 323 if (Array.isArray(obj[title][propertyName]) && obj[title][pr opertyName].length === 1) { | |
| 324 var newObj = obj[title][propertyName][0]; | |
| 325 obj[title][propertyName] = newObj; | |
| 326 } | |
| 327 | |
| 328 propertyName = ""; | |
| 329 propertyValue = ""; | |
| 330 } else if (this._position + 1 < this._wikiMarkupText.length && t his._wikiMarkupText[this._position] === "}" && this._wikiMarkupText[this._positi on + 1] === "}") { | |
| 331 propertyValue = this._deleteTrailingSpaces(propertyValue); | |
| 332 if (propertyValue !== "") | |
| 333 obj[title][propertyName].push(propertyValue); | |
| 334 if (Array.isArray(obj[title][propertyName]) && obj[title][pr opertyName].length === 1) { | |
| 335 var newObj = obj[title][propertyName][0]; | |
| 336 obj[title][propertyName] = newObj; | |
| 337 } | |
| 338 | |
| 339 propertyValue = ""; | |
| 340 state = states.FirstClose; | |
| 341 } else { | |
| 342 propertyValue = this._parseValue(); | |
| 343 skipIncrement = true; | |
| 344 } | |
| 345 break; | |
| 346 case states.FirstClose: | |
| 347 if (this._wikiMarkupText[this._position] === "}") | |
| 348 state = states.SecondClose; | |
| 349 else | |
| 350 state = states.Error; | |
| 351 break; | |
| 352 case states.SecondClose: | |
| 353 while (this._position < this._wikiMarkupText.length && this._wik iMarkupText[this._position] === "\n") | |
| 354 this._position++; | |
| 355 return obj; | |
| 356 case states.Error: | |
| 357 this._position = this._wikiMarkupText.length; | |
| 358 return {}; | |
| 359 } | 351 } |
| 360 if (!skipIncrement) | |
| 361 this._position++; | |
| 362 } | 352 } |
| 363 return obj; | 353 return name; |
| 364 }, | 354 }, |
| 365 | 355 |
| 366 /** | 356 /** |
| 367 * @param {string} str | 357 * @return {string} |
| 358 */ | |
| 359 _parseExampleCode: function() | |
| 360 { | |
| 361 var code = ""; | |
| 362 while (this._tokenizer.hasMoreTokens()) { | |
| 363 var token = this._tokenizer.peekToken(); | |
| 364 switch (token.type()) { | |
| 365 case WebInspector.WikiParser.TokenType.ClosingBraces: | |
| 366 return code; | |
| 367 case WebInspector.WikiParser.TokenType.VerticalLine: | |
| 368 this._tokenizer.nextToken(); | |
| 369 return code; | |
| 370 case WebInspector.WikiParser.TokenType.Exclamation: | |
| 371 this._tokenizer.nextToken(); | |
| 372 code += '|'; | |
| 373 break; | |
| 374 case WebInspector.WikiParser.TokenType.EqualSignInBraces: | |
| 375 this._tokenizer.nextToken(); | |
| 376 code += "="; | |
| 377 break; | |
| 378 default: | |
| 379 this._tokenizer.nextToken(); | |
| 380 code += token.value(); | |
| 381 } | |
| 382 } | |
| 383 return code; | |
| 384 }, | |
| 385 | |
| 386 /** | |
| 368 * @return {?WebInspector.WikiParser.Block} | 387 * @return {?WebInspector.WikiParser.Block} |
| 369 */ | 388 */ |
| 370 parseString: function(str) | 389 _parseString: function() |
| 371 { | 390 { |
| 372 this._tokenizer = new WebInspector.WikiParser.Tokenizer(str); | |
| 373 var children = []; | 391 var children = []; |
| 374 var blockChildren = []; | 392 var blockChildren = []; |
| 375 var text = ""; | 393 var text = ""; |
| 376 var self = this; | 394 var self = this; |
| 377 | 395 |
| 378 function processSimpleText() | 396 function processSimpleText() |
| 379 { | 397 { |
| 380 var currentText = self._deleteTrailingSpaces(text); | 398 var currentText = self._deleteTrailingSpaces(text); |
| 381 if (!currentText.length) | 399 if (!currentText.length) |
| 382 return; | 400 return; |
| 383 var simpleText = new WebInspector.WikiParser.PlainText(currentText, false); | 401 var simpleText = new WebInspector.WikiParser.PlainText(currentText, false); |
| 384 blockChildren.push(simpleText); | 402 blockChildren.push(simpleText); |
| 385 text = ""; | 403 text = ""; |
| 386 } | 404 } |
| 387 | 405 |
| 388 function processBlock() | 406 function processBlock() |
| 389 { | 407 { |
| 390 if (blockChildren.length) { | 408 if (blockChildren.length) { |
| 391 children.push(new WebInspector.WikiParser.Block(blockChildren, f alse)); | 409 children.push(new WebInspector.WikiParser.Block(blockChildren, f alse)); |
| 392 blockChildren = []; | 410 blockChildren = []; |
| 393 } | 411 } |
| 394 } | 412 } |
| 395 while (this._tokenizer._hasMoreTokens()) { | 413 |
| 396 var token = this._tokenizer._nextToken(); | 414 while (this._tokenizer.hasMoreTokens()) { |
| 415 var token = this._tokenizer.peekToken(); | |
| 397 switch (token.type()) { | 416 switch (token.type()) { |
| 417 case WebInspector.WikiParser.TokenType.VerticalLine: | |
| 418 this._tokenizer.nextToken(); | |
| 419 case WebInspector.WikiParser.TokenType.ClosingBraces: | |
| 420 processSimpleText(); | |
| 421 processBlock(); | |
| 422 return new WebInspector.WikiParser.Block(children, false); | |
| 398 case WebInspector.WikiParser.TokenType.TripleQuotes: | 423 case WebInspector.WikiParser.TokenType.TripleQuotes: |
| 424 this._tokenizer.nextToken(); | |
| 399 processSimpleText(); | 425 processSimpleText(); |
| 400 var highlightText = this._parseHighlight(); | 426 var highlightText = this._parseHighlight(); |
| 401 blockChildren.push(highlightText) | 427 blockChildren.push(highlightText) |
| 402 break; | 428 break; |
| 403 case WebInspector.WikiParser.TokenType.OpeningBrackets: | 429 case WebInspector.WikiParser.TokenType.OpeningBrackets: |
| 430 this._tokenizer.nextToken(); | |
| 404 processSimpleText(); | 431 processSimpleText(); |
| 405 var link = this._parseLink(); | 432 var link = this._parseLink(); |
| 406 blockChildren.push(link); | 433 blockChildren.push(link); |
| 407 break; | 434 break; |
| 408 case WebInspector.WikiParser.TokenType.OpeningCodeTag: | 435 case WebInspector.WikiParser.TokenType.OpeningCodeTag: |
| 436 this._tokenizer.nextToken(); | |
| 409 processSimpleText(); | 437 processSimpleText(); |
| 410 var code = this._parseCode(); | 438 var code = this._parseCode(); |
| 411 blockChildren.push(code); | 439 blockChildren.push(code); |
| 412 break; | 440 break; |
| 413 case WebInspector.WikiParser.TokenType.Bullet: | 441 case WebInspector.WikiParser.TokenType.Bullet: |
| 442 this._tokenizer.nextToken(); | |
| 414 processSimpleText(); | 443 processSimpleText(); |
| 415 processBlock(); | 444 processBlock(); |
| 416 var bulletText = this._parseBullet(); | 445 var bulletText = this._parseBullet(); |
| 417 children.push(bulletText); | 446 children.push(bulletText); |
| 418 break; | 447 break; |
| 419 case WebInspector.WikiParser.TokenType.CodeBlock: | 448 case WebInspector.WikiParser.TokenType.CodeBlock: |
| 449 this._tokenizer.nextToken(); | |
| 420 processSimpleText(); | 450 processSimpleText(); |
| 421 processBlock(); | 451 processBlock(); |
| 422 var code = new WebInspector.WikiParser.CodeBlock(token.value()); | 452 var code = new WebInspector.WikiParser.CodeBlock(token.value()); |
| 423 children.push(code); | 453 children.push(code); |
| 424 break; | 454 break; |
| 425 case WebInspector.WikiParser.TokenType.LineEnd: | 455 case WebInspector.WikiParser.TokenType.LineEnd: |
| 456 this._tokenizer.nextToken(); | |
| 426 processSimpleText(); | 457 processSimpleText(); |
| 427 processBlock(); | 458 processBlock(); |
| 428 break; | 459 break; |
| 429 case WebInspector.WikiParser.TokenType.VerticalLine: | 460 case WebInspector.WikiParser.TokenType.EqualSignInBraces: |
| 461 this._tokenizer.nextToken(); | |
| 462 text += "="; | |
| 463 break; | |
| 464 case WebInspector.WikiParser.TokenType.Exclamation: | |
| 465 this._tokenizer.nextToken(); | |
| 466 text += "|"; | |
| 467 break; | |
| 468 case WebInspector.WikiParser.TokenType.ClosingBrackets: | |
| 430 case WebInspector.WikiParser.TokenType.Text: | 469 case WebInspector.WikiParser.TokenType.Text: |
| 470 case WebInspector.WikiParser.TokenType.Space: | |
| 471 case WebInspector.WikiParser.TokenType.EqualSign: | |
| 472 this._tokenizer.nextToken(); | |
| 431 text += token.value(); | 473 text += token.value(); |
| 432 break; | 474 break; |
| 433 default: | 475 default: |
| 476 this._tokenizer.nextToken(); | |
| 434 return null; | 477 return null; |
| 435 } | 478 } |
| 436 } | 479 } |
| 437 | 480 |
| 438 processSimpleText(); | 481 processSimpleText(); |
| 439 processBlock(); | 482 processBlock(); |
| 440 | 483 |
| 441 return new WebInspector.WikiParser.Block(children, false); | 484 return new WebInspector.WikiParser.Block(children, false); |
| 442 }, | 485 }, |
| 443 | 486 |
| 444 /** | 487 /** |
| 445 * @return {!WebInspector.WikiParser.Link} | 488 * @return {!WebInspector.WikiParser.Link} |
| 446 */ | 489 */ |
| 447 _parseLink: function() | 490 _parseLink: function() |
| 448 { | 491 { |
| 449 var url = ""; | 492 var url = ""; |
| 450 var children = []; | 493 var children = []; |
| 451 while (this._tokenizer._hasMoreTokens()) { | 494 while (this._tokenizer.hasMoreTokens()) { |
| 452 var token = this._tokenizer._nextToken(); | 495 var token = this._tokenizer.nextToken(); |
| 453 switch (token.type()) { | 496 switch (token.type()) { |
| 454 case WebInspector.WikiParser.TokenType.ClosingBrackets: | 497 case WebInspector.WikiParser.TokenType.ClosingBrackets: |
| 455 return new WebInspector.WikiParser.Link(url, children); | 498 return new WebInspector.WikiParser.Link(url, children); |
| 456 case WebInspector.WikiParser.TokenType.VerticalLine: | 499 case WebInspector.WikiParser.TokenType.VerticalLine: |
| 500 case WebInspector.WikiParser.TokenType.Exclamation: | |
| 457 children.push(this._parseLinkName()); | 501 children.push(this._parseLinkName()); |
| 458 return new WebInspector.WikiParser.Link(url, children); | 502 return new WebInspector.WikiParser.Link(url, children); |
| 459 default: | 503 default: |
| 460 url += token.value(); | 504 url += token.value(); |
| 461 } | 505 } |
| 462 } | 506 } |
| 463 | 507 |
| 464 return new WebInspector.WikiParser.Link(url, children); | 508 return new WebInspector.WikiParser.Link(url, children); |
| 465 }, | 509 }, |
| 466 | 510 |
| 467 /** | 511 /** |
| 468 * @return {!WebInspector.WikiParser.Inline} | 512 * @return {!WebInspector.WikiParser.Inline} |
| 469 */ | 513 */ |
| 470 _parseLinkName: function() | 514 _parseLinkName: function() |
| 471 { | 515 { |
| 472 var children = []; | 516 var children = []; |
| 473 while (this._tokenizer._hasMoreTokens()) { | 517 var text = ""; |
| 474 var token = this._tokenizer._nextToken(); | 518 var self = this; |
| 519 function processSimpleText() | |
| 520 { | |
| 521 text = self._deleteTrailingSpaces(text); | |
| 522 if (!text.length) | |
| 523 return; | |
| 524 var simpleText = new WebInspector.WikiParser.PlainText(text, false); | |
| 525 children.push(simpleText); | |
| 526 text = ""; | |
| 527 } | |
| 528 | |
| 529 while (this._tokenizer.hasMoreTokens()) { | |
| 530 var token = this._tokenizer.nextToken(); | |
| 475 switch (token.type()) { | 531 switch (token.type()) { |
| 476 case WebInspector.WikiParser.TokenType.ClosingBrackets: | 532 case WebInspector.WikiParser.TokenType.ClosingBrackets: |
| 533 processSimpleText(); | |
| 477 return new WebInspector.WikiParser.Inline(WebInspector.WikiParse r.ArticleElement.Type.Inline, children); | 534 return new WebInspector.WikiParser.Inline(WebInspector.WikiParse r.ArticleElement.Type.Inline, children); |
| 478 case WebInspector.WikiParser.TokenType.OpeningCodeTag: | 535 case WebInspector.WikiParser.TokenType.OpeningCodeTag: |
| 536 processSimpleText(); | |
| 479 children.push(this._parseCode()); | 537 children.push(this._parseCode()); |
| 480 break; | 538 break; |
| 481 default: | 539 default: |
| 482 children.push(new WebInspector.WikiParser.PlainText(token.value( ), false)); | 540 text += token.value(); |
| 483 break; | 541 break; |
| 484 } | 542 } |
| 485 } | 543 } |
| 486 | 544 |
| 487 return new WebInspector.WikiParser.Inline(WebInspector.WikiParser.Articl eElement.Type.Inline, children); | 545 return new WebInspector.WikiParser.Inline(WebInspector.WikiParser.Articl eElement.Type.Inline, children); |
| 488 }, | 546 }, |
| 489 | 547 |
| 490 /** | 548 /** |
| 491 * @return {!WebInspector.WikiParser.Inline} | 549 * @return {!WebInspector.WikiParser.Inline} |
| 492 */ | 550 */ |
| 493 _parseCode : function() | 551 _parseCode : function() |
| 494 { | 552 { |
| 495 var children = []; | 553 var children = []; |
| 496 var text = ""; | 554 var text = ""; |
| 497 while (this._tokenizer._hasMoreTokens()) { | 555 while (this._tokenizer.hasMoreTokens()) { |
| 498 var token = this._tokenizer._nextToken(); | 556 var token = this._tokenizer.nextToken(); |
| 499 switch (token.type()) { | 557 switch (token.type()) { |
| 500 case WebInspector.WikiParser.TokenType.ClosingCodeTag: | 558 case WebInspector.WikiParser.TokenType.ClosingCodeTag: |
| 501 text = this._deleteTrailingSpaces(text); | 559 text = this._deleteTrailingSpaces(text); |
| 502 if (text.length) { | 560 if (text.length) { |
| 503 var simpleText = new WebInspector.WikiParser.PlainText(text, false); | 561 var simpleText = new WebInspector.WikiParser.PlainText(text, false); |
| 504 children.push(simpleText); | 562 children.push(simpleText); |
| 505 text = ""; | 563 text = ""; |
| 506 } | 564 } |
| 507 var code = new WebInspector.WikiParser.Inline(WebInspector.WikiP arser.ArticleElement.Type.Code, children); | 565 var code = new WebInspector.WikiParser.Inline(WebInspector.WikiP arser.ArticleElement.Type.Code, children); |
| 508 return code; | 566 return code; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 521 | 579 |
| 522 return new WebInspector.WikiParser.Inline(WebInspector.WikiParser.Articl eElement.Type.Code, children); | 580 return new WebInspector.WikiParser.Inline(WebInspector.WikiParser.Articl eElement.Type.Code, children); |
| 523 }, | 581 }, |
| 524 | 582 |
| 525 /** | 583 /** |
| 526 * @return {!WebInspector.WikiParser.Block} | 584 * @return {!WebInspector.WikiParser.Block} |
| 527 */ | 585 */ |
| 528 _parseBullet: function() | 586 _parseBullet: function() |
| 529 { | 587 { |
| 530 var children = []; | 588 var children = []; |
| 531 while (this._tokenizer._hasMoreTokens()) { | 589 while (this._tokenizer.hasMoreTokens()) { |
| 532 var token = this._tokenizer._nextToken() | 590 var token = this._tokenizer.nextToken() |
| 533 switch (token.type()) { | 591 switch (token.type()) { |
| 534 case WebInspector.WikiParser.TokenType.OpeningBrackets: | 592 case WebInspector.WikiParser.TokenType.OpeningBrackets: |
| 535 children.push(this._parseLink()); | 593 children.push(this._parseLink()); |
| 536 break; | 594 break; |
| 537 case WebInspector.WikiParser.TokenType.OpeningCodeTag: | 595 case WebInspector.WikiParser.TokenType.OpeningCodeTag: |
| 538 children.push(this._parseCode()); | 596 children.push(this._parseCode()); |
| 539 break; | 597 break; |
| 540 case WebInspector.WikiParser.TokenType.LineEnd: | 598 case WebInspector.WikiParser.TokenType.LineEnd: |
| 541 return new WebInspector.WikiParser.Block(children, true); | 599 return new WebInspector.WikiParser.Block(children, true); |
| 542 default: | 600 default: |
| 543 var text = this._deleteTrailingSpaces(token.value()); | 601 var text = this._deleteTrailingSpaces(token.value()); |
| 544 if (text.length) { | 602 if (text.length) { |
| 545 var simpleText = new WebInspector.WikiParser.PlainText(text, false); | 603 var simpleText = new WebInspector.WikiParser.PlainText(text, false); |
| 546 children.push(simpleText); | 604 children.push(simpleText); |
| 547 text = ""; | 605 text = ""; |
| 548 } | 606 } |
| 549 } | 607 } |
| 550 } | 608 } |
| 551 | 609 |
| 552 return new WebInspector.WikiParser.Block(children, true); | 610 return new WebInspector.WikiParser.Block(children, true); |
| 553 }, | 611 }, |
| 554 | 612 |
| 555 /** | 613 /** |
| 556 * @return {!WebInspector.WikiParser.PlainText} | 614 * @return {!WebInspector.WikiParser.PlainText} |
| 557 */ | 615 */ |
| 558 _parseHighlight: function() | 616 _parseHighlight: function() |
| 559 { | 617 { |
| 560 var text = ""; | 618 var text = ""; |
| 561 while (this._tokenizer._hasMoreTokens()) { | 619 while (this._tokenizer.hasMoreTokens()) { |
| 562 var token = this._tokenizer._nextToken() | 620 var token = this._tokenizer.nextToken() |
| 563 switch (token.type()) { | 621 switch (token.type()) { |
| 564 case WebInspector.WikiParser.TokenType.TripleQuotes: | 622 case WebInspector.WikiParser.TokenType.TripleQuotes: |
| 565 text = this._deleteTrailingSpaces(text); | 623 text = this._deleteTrailingSpaces(text); |
| 566 return new WebInspector.WikiParser.PlainText(text, true); | 624 return new WebInspector.WikiParser.PlainText(text, true); |
| 567 default: | 625 default: |
| 568 text += token.value(); | 626 text += token.value(); |
| 569 } | 627 } |
| 570 } | 628 } |
| 571 return new WebInspector.WikiParser.PlainText(text, true); | 629 return new WebInspector.WikiParser.PlainText(text, true); |
| 572 }, | 630 }, |
| 573 | 631 |
| 574 /** | 632 /** |
| 575 * @param {string} str | 633 * @param {string} str |
| 576 * @return {string} | 634 * @return {string} |
| 577 */ | 635 */ |
| 578 _deleteTrailingSpaces: function(str) | 636 _deleteTrailingSpaces: function(str) |
| 579 { | 637 { |
| 580 return str.replace(/[\n\r]*$/gm, ""); | 638 return str.replace(/[\n\r]*$/gm, ""); |
| 581 } | 639 } |
| 582 } | 640 } |
| 583 | 641 |
| 584 WebInspector.WikiParser.oneOpeningBracket = /^\n* \[[^\[]/; | |
| 585 WebInspector.WikiParser.twoOpeningBrackets = /^\n* \[\[/; | |
| 586 WebInspector.WikiParser.oneClosingBracket = /^\n*\][^\]] /; | |
| 587 WebInspector.WikiParser.twoClosingBrackets = /^\n*\]\]/; | |
| 588 WebInspector.WikiParser.tripleQuotes = /^\n*'''/; | |
| 589 WebInspector.WikiParser.openingCodeTag = /^<\s*code\s*>/; | |
| 590 WebInspector.WikiParser.closingCodeTag = /^<\s*\/\s*code\s*>/; | |
| 591 WebInspector.WikiParser.closingBullet = /^\*/; | |
| 592 WebInspector.WikiParser.lineEnd = /^\n/; | |
| 593 WebInspector.WikiParser.verticalLine = /^\|/; | |
| 594 WebInspector.WikiParser.newLineWithSpace = /^\n /; | |
| 595 WebInspector.WikiParser.newLineWithoutSpace = /\n[^ ]/; | |
| 596 | |
| 597 /** | |
| 598 * @constructor | |
| 599 * @param {!RegExp} regex | |
| 600 * @param {!WebInspector.WikiParser.TokenType} type | |
| 601 */ | |
| 602 WebInspector.WikiParser.TokenDescriptor = function(regex, type) | |
| 603 { | |
| 604 this.regex = regex; | |
| 605 this.type = type; | |
| 606 } | |
| 607 | |
| 608 WebInspector.WikiParser._tokenDescriptors = [ | |
| 609 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.newLineW ithSpace, WebInspector.WikiParser.TokenType.CodeBlock), | |
| 610 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.tripleQu otes, WebInspector.WikiParser.TokenType.TripleQuotes), | |
| 611 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.oneOpeni ngBracket, WebInspector.WikiParser.TokenType.OpeningBrackets), | |
| 612 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.twoOpeni ngBrackets, WebInspector.WikiParser.TokenType.OpeningBrackets), | |
| 613 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.oneClosi ngBracket, WebInspector.WikiParser.TokenType.ClosingBrackets), | |
| 614 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.twoClosi ngBrackets, WebInspector.WikiParser.TokenType.ClosingBrackets), | |
| 615 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.openingC odeTag, WebInspector.WikiParser.TokenType.OpeningCodeTag), | |
| 616 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingC odeTag, WebInspector.WikiParser.TokenType.ClosingCodeTag), | |
| 617 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingB ullet, WebInspector.WikiParser.TokenType.Bullet), | |
| 618 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.vertical Line, WebInspector.WikiParser.TokenType.VerticalLine), | |
| 619 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.lineEnd, WebInspector.WikiParser.TokenType.LineEnd) | |
| 620 ]; | |
| 621 | |
| 622 /** | 642 /** |
| 623 * @constructor | 643 * @constructor |
| 624 * @param {!WebInspector.WikiParser.ArticleElement.Type} type | 644 * @param {!WebInspector.WikiParser.ArticleElement.Type} type |
| 625 */ | 645 */ |
| 626 WebInspector.WikiParser.ArticleElement = function(type) | 646 WebInspector.WikiParser.ArticleElement = function(type) |
| 627 { | 647 { |
| 628 this._type = type; | 648 this._type = type; |
| 629 } | 649 } |
| 630 | 650 |
| 631 WebInspector.WikiParser.ArticleElement.prototype = { | 651 WebInspector.WikiParser.ArticleElement.prototype = { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 779 /** | 799 /** |
| 780 * @return {string} | 800 * @return {string} |
| 781 */ | 801 */ |
| 782 url : function() | 802 url : function() |
| 783 { | 803 { |
| 784 return this._url; | 804 return this._url; |
| 785 }, | 805 }, |
| 786 | 806 |
| 787 __proto__: WebInspector.WikiParser.Inline.prototype | 807 __proto__: WebInspector.WikiParser.Inline.prototype |
| 788 } | 808 } |
| OLD | NEW |