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.unescapeHTML(); |
12 this._wikiMarkupText = wikiMarkupText; | 12 this._tokenizer = new WebInspector.WikiParser.Tokenizer(text); |
13 this._document = this._parse(); | 13 this._document = this._parse(); |
14 /** @type {?WebInspector.WikiParser.Tokenizer} */ | |
15 this._tokenizer; | |
16 } | 14 } |
17 | 15 |
18 /** | 16 /** |
19 * @package | 17 * @constructor |
20 * @enum {string} | |
21 */ | 18 */ |
22 WebInspector.WikiParser.State = { | 19 WebInspector.WikiParser.Section = function() |
23 Error: "Error", | 20 { |
24 FirstOpen: "FirstOpen", | 21 /** @type {string} */ |
25 SecondOpen: "SecondOpen", | 22 this.title; |
26 Title: "Title", | 23 /** @type {?WebInspector.WikiParser.Values} */ |
apavlov
2014/09/10 14:09:24
blank lines before jsdocs
iliia
2014/09/11 09:26:30
Done.
| |
27 PropertyName: "PropertyName", | 24 this.values; |
28 PropertyValue: "PropertyValue", | 25 /** @type {?WebInspector.WikiParser.ArticleElement} */ |
29 FirstClose: "FirstClose", | 26 this.singleValue; |
30 SecondClose: "SecondClose" | |
31 } | 27 } |
32 | 28 |
33 /** | 29 /** |
34 * @package | 30 * @constructor |
35 * @enum {string} | |
36 */ | 31 */ |
37 WebInspector.WikiParser.LinkStates = { | 32 WebInspector.WikiParser.Field = function() |
38 Error: "Error", | 33 { |
39 LinkUrl: "LinkUrl", | 34 /** @type {string} */ |
40 LinkName: "LinkName" | 35 this.name; |
36 /** @type {?WebInspector.WikiParser.FieldValue} */ | |
apavlov
2014/09/10 14:09:23
ditto
iliia
2014/09/11 09:26:30
Done.
| |
37 this.value; | |
41 } | 38 } |
42 | 39 |
43 /** | 40 /** @typedef {(?WebInspector.WikiParser.ArticleElement|!Array.<!WebInspector.Wik iParser.Section>)} */ |
44 * @package | 41 WebInspector.WikiParser.FieldValue; |
45 * @enum {string} | 42 /** @typedef {?Object.<string, !WebInspector.WikiParser.FieldValue>} */ |
apavlov
2014/09/10 14:09:24
ditto
iliia
2014/09/11 09:26:30
Done.
| |
46 */ | 43 WebInspector.WikiParser.Values; |
47 WebInspector.WikiParser.HtmlStates = { | 44 /** @typedef {(?WebInspector.WikiParser.Value|?WebInspector.WikiParser.ArticleEl ement)} */ |
48 Error: "Error", | 45 WebInspector.WikiParser.Value; |
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 | 46 |
64 /** | 47 /** |
65 * @package | 48 * @package |
66 * @enum {string} | 49 * @enum {string} |
67 */ | 50 */ |
68 WebInspector.WikiParser.TokenType = { | 51 WebInspector.WikiParser.TokenType = { |
52 Text: "Text", | |
53 Table: "Table", | |
54 OpeningBraces: "OpeningBraces", | |
55 ClosingBraces: "ClosingBraces", | |
56 Exclamation: "Exclamation", | |
57 OpeningBrackets: "OpeningBrackets", | |
58 ClosingBrackets: "ClosingBrackets", | |
59 EqualSign: "EqualSign", | |
60 EqualSignInBraces: "EqualSignInBraces", | |
61 VerticalLine: "VerticalLine", | |
69 TripleQuotes: "TripleQuotes", | 62 TripleQuotes: "TripleQuotes", |
70 OpeningBrackets: "OpeningBrackets", | |
71 OpeningCodeTag: "OpeningCodeTag", | 63 OpeningCodeTag: "OpeningCodeTag", |
72 ClosingBrackets: "ClosingBrackets", | |
73 ClosingCodeTag: "ClosingCodeTag", | 64 ClosingCodeTag: "ClosingCodeTag", |
74 Bullet: "Bullet", | 65 Bullet: "Bullet", |
75 Text: "Text", | |
76 VerticalLine: "VerticalLine", | |
77 LineEnd: "LineEnd", | 66 LineEnd: "LineEnd", |
78 CodeBlock: "CodeBlock" | 67 CodeBlock: "CodeBlock" |
79 } | 68 } |
80 | 69 |
81 /** | 70 /** |
82 * @constructor | 71 * @constructor |
83 * @param {string} result | 72 * @param {string} result |
84 * @param {!WebInspector.WikiParser.TokenType} type | 73 * @param {!WebInspector.WikiParser.TokenType} type |
85 */ | 74 */ |
86 WebInspector.WikiParser.Token = function(result, type) | 75 WebInspector.WikiParser.Token = function(result, type) |
(...skipping 20 matching lines...) Expand all Loading... | |
107 } | 96 } |
108 } | 97 } |
109 | 98 |
110 /** | 99 /** |
111 * @constructor | 100 * @constructor |
112 * @param {string} str | 101 * @param {string} str |
113 */ | 102 */ |
114 WebInspector.WikiParser.Tokenizer = function(str) | 103 WebInspector.WikiParser.Tokenizer = function(str) |
115 { | 104 { |
116 this._text = str; | 105 this._text = str; |
106 this._token = this._internalNextToken(); | |
117 } | 107 } |
118 | 108 |
119 WebInspector.WikiParser.Tokenizer.prototype = { | 109 WebInspector.WikiParser.Tokenizer.prototype = { |
120 /** | 110 /** |
121 * @return {!WebInspector.WikiParser.Token} | 111 * @return {!WebInspector.WikiParser.Token} |
122 */ | 112 */ |
123 _nextToken: function() | 113 peekToken: function() |
114 { | |
115 return this._token; | |
116 }, | |
117 | |
118 /** | |
119 * @return {!WebInspector.WikiParser.Token} | |
120 */ | |
121 nextToken: function() | |
122 { | |
123 var token = this._token; | |
124 this._token = this._internalNextToken(); | |
125 return token; | |
126 }, | |
127 | |
128 /** | |
129 * @return {!WebInspector.WikiParser.Token} | |
130 */ | |
131 _internalNextToken: function() | |
124 { | 132 { |
125 if (WebInspector.WikiParser.newLineWithSpace.test(this._text)) { | 133 if (WebInspector.WikiParser.newLineWithSpace.test(this._text)) { |
126 var result = WebInspector.WikiParser.newLineWithSpace.exec(this._tex t); | 134 var result = WebInspector.WikiParser.newLineWithSpace.exec(this._tex t); |
127 var begin = result.index + result[0].length; | 135 var begin = result.index + result[0].length - 3; |
128 var end = this._text.length; | 136 var end = this._text.length; |
129 var lineEnd = WebInspector.WikiParser.newLineWithoutSpace.exec(this. _text); | 137 var lineEnd = WebInspector.WikiParser.newLineWithoutSpace.exec(this. _text); |
130 if (lineEnd) | 138 if (lineEnd) |
131 end = lineEnd.index; | 139 end = lineEnd.index; |
132 var token = this._text.substring(begin, end).replace(/\n */g, "\n"); | 140 var token = this._text.substring(begin, end).replace(/\n /g, "\n").r eplace(/{{=}}/g, "="); |
133 this._text = this._text.substring(end + 1); | 141 this._text = this._text.substring(end + 1); |
134 return new WebInspector.WikiParser.Token(token, WebInspector.WikiPar ser.TokenType.CodeBlock); | 142 return new WebInspector.WikiParser.Token(token, WebInspector.WikiPar ser.TokenType.CodeBlock); |
135 } | 143 } |
136 | 144 |
137 for (var i = 0; i < WebInspector.WikiParser._tokenDescriptors.length; ++ i) { | 145 for (var i = 0; i < WebInspector.WikiParser._tokenDescriptors.length; ++ i) { |
138 var result = WebInspector.WikiParser._tokenDescriptors[i].regex.exec (this._text); | 146 var result = WebInspector.WikiParser._tokenDescriptors[i].regex.exec (this._text); |
139 if (result) { | 147 if (result) { |
140 this._text = this._text.substring(result.index + result[0].lengt h); | 148 this._text = this._text.substring(result.index + result[0].lengt h); |
141 return new WebInspector.WikiParser.Token(result[0], WebInspector .WikiParser._tokenDescriptors[i].type); | 149 return new WebInspector.WikiParser.Token(result[0], WebInspector .WikiParser._tokenDescriptors[i].type); |
142 } | 150 } |
143 } | 151 } |
144 | 152 |
145 for (var lastIndex = 0; lastIndex < this._text.length; ++lastIndex) { | 153 for (var lastIndex = 0; lastIndex < this._text.length; ++lastIndex) { |
146 var testString = this._text.substring(lastIndex); | 154 var testString = this._text.substring(lastIndex); |
147 for (var i = 0; i < WebInspector.WikiParser._tokenDescriptors.length ; ++i) { | 155 for (var i = 0; i < WebInspector.WikiParser._tokenDescriptors.length ; ++i) { |
148 if (WebInspector.WikiParser._tokenDescriptors[i].regex.test(test String)) { | 156 if (WebInspector.WikiParser._tokenDescriptors[i].regex.test(test String)) { |
149 var token = this._text.substring(0, lastIndex); | 157 var token = this._text.substring(0, lastIndex); |
150 this._text = this._text.substring(lastIndex); | 158 this._text = this._text.substring(lastIndex); |
151 return new WebInspector.WikiParser.Token(token, WebInspector .WikiParser.TokenType.Text); | 159 return new WebInspector.WikiParser.Token(token, WebInspector .WikiParser.TokenType.Text); |
152 } | 160 } |
153 } | 161 } |
154 } | 162 } |
155 | 163 |
156 var token = this._text; | 164 var token = this._text; |
157 this._text = ""; | 165 this._text = ""; |
158 return new WebInspector.WikiParser.Token(token, WebInspector.WikiParser. TokenType.Text); | 166 return new WebInspector.WikiParser.Token(token, WebInspector.WikiParser. TokenType.Text); |
159 }, | 167 }, |
160 | 168 |
161 /** | 169 /** |
170 * @return {!WebInspector.WikiParser.Tokenizer} | |
171 */ | |
172 clone: function() | |
173 { | |
174 var tokenizer = new WebInspector.WikiParser.Tokenizer(this._text); | |
175 tokenizer._token = this._token; | |
176 tokenizer._text = this._text; | |
177 return tokenizer; | |
178 }, | |
179 | |
180 /** | |
162 * @return {boolean} | 181 * @return {boolean} |
163 */ | 182 */ |
164 _hasMoreTokens: function() | 183 hasMoreTokens: function() |
165 { | 184 { |
166 return !!this._text.length; | 185 return !!this._text.length; |
167 } | 186 } |
168 } | 187 } |
169 | 188 |
189 WebInspector.WikiParser.table = /^{{{!}}/; | |
190 WebInspector.WikiParser.exclamation = /^{{!}}/; | |
191 WebInspector.WikiParser.openingBraces = /^{{/; | |
192 WebInspector.WikiParser.equalSign = /^=/; | |
193 WebInspector.WikiParser.equalSignInBraces = /^{{=}}/; | |
194 WebInspector.WikiParser.closingBraces = /^\s*}}/; | |
195 WebInspector.WikiParser.oneOpeningBracketWithSpace = /^\n* \[/; | |
196 WebInspector.WikiParser.twoOpeningBracketsWithSpace = /^\n* \[\[/; | |
197 WebInspector.WikiParser.oneClosingBracket = /^\n*\]/; | |
198 WebInspector.WikiParser.twoClosingBrackets = /^\n*\]\]/; | |
199 WebInspector.WikiParser.tripleQuotes = /^\n*'''/; | |
200 WebInspector.WikiParser.openingCodeTag = /^<\s*code\s*>/; | |
201 WebInspector.WikiParser.closingCodeTag = /^<\s*\/\s*code\s*>/; | |
202 WebInspector.WikiParser.closingBullet = /^\*/; | |
203 WebInspector.WikiParser.lineEnd = /^\n/; | |
204 WebInspector.WikiParser.verticalLine = /^\n*\|/; | |
205 WebInspector.WikiParser.newLineWithSpace = /^\n [^ ]/; | |
206 WebInspector.WikiParser.newLineWithoutSpace = /\n[^ ]/; | |
207 | |
208 /** | |
209 * @constructor | |
210 * @param {!RegExp} regex | |
211 * @param {!WebInspector.WikiParser.TokenType} type | |
212 */ | |
213 WebInspector.WikiParser.TokenDescriptor = function(regex, type) | |
214 { | |
215 this.regex = regex; | |
216 this.type = type; | |
217 } | |
218 | |
219 WebInspector.WikiParser._tokenDescriptors = [ | |
220 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.exclamat ion, WebInspector.WikiParser.TokenType.Exclamation), | |
221 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.equalSig nInBraces, WebInspector.WikiParser.TokenType.EqualSignInBraces), | |
222 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.equalSig n, WebInspector.WikiParser.TokenType.EqualSign), | |
223 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.table, W ebInspector.WikiParser.TokenType.Table), | |
224 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.openingB races, WebInspector.WikiParser.TokenType.OpeningBraces), | |
225 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.vertical Line, WebInspector.WikiParser.TokenType.VerticalLine), | |
226 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingB races, WebInspector.WikiParser.TokenType.ClosingBraces), | |
227 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.twoOpeni ngBracketsWithSpace, WebInspector.WikiParser.TokenType.OpeningBrackets), | |
228 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.twoClosi ngBrackets, WebInspector.WikiParser.TokenType.ClosingBrackets), | |
229 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.oneOpeni ngBracketWithSpace, WebInspector.WikiParser.TokenType.OpeningBrackets), | |
230 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.oneClosi ngBracket, WebInspector.WikiParser.TokenType.ClosingBrackets), | |
231 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.newLineW ithSpace, WebInspector.WikiParser.TokenType.CodeBlock), | |
232 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.tripleQu otes, WebInspector.WikiParser.TokenType.TripleQuotes), | |
233 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.openingC odeTag, WebInspector.WikiParser.TokenType.OpeningCodeTag), | |
234 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingC odeTag, WebInspector.WikiParser.TokenType.ClosingCodeTag), | |
235 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingB ullet, WebInspector.WikiParser.TokenType.Bullet), | |
236 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.lineEnd, WebInspector.WikiParser.TokenType.LineEnd) | |
237 ] | |
238 | |
170 WebInspector.WikiParser.prototype = { | 239 WebInspector.WikiParser.prototype = { |
171 /** | 240 /** |
172 * @return {!Object} | 241 * @return {!Object} |
173 */ | 242 */ |
174 document: function() | 243 document: function() |
175 { | 244 { |
176 return this._document; | 245 return this._document; |
177 }, | 246 }, |
178 | 247 |
179 /** | 248 /** |
180 * @return {!Object} | 249 * @return {?WebInspector.WikiParser.TokenType} |
250 */ | |
251 _secondTokenType: function() | |
apavlov
2014/09/10 14:09:23
why not just save and restore the state of the cur
iliia
2014/09/11 09:26:31
Clone is a saving copy of the state of current tok
apavlov
2014/09/11 10:40:26
I know that cloning implicitly allows to retain th
| |
252 { | |
253 var tokenizer = this._tokenizer.clone(); | |
254 if (!tokenizer.hasMoreTokens()) | |
255 return null; | |
256 tokenizer.nextToken(); | |
257 if (!tokenizer.hasMoreTokens()) | |
258 return null; | |
259 return tokenizer.nextToken().type(); | |
260 }, | |
261 | |
262 /** | |
263 * @return {!Object.<string, ?WebInspector.WikiParser.Value>} | |
181 */ | 264 */ |
182 _parse: function() | 265 _parse: function() |
183 { | 266 { |
184 var obj = {}; | 267 var obj = {}; |
185 this._wikiMarkupText = this._wikiMarkupText.replace(/</g, "<") | 268 while (this._tokenizer.hasMoreTokens()) { |
186 .replace(/>/g, ">") | 269 var section = this._parseSection(); |
187 .replace(/:/g, ":") | 270 if (section.title) { |
188 .replace(/"/g, "\"") | 271 if (section.singleValue) |
189 .replace(/</g, "<") | 272 obj[section.title] = section.singleValue; |
190 .replace(/>/g, ">") | 273 else |
191 .replace(/{{=}}/g, "=") | 274 obj[section.title] = section.values; |
192 .replace(/{{!}}/g, "|") | |
193 .replace(/&/g, "&"); | |
194 while (this._position < this._wikiMarkupText.length) { | |
195 var field = this._parseField(); | |
196 for (var key in field) { | |
197 console.assert(typeof obj[key] === "undefined", "Duplicate key: " + key); | |
198 obj[key] = field[key]; | |
199 } | 275 } |
200 } | 276 } |
201 return obj; | 277 return obj; |
202 }, | 278 }, |
203 | 279 |
204 /** | 280 /** |
281 * @return {!WebInspector.WikiParser.Section} | |
282 */ | |
283 _parseSection: function() | |
284 { | |
285 var section = new WebInspector.WikiParser.Section(); | |
286 if (!this._tokenizer.hasMoreTokens() || this._tokenizer.nextToken().type () !== WebInspector.WikiParser.TokenType.OpeningBraces) | |
287 return section; | |
288 | |
289 var title = this._deleteTrailingSpaces(this._parseTitle()); | |
290 if (!title.length) | |
291 return section; | |
292 section.title = title; | |
293 if (this._tokenizer.peekToken().type() === WebInspector.WikiParser.Token Type.ClosingBraces) { | |
294 this._tokenizer.nextToken(); | |
295 return section; | |
296 } | |
297 var secondTokenType = this._secondTokenType(); | |
298 if (!secondTokenType || secondTokenType !== WebInspector.WikiParser.Toke nType.EqualSign) { | |
299 section.singleValue = this._parseString(); | |
300 } else { | |
301 section.values = {}; | |
302 while (this._tokenizer.hasMoreTokens()) { | |
303 var field = this._parseField(); | |
304 section.values[field.name] = field.value; | |
305 if (this._tokenizer.peekToken().type() === WebInspector.WikiPars er.TokenType.ClosingBraces) { | |
306 this._tokenizer.nextToken(); | |
307 return section; | |
308 } | |
309 } | |
310 } | |
311 var token = this._tokenizer.nextToken(); | |
312 if (token.type() !== WebInspector.WikiParser.TokenType.ClosingBraces) | |
313 throw new Error("Two closing braces expected; found " + token.value( )); | |
314 | |
315 return section; | |
316 }, | |
317 | |
318 /** | |
319 * @return {!WebInspector.WikiParser.Field} | |
320 */ | |
321 _parseField: function() | |
322 { | |
323 var field = new WebInspector.WikiParser.Field; | |
apavlov
2014/09/10 14:09:23
new ...Field();
iliia
2014/09/11 09:26:30
Done.
| |
324 field.name = this._parseName(); | |
325 var token = this._tokenizer.peekToken(); | |
326 switch (token.type()) { | |
327 case WebInspector.WikiParser.TokenType.OpeningBraces: | |
328 field.value = this._parseArray(); | |
329 break; | |
330 case WebInspector.WikiParser.TokenType.LineEnd: | |
331 this._tokenizer.nextToken(); | |
332 break; | |
333 case WebInspector.WikiParser.TokenType.ClosingBraces: | |
334 return field; | |
335 break; | |
336 default: | |
337 if (field.name === "Code") | |
338 field.value = this._parseExampleCode(); | |
339 else | |
340 field.value = this._parseString(); | |
341 } | |
342 return field; | |
343 }, | |
344 | |
345 /** | |
346 * @return {!Array.<!WebInspector.WikiParser.Section>} | |
347 */ | |
348 _parseArray: function() | |
349 { | |
350 var array = []; | |
351 while (this._tokenizer.peekToken().type() === WebInspector.WikiParser.To kenType.OpeningBraces) | |
352 array.push(this._parseSection()); | |
353 if (this._tokenizer.peekToken().type() === WebInspector.WikiParser.Token Type.VerticalLine) | |
354 this._tokenizer.nextToken(); | |
355 return array; | |
356 }, | |
357 | |
358 /** | |
205 * @return {string} | 359 * @return {string} |
206 */ | 360 */ |
207 _parseValue: function() { | 361 _parseTitle: function() |
208 var states = WebInspector.WikiParser.ValueState; | 362 { |
209 var state = states.Outside; | |
210 var value = ""; | |
211 while (this._position < this._wikiMarkupText.length) { | |
212 switch (state) { | |
213 case states.Outside: | |
214 if (this._wikiMarkupText[this._position] === "|" || (this._wikiM arkupText[this._position] === "}" && this._wikiMarkupText[this._position + 1] == = "}")) | |
215 return value; | |
216 switch (this._wikiMarkupText[this._position]) { | |
217 case "<": | |
218 var indexClose = this._wikiMarkupText.indexOf(">", this._pos ition); | |
219 if (indexClose !== -1) { | |
220 value += this._wikiMarkupText.substring(this._position, indexClose + 1); | |
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; | |
232 case states.InsideSquare: | |
233 if (this._wikiMarkupText[this._position] === "[") { | |
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 } | |
249 this._position++; | |
250 } | |
251 return value; | |
252 }, | |
253 | |
254 /** | |
255 * @return {!Object} | |
256 */ | |
257 _parseField: function() | |
258 { | |
259 var obj = {}; | |
260 var title = ""; | 363 var title = ""; |
261 var propertyName = ""; | 364 while (this._tokenizer.hasMoreTokens()) { |
262 var propertyValue = ""; | 365 var token = this._tokenizer.peekToken(); |
263 var states = WebInspector.WikiParser.State; | 366 switch (token.type()) { |
264 var state = states.FirstOpen; | 367 case WebInspector.WikiParser.TokenType.ClosingBraces: |
265 while (this._position < this._wikiMarkupText.length) { | 368 return title; |
266 var skipIncrement = false; | 369 case WebInspector.WikiParser.TokenType.VerticalLine: |
267 switch (state) { | 370 this._tokenizer.nextToken(); |
268 case states.FirstOpen: | 371 return title; |
269 if (this._wikiMarkupText[this._position] === "{") | 372 case WebInspector.WikiParser.TokenType.Text: |
270 state = states.SecondOpen; | 373 title += this._tokenizer.nextToken().value(); |
271 else | 374 break; |
apavlov
2014/09/10 14:09:24
"return title;" for consistency?
iliia
2014/09/11 09:26:31
We must return title only then we met | or }}, so
apavlov
2014/09/11 10:40:26
Oops, misread the code, thanks.
| |
272 state = states.Error; | 375 default: |
273 break; | 376 throw new Error("Title could not be parsed. Unexpected token " + token.value()); |
274 case states.SecondOpen: | 377 } |
275 if (this._wikiMarkupText[this._position] === "{") | 378 } |
276 state = states.Title; | 379 return title; |
277 else | 380 }, |
278 state = states.Error; | 381 |
279 break; | 382 /** |
280 case states.Title: | 383 * @return {string} |
281 if (this._wikiMarkupText[this._position] === "|") { | 384 */ |
282 title = this._deleteTrailingSpaces(title); | 385 _parseName: function() |
283 if (title !== "") | 386 { |
284 obj[title] = {}; | 387 var name = ""; |
285 state = states.PropertyName; | 388 while (this._tokenizer.hasMoreTokens()) { |
286 } else if (this._wikiMarkupText[this._position] === "}") { | 389 var token = this._tokenizer.peekToken(); |
287 title = this._deleteTrailingSpaces(title); | 390 switch (token.type()) { |
288 if (title !== "") | 391 case WebInspector.WikiParser.TokenType.ClosingBraces: |
289 obj[title] = {}; | 392 return name; |
290 state = states.FirstClose; | 393 case WebInspector.WikiParser.TokenType.EqualSign: |
291 } else { | 394 this._tokenizer.nextToken(); |
292 title += (this._wikiMarkupText[this._position] === "\n" ? "" : this._wikiMarkupText[this._position]); | 395 return name; |
293 } | 396 case WebInspector.WikiParser.TokenType.VerticalLine: |
294 break; | 397 case WebInspector.WikiParser.TokenType.Text: |
295 case states.PropertyName: | 398 name += this._tokenizer.nextToken().value(); |
296 if (this._wikiMarkupText[this._position] === "=") { | 399 break; |
297 state = states.PropertyValue; | 400 default: |
298 this._deleteTrailingSpaces(propertyName); | 401 throw new Error("Name could not be parsed. Unexpected token " + token.value()); |
299 if (propertyName !== "") | 402 } |
300 obj[title][propertyName] = []; | 403 } |
301 } else { | 404 return name; |
302 if (this._wikiMarkupText[this._position] === "}") { | 405 }, |
303 propertyName = this._deleteTrailingSpaces(propertyName); | 406 |
304 obj[title] = propertyName; | 407 /** |
305 state = states.FirstClose; | 408 * @return {!WebInspector.WikiParser.Block} |
306 } else { | 409 */ |
307 propertyName += this._wikiMarkupText[this._position]; | 410 _parseExampleCode: function() |
308 } | 411 { |
309 } | 412 var code = ""; |
310 break; | 413 /** |
apavlov
2014/09/10 14:09:24
blank lines between inner function and surrounding
iliia
2014/09/11 09:26:30
Done.
| |
311 case states.PropertyValue: | 414 * @return {!WebInspector.WikiParser.Block} |
312 if (this._wikiMarkupText[this._position] === "{" && this._wikiMa rkupText[this._position + 1] === "{") { | 415 */ |
313 propertyValue = this._parseField(); | 416 function wrapToArticleElement() |
apavlov
2014/09/10 14:09:24
To -> Into
iliia
2014/09/11 09:26:30
Done.
| |
314 obj[title][propertyName].push(propertyValue); | 417 { |
315 propertyValue = ""; | 418 var plainText = new WebInspector.WikiParser.PlainText(code, false); |
apavlov
2014/09/10 14:09:24
Can these "false" arguments be made optional in th
iliia
2014/09/11 09:26:31
Done.
| |
316 skipIncrement = true; | 419 var block = new WebInspector.WikiParser.Block([plainText], false) |
317 } else if (this._wikiMarkupText[this._position] === "|") { | 420 var articleElement = new WebInspector.WikiParser.Block([block], fals e); |
318 propertyValue = this._deleteTrailingSpaces(propertyValue); | 421 return articleElement; |
319 if (propertyValue !== "") | 422 } |
320 obj[title][propertyName] = propertyValue; | 423 while (this._tokenizer.hasMoreTokens()) { |
321 | 424 var token = this._tokenizer.peekToken(); |
322 state = states.PropertyName; | 425 switch (token.type()) { |
323 if (Array.isArray(obj[title][propertyName]) && obj[title][pr opertyName].length === 1) { | 426 case WebInspector.WikiParser.TokenType.ClosingBraces: |
324 var newObj = obj[title][propertyName][0]; | 427 return wrapToArticleElement(); |
325 obj[title][propertyName] = newObj; | 428 case WebInspector.WikiParser.TokenType.VerticalLine: |
326 } | 429 this._tokenizer.nextToken(); |
327 | 430 return wrapToArticleElement(); |
328 propertyName = ""; | 431 case WebInspector.WikiParser.TokenType.Exclamation: |
329 propertyValue = ""; | 432 this._tokenizer.nextToken(); |
330 } else if (this._position + 1 < this._wikiMarkupText.length && t his._wikiMarkupText[this._position] === "}" && this._wikiMarkupText[this._positi on + 1] === "}") { | 433 code += '|'; |
apavlov
2014/09/10 14:09:23
double quotes
iliia
2014/09/11 09:26:31
Done.
| |
331 propertyValue = this._deleteTrailingSpaces(propertyValue); | 434 break; |
332 if (propertyValue !== "") | 435 case WebInspector.WikiParser.TokenType.EqualSignInBraces: |
333 obj[title][propertyName].push(propertyValue); | 436 this._tokenizer.nextToken(); |
334 if (Array.isArray(obj[title][propertyName]) && obj[title][pr opertyName].length === 1) { | 437 code += "="; |
335 var newObj = obj[title][propertyName][0]; | 438 break; |
336 obj[title][propertyName] = newObj; | 439 default: |
337 } | 440 this._tokenizer.nextToken(); |
338 | 441 code += token.value(); |
339 propertyValue = ""; | 442 } |
340 state = states.FirstClose; | 443 } |
341 } else { | 444 return wrapToArticleElement(); |
342 propertyValue = this._parseValue(); | 445 }, |
343 skipIncrement = true; | 446 |
344 } | 447 /** |
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 } | |
360 if (!skipIncrement) | |
361 this._position++; | |
362 } | |
363 return obj; | |
364 }, | |
365 | |
366 /** | |
367 * @param {string} str | |
368 * @return {?WebInspector.WikiParser.Block} | 448 * @return {?WebInspector.WikiParser.Block} |
369 */ | 449 */ |
370 parseString: function(str) | 450 _parseString: function() |
371 { | 451 { |
372 this._tokenizer = new WebInspector.WikiParser.Tokenizer(str); | |
373 var children = []; | 452 var children = []; |
374 var blockChildren = []; | 453 var blockChildren = []; |
375 var text = ""; | 454 var text = ""; |
376 var self = this; | 455 var self = this; |
377 | 456 |
378 function processSimpleText() | 457 function processSimpleText() |
379 { | 458 { |
380 var currentText = self._deleteTrailingSpaces(text); | 459 var currentText = self._deleteTrailingSpaces(text); |
381 if (!currentText.length) | 460 if (!currentText.length) |
382 return; | 461 return; |
383 var simpleText = new WebInspector.WikiParser.PlainText(currentText, false); | 462 var simpleText = new WebInspector.WikiParser.PlainText(currentText, false); |
384 blockChildren.push(simpleText); | 463 blockChildren.push(simpleText); |
385 text = ""; | 464 text = ""; |
386 } | 465 } |
387 | 466 |
388 function processBlock() | 467 function processBlock() |
389 { | 468 { |
390 if (blockChildren.length) { | 469 if (blockChildren.length) { |
391 children.push(new WebInspector.WikiParser.Block(blockChildren, f alse)); | 470 children.push(new WebInspector.WikiParser.Block(blockChildren, f alse)); |
392 blockChildren = []; | 471 blockChildren = []; |
393 } | 472 } |
394 } | 473 } |
395 while (this._tokenizer._hasMoreTokens()) { | 474 |
396 var token = this._tokenizer._nextToken(); | 475 while (this._tokenizer.hasMoreTokens()) { |
476 var token = this._tokenizer.peekToken(); | |
397 switch (token.type()) { | 477 switch (token.type()) { |
478 case WebInspector.WikiParser.TokenType.VerticalLine: | |
479 this._tokenizer.nextToken(); | |
480 case WebInspector.WikiParser.TokenType.ClosingBraces: | |
481 processSimpleText(); | |
482 processBlock(); | |
483 return new WebInspector.WikiParser.Block(children, false); | |
398 case WebInspector.WikiParser.TokenType.TripleQuotes: | 484 case WebInspector.WikiParser.TokenType.TripleQuotes: |
485 this._tokenizer.nextToken(); | |
399 processSimpleText(); | 486 processSimpleText(); |
400 var highlightText = this._parseHighlight(); | 487 var highlightText = this._parseHighlight(); |
401 blockChildren.push(highlightText) | 488 blockChildren.push(highlightText) |
402 break; | 489 break; |
403 case WebInspector.WikiParser.TokenType.OpeningBrackets: | 490 case WebInspector.WikiParser.TokenType.OpeningBrackets: |
491 this._tokenizer.nextToken(); | |
404 processSimpleText(); | 492 processSimpleText(); |
405 var link = this._parseLink(); | 493 var link = this._parseLink(); |
406 blockChildren.push(link); | 494 blockChildren.push(link); |
407 break; | 495 break; |
408 case WebInspector.WikiParser.TokenType.OpeningCodeTag: | 496 case WebInspector.WikiParser.TokenType.OpeningCodeTag: |
497 this._tokenizer.nextToken(); | |
409 processSimpleText(); | 498 processSimpleText(); |
410 var code = this._parseCode(); | 499 var code = this._parseCode(); |
411 blockChildren.push(code); | 500 blockChildren.push(code); |
412 break; | 501 break; |
413 case WebInspector.WikiParser.TokenType.Bullet: | 502 case WebInspector.WikiParser.TokenType.Bullet: |
503 this._tokenizer.nextToken(); | |
414 processSimpleText(); | 504 processSimpleText(); |
415 processBlock(); | 505 processBlock(); |
416 var bulletText = this._parseBullet(); | 506 var bulletText = this._parseBullet(); |
417 children.push(bulletText); | 507 children.push(bulletText); |
418 break; | 508 break; |
419 case WebInspector.WikiParser.TokenType.CodeBlock: | 509 case WebInspector.WikiParser.TokenType.CodeBlock: |
510 this._tokenizer.nextToken(); | |
420 processSimpleText(); | 511 processSimpleText(); |
421 processBlock(); | 512 processBlock(); |
422 var code = new WebInspector.WikiParser.CodeBlock(token.value()); | 513 var code = new WebInspector.WikiParser.CodeBlock(this._deleteFro ntLineEnds(token.value())); |
423 children.push(code); | 514 children.push(code); |
424 break; | 515 break; |
425 case WebInspector.WikiParser.TokenType.LineEnd: | 516 case WebInspector.WikiParser.TokenType.LineEnd: |
517 this._tokenizer.nextToken(); | |
426 processSimpleText(); | 518 processSimpleText(); |
427 processBlock(); | 519 processBlock(); |
428 break; | 520 break; |
429 case WebInspector.WikiParser.TokenType.VerticalLine: | 521 case WebInspector.WikiParser.TokenType.EqualSignInBraces: |
522 this._tokenizer.nextToken(); | |
523 text += "="; | |
524 break; | |
525 case WebInspector.WikiParser.TokenType.Exclamation: | |
526 this._tokenizer.nextToken(); | |
527 text += "|"; | |
528 break; | |
529 case WebInspector.WikiParser.TokenType.ClosingBrackets: | |
430 case WebInspector.WikiParser.TokenType.Text: | 530 case WebInspector.WikiParser.TokenType.Text: |
531 case WebInspector.WikiParser.TokenType.EqualSign: | |
532 case WebInspector.WikiParser.TokenType.Table: | |
533 this._tokenizer.nextToken(); | |
431 text += token.value(); | 534 text += token.value(); |
432 break; | 535 break; |
433 default: | 536 default: |
537 this._tokenizer.nextToken(); | |
434 return null; | 538 return null; |
435 } | 539 } |
436 } | 540 } |
437 | 541 |
438 processSimpleText(); | 542 processSimpleText(); |
439 processBlock(); | 543 processBlock(); |
440 | 544 |
441 return new WebInspector.WikiParser.Block(children, false); | 545 return new WebInspector.WikiParser.Block(children, false); |
442 }, | 546 }, |
443 | 547 |
444 /** | 548 /** |
445 * @return {!WebInspector.WikiParser.Link} | 549 * @return {!WebInspector.WikiParser.Link} |
446 */ | 550 */ |
447 _parseLink: function() | 551 _parseLink: function() |
448 { | 552 { |
449 var url = ""; | 553 var url = ""; |
450 var children = []; | 554 var children = []; |
451 while (this._tokenizer._hasMoreTokens()) { | 555 while (this._tokenizer.hasMoreTokens()) { |
452 var token = this._tokenizer._nextToken(); | 556 var token = this._tokenizer.nextToken(); |
453 switch (token.type()) { | 557 switch (token.type()) { |
454 case WebInspector.WikiParser.TokenType.ClosingBrackets: | 558 case WebInspector.WikiParser.TokenType.ClosingBrackets: |
455 return new WebInspector.WikiParser.Link(url, children); | 559 return new WebInspector.WikiParser.Link(url, children); |
456 case WebInspector.WikiParser.TokenType.VerticalLine: | 560 case WebInspector.WikiParser.TokenType.VerticalLine: |
561 case WebInspector.WikiParser.TokenType.Exclamation: | |
457 children.push(this._parseLinkName()); | 562 children.push(this._parseLinkName()); |
458 return new WebInspector.WikiParser.Link(url, children); | 563 return new WebInspector.WikiParser.Link(url, children); |
459 default: | 564 default: |
460 url += token.value(); | 565 url += token.value(); |
461 } | 566 } |
462 } | 567 } |
463 | 568 |
464 return new WebInspector.WikiParser.Link(url, children); | 569 return new WebInspector.WikiParser.Link(url, children); |
465 }, | 570 }, |
466 | 571 |
467 /** | 572 /** |
468 * @return {!WebInspector.WikiParser.Inline} | 573 * @return {!WebInspector.WikiParser.Inline} |
469 */ | 574 */ |
470 _parseLinkName: function() | 575 _parseLinkName: function() |
471 { | 576 { |
472 var children = []; | 577 var children = []; |
473 while (this._tokenizer._hasMoreTokens()) { | 578 var text = ""; |
474 var token = this._tokenizer._nextToken(); | 579 var self = this; |
580 function processSimpleText() | |
581 { | |
582 text = self._deleteTrailingSpaces(text); | |
583 if (!text.length) | |
584 return; | |
585 var simpleText = new WebInspector.WikiParser.PlainText(text, false); | |
586 children.push(simpleText); | |
587 text = ""; | |
588 } | |
589 | |
590 while (this._tokenizer.hasMoreTokens()) { | |
591 var token = this._tokenizer.nextToken(); | |
475 switch (token.type()) { | 592 switch (token.type()) { |
476 case WebInspector.WikiParser.TokenType.ClosingBrackets: | 593 case WebInspector.WikiParser.TokenType.ClosingBrackets: |
594 processSimpleText(); | |
477 return new WebInspector.WikiParser.Inline(WebInspector.WikiParse r.ArticleElement.Type.Inline, children); | 595 return new WebInspector.WikiParser.Inline(WebInspector.WikiParse r.ArticleElement.Type.Inline, children); |
apavlov
2014/09/10 14:09:24
Article element types should never get passed into
iliia
2014/09/11 09:26:30
So if some of Inlines haven't any special fields o
apavlov
2014/09/11 10:40:26
Can an instance of WI.WikiParser.Inline have a typ
iliia
2014/09/11 13:26:28
Yes, for example, Link.
On 2014/09/11 10:40:26, ap
apavlov
2014/09/11 19:55:22
OK, I have chatted with Andrey about it. Leaving t
| |
478 case WebInspector.WikiParser.TokenType.OpeningCodeTag: | 596 case WebInspector.WikiParser.TokenType.OpeningCodeTag: |
597 processSimpleText(); | |
479 children.push(this._parseCode()); | 598 children.push(this._parseCode()); |
480 break; | 599 break; |
481 default: | 600 default: |
482 children.push(new WebInspector.WikiParser.PlainText(token.value( ), false)); | 601 text += token.value(); |
483 break; | 602 break; |
484 } | 603 } |
485 } | 604 } |
486 | 605 |
487 return new WebInspector.WikiParser.Inline(WebInspector.WikiParser.Articl eElement.Type.Inline, children); | 606 return new WebInspector.WikiParser.Inline(WebInspector.WikiParser.Articl eElement.Type.Inline, children); |
488 }, | 607 }, |
489 | 608 |
490 /** | 609 /** |
491 * @return {!WebInspector.WikiParser.Inline} | 610 * @return {!WebInspector.WikiParser.Inline} |
492 */ | 611 */ |
493 _parseCode : function() | 612 _parseCode : function() |
494 { | 613 { |
495 var children = []; | 614 var children = []; |
496 var text = ""; | 615 var text = ""; |
497 while (this._tokenizer._hasMoreTokens()) { | 616 while (this._tokenizer.hasMoreTokens()) { |
498 var token = this._tokenizer._nextToken(); | 617 var token = this._tokenizer.nextToken(); |
499 switch (token.type()) { | 618 switch (token.type()) { |
500 case WebInspector.WikiParser.TokenType.ClosingCodeTag: | 619 case WebInspector.WikiParser.TokenType.ClosingCodeTag: |
501 text = this._deleteTrailingSpaces(text); | 620 text = this._deleteTrailingSpaces(text); |
502 if (text.length) { | 621 if (text.length) { |
503 var simpleText = new WebInspector.WikiParser.PlainText(text, false); | 622 var simpleText = new WebInspector.WikiParser.PlainText(text, false); |
504 children.push(simpleText); | 623 children.push(simpleText); |
505 text = ""; | 624 text = ""; |
506 } | 625 } |
507 var code = new WebInspector.WikiParser.Inline(WebInspector.WikiP arser.ArticleElement.Type.Code, children); | 626 var code = new WebInspector.WikiParser.Inline(WebInspector.WikiP arser.ArticleElement.Type.Code, children); |
508 return code; | 627 return code; |
(...skipping 12 matching lines...) Expand all Loading... | |
521 | 640 |
522 return new WebInspector.WikiParser.Inline(WebInspector.WikiParser.Articl eElement.Type.Code, children); | 641 return new WebInspector.WikiParser.Inline(WebInspector.WikiParser.Articl eElement.Type.Code, children); |
523 }, | 642 }, |
524 | 643 |
525 /** | 644 /** |
526 * @return {!WebInspector.WikiParser.Block} | 645 * @return {!WebInspector.WikiParser.Block} |
527 */ | 646 */ |
528 _parseBullet: function() | 647 _parseBullet: function() |
529 { | 648 { |
530 var children = []; | 649 var children = []; |
531 while (this._tokenizer._hasMoreTokens()) { | 650 while (this._tokenizer.hasMoreTokens()) { |
532 var token = this._tokenizer._nextToken() | 651 var token = this._tokenizer.nextToken() |
533 switch (token.type()) { | 652 switch (token.type()) { |
534 case WebInspector.WikiParser.TokenType.OpeningBrackets: | 653 case WebInspector.WikiParser.TokenType.OpeningBrackets: |
535 children.push(this._parseLink()); | 654 children.push(this._parseLink()); |
536 break; | 655 break; |
537 case WebInspector.WikiParser.TokenType.OpeningCodeTag: | 656 case WebInspector.WikiParser.TokenType.OpeningCodeTag: |
538 children.push(this._parseCode()); | 657 children.push(this._parseCode()); |
539 break; | 658 break; |
540 case WebInspector.WikiParser.TokenType.LineEnd: | 659 case WebInspector.WikiParser.TokenType.LineEnd: |
541 return new WebInspector.WikiParser.Block(children, true); | 660 return new WebInspector.WikiParser.Block(children, true); |
542 default: | 661 default: |
543 var text = this._deleteTrailingSpaces(token.value()); | 662 var text = this._deleteTrailingSpaces(token.value()); |
544 if (text.length) { | 663 if (text.length) { |
545 var simpleText = new WebInspector.WikiParser.PlainText(text, false); | 664 var simpleText = new WebInspector.WikiParser.PlainText(text, false); |
546 children.push(simpleText); | 665 children.push(simpleText); |
547 text = ""; | 666 text = ""; |
548 } | 667 } |
549 } | 668 } |
550 } | 669 } |
551 | 670 |
552 return new WebInspector.WikiParser.Block(children, true); | 671 return new WebInspector.WikiParser.Block(children, true); |
553 }, | 672 }, |
554 | 673 |
555 /** | 674 /** |
556 * @return {!WebInspector.WikiParser.PlainText} | 675 * @return {!WebInspector.WikiParser.PlainText} |
557 */ | 676 */ |
558 _parseHighlight: function() | 677 _parseHighlight: function() |
559 { | 678 { |
560 var text = ""; | 679 var text = ""; |
561 while (this._tokenizer._hasMoreTokens()) { | 680 while (this._tokenizer.hasMoreTokens()) { |
562 var token = this._tokenizer._nextToken() | 681 var token = this._tokenizer.nextToken() |
563 switch (token.type()) { | 682 switch (token.type()) { |
564 case WebInspector.WikiParser.TokenType.TripleQuotes: | 683 case WebInspector.WikiParser.TokenType.TripleQuotes: |
565 text = this._deleteTrailingSpaces(text); | 684 text = this._deleteTrailingSpaces(text); |
566 return new WebInspector.WikiParser.PlainText(text, true); | 685 return new WebInspector.WikiParser.PlainText(text, true); |
567 default: | 686 default: |
568 text += token.value(); | 687 text += token.value(); |
569 } | 688 } |
570 } | 689 } |
571 return new WebInspector.WikiParser.PlainText(text, true); | 690 return new WebInspector.WikiParser.PlainText(text, true); |
572 }, | 691 }, |
573 | 692 |
574 /** | 693 /** |
575 * @param {string} str | 694 * @param {string} str |
576 * @return {string} | 695 * @return {string} |
577 */ | 696 */ |
578 _deleteTrailingSpaces: function(str) | 697 _deleteTrailingSpaces: function(str) |
579 { | 698 { |
580 return str.replace(/[\n\r]*$/gm, ""); | 699 return str.replace(/[\n\r]*$/gm, ""); |
700 }, | |
701 | |
702 /** | |
703 * @param {string} str | |
704 * @return {string} str | |
apavlov
2014/09/11 19:55:22
remove "str"
| |
705 */ | |
706 _deleteFrontLineEnds: function(str) | |
apavlov
2014/09/11 19:55:22
_trimLeadingNewLines
| |
707 { | |
708 return str.replace(/^\n*/, ""); | |
581 } | 709 } |
582 } | 710 } |
583 | 711 |
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 /** | 712 /** |
623 * @constructor | 713 * @constructor |
624 * @param {!WebInspector.WikiParser.ArticleElement.Type} type | 714 * @param {!WebInspector.WikiParser.ArticleElement.Type} type |
625 */ | 715 */ |
626 WebInspector.WikiParser.ArticleElement = function(type) | 716 WebInspector.WikiParser.ArticleElement = function(type) |
627 { | 717 { |
628 this._type = type; | 718 this._type = type; |
629 } | 719 } |
630 | 720 |
631 WebInspector.WikiParser.ArticleElement.prototype = { | 721 WebInspector.WikiParser.ArticleElement.prototype = { |
(...skipping 28 matching lines...) Expand all Loading... | |
660 { | 750 { |
661 WebInspector.WikiParser.ArticleElement.call(this, WebInspector.WikiParser.Ar ticleElement.Type.PlainText); | 751 WebInspector.WikiParser.ArticleElement.call(this, WebInspector.WikiParser.Ar ticleElement.Type.PlainText); |
662 this._text = text; | 752 this._text = text; |
663 this._isHighlighted = highlight; | 753 this._isHighlighted = highlight; |
664 } | 754 } |
665 | 755 |
666 WebInspector.WikiParser.PlainText.prototype = { | 756 WebInspector.WikiParser.PlainText.prototype = { |
667 /** | 757 /** |
668 * @return {string} | 758 * @return {string} |
669 */ | 759 */ |
670 text : function() | 760 text : function() |
apavlov
2014/09/10 14:09:24
no whitespace before colon
iliia
2014/09/11 09:26:30
Done.
| |
671 { | 761 { |
672 return this._text; | 762 return this._text; |
673 }, | 763 }, |
674 | 764 |
675 /** | 765 /** |
676 * @return {boolean} | 766 * @return {boolean} |
677 */ | 767 */ |
678 isHighlighted: function() | 768 isHighlighted: function() |
679 { | 769 { |
680 return this._isHighlighted; | 770 return this._isHighlighted; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
779 /** | 869 /** |
780 * @return {string} | 870 * @return {string} |
781 */ | 871 */ |
782 url : function() | 872 url : function() |
783 { | 873 { |
784 return this._url; | 874 return this._url; |
785 }, | 875 }, |
786 | 876 |
787 __proto__: WebInspector.WikiParser.Inline.prototype | 877 __proto__: WebInspector.WikiParser.Inline.prototype |
788 } | 878 } |
OLD | NEW |