Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(588)

Side by Side Diff: Source/devtools/front_end/documentation/WikiParser.js

Issue 539353004: DevTools: [Documentation] Update parser for WikiText (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: comments addressed Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
27 PropertyName: "PropertyName", 24 /** @type {?WebInspector.WikiParser.Values} */
28 PropertyValue: "PropertyValue", 25 this.values;
29 FirstClose: "FirstClose", 26
30 SecondClose: "SecondClose" 27 /** @type {?WebInspector.WikiParser.ArticleElement} */
28 this.singleValue;
31 } 29 }
32 30
33 /** 31 /**
34 * @package 32 * @constructor
35 * @enum {string}
36 */ 33 */
37 WebInspector.WikiParser.LinkStates = { 34 WebInspector.WikiParser.Field = function()
38 Error: "Error", 35 {
39 LinkUrl: "LinkUrl", 36 /** @type {string} */
40 LinkName: "LinkName" 37 this.name;
38
39 /** @type {?WebInspector.WikiParser.FieldValue} */
40 this.value;
41 } 41 }
42 42
43 /** 43 /** @typedef {(?WebInspector.WikiParser.ArticleElement|!Array.<!WebInspector.Wik iParser.Section>)} */
apavlov 2014/09/11 10:40:27 Has this and the following union type been agreed
iliia 2014/09/11 13:26:29 Yes, it was discussed with him. We don't know how
44 * @package 44 WebInspector.WikiParser.FieldValue;
45 * @enum {string}
46 */
47 WebInspector.WikiParser.HtmlStates = {
48 Error: "Error",
49 Entry: "Entry",
50 InsideTag: "InsideTag",
51 Exit: "Exit"
52 }
53 45
54 /** 46 /** @typedef {?Object.<string, !WebInspector.WikiParser.FieldValue>} */
55 * @package 47 WebInspector.WikiParser.Values;
56 * @enum {string} 48
57 */ 49 /** @typedef {(?WebInspector.WikiParser.Value|?WebInspector.WikiParser.ArticleEl ement)} */
58 WebInspector.WikiParser.ValueState = { 50 WebInspector.WikiParser.Value;
59 Error: "Error",
60 Outside: "Outside",
61 InsideSquare: "InsideSquare"
62 }
63 51
64 /** 52 /**
65 * @package 53 * @package
66 * @enum {string} 54 * @enum {string}
67 */ 55 */
68 WebInspector.WikiParser.TokenType = { 56 WebInspector.WikiParser.TokenType = {
57 Text: "Text",
58 Table: "Table",
59 OpeningBraces: "OpeningBraces",
60 ClosingBraces: "ClosingBraces",
61 Exclamation: "Exclamation",
62 OpeningBrackets: "OpeningBrackets",
63 ClosingBrackets: "ClosingBrackets",
64 EqualSign: "EqualSign",
65 EqualSignInBraces: "EqualSignInBraces",
66 VerticalLine: "VerticalLine",
69 TripleQuotes: "TripleQuotes", 67 TripleQuotes: "TripleQuotes",
70 OpeningBrackets: "OpeningBrackets",
71 OpeningCodeTag: "OpeningCodeTag", 68 OpeningCodeTag: "OpeningCodeTag",
72 ClosingBrackets: "ClosingBrackets",
73 ClosingCodeTag: "ClosingCodeTag", 69 ClosingCodeTag: "ClosingCodeTag",
74 Bullet: "Bullet", 70 Bullet: "Bullet",
75 Text: "Text",
76 VerticalLine: "VerticalLine",
77 LineEnd: "LineEnd", 71 LineEnd: "LineEnd",
78 CodeBlock: "CodeBlock" 72 CodeBlock: "CodeBlock"
79 } 73 }
80 74
81 /** 75 /**
82 * @constructor 76 * @constructor
83 * @param {string} result 77 * @param {string} result
84 * @param {!WebInspector.WikiParser.TokenType} type 78 * @param {!WebInspector.WikiParser.TokenType} type
85 */ 79 */
86 WebInspector.WikiParser.Token = function(result, type) 80 WebInspector.WikiParser.Token = function(result, type)
(...skipping 20 matching lines...) Expand all
107 } 101 }
108 } 102 }
109 103
110 /** 104 /**
111 * @constructor 105 * @constructor
112 * @param {string} str 106 * @param {string} str
113 */ 107 */
114 WebInspector.WikiParser.Tokenizer = function(str) 108 WebInspector.WikiParser.Tokenizer = function(str)
115 { 109 {
116 this._text = str; 110 this._text = str;
111 this._token = this._internalNextToken();
117 } 112 }
118 113
119 WebInspector.WikiParser.Tokenizer.prototype = { 114 WebInspector.WikiParser.Tokenizer.prototype = {
120 /** 115 /**
121 * @return {!WebInspector.WikiParser.Token} 116 * @return {!WebInspector.WikiParser.Token}
122 */ 117 */
123 _nextToken: function() 118 peekToken: function()
119 {
120 return this._token;
121 },
122
123 /**
124 * @return {!WebInspector.WikiParser.Token}
125 */
126 nextToken: function()
127 {
128 var token = this._token;
129 this._token = this._internalNextToken();
130 return token;
131 },
132
133 /**
134 * @return {!WebInspector.WikiParser.Token}
135 */
136 _internalNextToken: function()
124 { 137 {
125 if (WebInspector.WikiParser.newLineWithSpace.test(this._text)) { 138 if (WebInspector.WikiParser.newLineWithSpace.test(this._text)) {
126 var result = WebInspector.WikiParser.newLineWithSpace.exec(this._tex t); 139 var result = WebInspector.WikiParser.newLineWithSpace.exec(this._tex t);
127 var begin = result.index + result[0].length; 140 var begin = result.index + result[0].length - 3;
128 var end = this._text.length; 141 var end = this._text.length;
129 var lineEnd = WebInspector.WikiParser.newLineWithoutSpace.exec(this. _text); 142 var lineEnd = WebInspector.WikiParser.newLineWithoutSpace.exec(this. _text);
130 if (lineEnd) 143 if (lineEnd)
131 end = lineEnd.index; 144 end = lineEnd.index;
132 var token = this._text.substring(begin, end).replace(/\n */g, "\n"); 145 var token = this._text.substring(begin, end).replace(/\n /g, "\n").r eplace(/{{=}}/g, "=");
133 this._text = this._text.substring(end + 1); 146 this._text = this._text.substring(end + 1);
134 return new WebInspector.WikiParser.Token(token, WebInspector.WikiPar ser.TokenType.CodeBlock); 147 return new WebInspector.WikiParser.Token(token, WebInspector.WikiPar ser.TokenType.CodeBlock);
135 } 148 }
136 149
137 for (var i = 0; i < WebInspector.WikiParser._tokenDescriptors.length; ++ i) { 150 for (var i = 0; i < WebInspector.WikiParser._tokenDescriptors.length; ++ i) {
138 var result = WebInspector.WikiParser._tokenDescriptors[i].regex.exec (this._text); 151 var result = WebInspector.WikiParser._tokenDescriptors[i].regex.exec (this._text);
139 if (result) { 152 if (result) {
140 this._text = this._text.substring(result.index + result[0].lengt h); 153 this._text = this._text.substring(result.index + result[0].lengt h);
141 return new WebInspector.WikiParser.Token(result[0], WebInspector .WikiParser._tokenDescriptors[i].type); 154 return new WebInspector.WikiParser.Token(result[0], WebInspector .WikiParser._tokenDescriptors[i].type);
142 } 155 }
143 } 156 }
144 157
145 for (var lastIndex = 0; lastIndex < this._text.length; ++lastIndex) { 158 for (var lastIndex = 0; lastIndex < this._text.length; ++lastIndex) {
146 var testString = this._text.substring(lastIndex); 159 var testString = this._text.substring(lastIndex);
147 for (var i = 0; i < WebInspector.WikiParser._tokenDescriptors.length ; ++i) { 160 for (var i = 0; i < WebInspector.WikiParser._tokenDescriptors.length ; ++i) {
148 if (WebInspector.WikiParser._tokenDescriptors[i].regex.test(test String)) { 161 if (WebInspector.WikiParser._tokenDescriptors[i].regex.test(test String)) {
149 var token = this._text.substring(0, lastIndex); 162 var token = this._text.substring(0, lastIndex);
150 this._text = this._text.substring(lastIndex); 163 this._text = this._text.substring(lastIndex);
151 return new WebInspector.WikiParser.Token(token, WebInspector .WikiParser.TokenType.Text); 164 return new WebInspector.WikiParser.Token(token, WebInspector .WikiParser.TokenType.Text);
152 } 165 }
153 } 166 }
154 } 167 }
155 168
156 var token = this._text; 169 var token = this._text;
157 this._text = ""; 170 this._text = "";
158 return new WebInspector.WikiParser.Token(token, WebInspector.WikiParser. TokenType.Text); 171 return new WebInspector.WikiParser.Token(token, WebInspector.WikiParser. TokenType.Text);
159 }, 172 },
160 173
161 /** 174 /**
175 * @return {!WebInspector.WikiParser.Tokenizer}
176 */
177 clone: function()
178 {
179 var tokenizer = new WebInspector.WikiParser.Tokenizer(this._text);
180 tokenizer._token = this._token;
181 tokenizer._text = this._text;
182 return tokenizer;
183 },
184
185 /**
162 * @return {boolean} 186 * @return {boolean}
163 */ 187 */
164 _hasMoreTokens: function() 188 hasMoreTokens: function()
165 { 189 {
166 return !!this._text.length; 190 return !!this._text.length;
167 } 191 }
168 } 192 }
169 193
194 WebInspector.WikiParser.table = /^{{{!}}/;
195 WebInspector.WikiParser.exclamation = /^{{!}}/;
196 WebInspector.WikiParser.openingBraces = /^{{/;
197 WebInspector.WikiParser.equalSign = /^=/;
198 WebInspector.WikiParser.equalSignInBraces = /^{{=}}/;
199 WebInspector.WikiParser.closingBraces = /^\s*}}/;
200 WebInspector.WikiParser.oneOpeningBracketWithSpace = /^\n* \[/;
201 WebInspector.WikiParser.twoOpeningBracketsWithSpace = /^\n* \[\[/;
202 WebInspector.WikiParser.oneClosingBracket = /^\n*\]/;
203 WebInspector.WikiParser.twoClosingBrackets = /^\n*\]\]/;
204 WebInspector.WikiParser.tripleQuotes = /^\n*'''/;
205 WebInspector.WikiParser.openingCodeTag = /^<\s*code\s*>/;
206 WebInspector.WikiParser.closingCodeTag = /^<\s*\/\s*code\s*>/;
207 WebInspector.WikiParser.closingBullet = /^\*/;
208 WebInspector.WikiParser.lineEnd = /^\n/;
209 WebInspector.WikiParser.verticalLine = /^\n*\|/;
210 WebInspector.WikiParser.newLineWithSpace = /^\n [^ ]/;
211 WebInspector.WikiParser.newLineWithoutSpace = /\n[^ ]/;
212
213 /**
214 * @constructor
215 * @param {!RegExp} regex
216 * @param {!WebInspector.WikiParser.TokenType} type
217 */
218 WebInspector.WikiParser.TokenDescriptor = function(regex, type)
219 {
220 this.regex = regex;
221 this.type = type;
222 }
223
224 WebInspector.WikiParser._tokenDescriptors = [
225 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.exclamat ion, WebInspector.WikiParser.TokenType.Exclamation),
226 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.equalSig nInBraces, WebInspector.WikiParser.TokenType.EqualSignInBraces),
227 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.equalSig n, WebInspector.WikiParser.TokenType.EqualSign),
228 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.table, W ebInspector.WikiParser.TokenType.Table),
229 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.openingB races, WebInspector.WikiParser.TokenType.OpeningBraces),
230 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.vertical Line, WebInspector.WikiParser.TokenType.VerticalLine),
231 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingB races, WebInspector.WikiParser.TokenType.ClosingBraces),
232 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.twoOpeni ngBracketsWithSpace, WebInspector.WikiParser.TokenType.OpeningBrackets),
233 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.twoClosi ngBrackets, WebInspector.WikiParser.TokenType.ClosingBrackets),
234 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.oneOpeni ngBracketWithSpace, WebInspector.WikiParser.TokenType.OpeningBrackets),
235 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.oneClosi ngBracket, WebInspector.WikiParser.TokenType.ClosingBrackets),
236 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.newLineW ithSpace, WebInspector.WikiParser.TokenType.CodeBlock),
237 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.tripleQu otes, WebInspector.WikiParser.TokenType.TripleQuotes),
238 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.openingC odeTag, WebInspector.WikiParser.TokenType.OpeningCodeTag),
239 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingC odeTag, WebInspector.WikiParser.TokenType.ClosingCodeTag),
240 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingB ullet, WebInspector.WikiParser.TokenType.Bullet),
241 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.lineEnd, WebInspector.WikiParser.TokenType.LineEnd)
242 ]
243
170 WebInspector.WikiParser.prototype = { 244 WebInspector.WikiParser.prototype = {
171 /** 245 /**
172 * @return {!Object} 246 * @return {!Object}
173 */ 247 */
174 document: function() 248 document: function()
175 { 249 {
176 return this._document; 250 return this._document;
177 }, 251 },
178 252
179 /** 253 /**
180 * @return {!Object} 254 * @return {?WebInspector.WikiParser.TokenType}
255 */
256 _secondTokenType: function()
257 {
258 var tokenizer = this._tokenizer.clone();
259 if (!tokenizer.hasMoreTokens())
260 return null;
261 tokenizer.nextToken();
262 if (!tokenizer.hasMoreTokens())
263 return null;
264 return tokenizer.nextToken().type();
265 },
266
267 /**
268 * @return {!Object.<string, ?WebInspector.WikiParser.Value>}
181 */ 269 */
182 _parse: function() 270 _parse: function()
183 { 271 {
184 var obj = {}; 272 var obj = {};
185 this._wikiMarkupText = this._wikiMarkupText.replace(/&lt;/g, "<") 273 while (this._tokenizer.hasMoreTokens()) {
186 .replace(/&gt;/g, ">") 274 var section = this._parseSection();
187 .replace(/&#58;/g, ":") 275 if (section.title) {
188 .replace(/&quot;/g, "\"") 276 if (section.singleValue)
189 .replace(/&#60;/g, "<") 277 obj[section.title] = section.singleValue;
apavlov 2014/09/11 10:40:27 obj[section.title] = section.singleValue || sectio
iliia 2014/09/11 13:26:29 Done.
190 .replace(/&#62;/g, ">") 278 else
191 .replace(/{{=}}/g, "=") 279 obj[section.title] = section.values;
192 .replace(/{{!}}/g, "|")
193 .replace(/&amp;/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 } 280 }
200 } 281 }
201 return obj; 282 return obj;
202 }, 283 },
203 284
204 /** 285 /**
286 * @return {!WebInspector.WikiParser.Section}
287 */
288 _parseSection: function()
289 {
290 var section = new WebInspector.WikiParser.Section();
291 if (!this._tokenizer.hasMoreTokens() || this._tokenizer.nextToken().type () !== WebInspector.WikiParser.TokenType.OpeningBraces)
292 return section;
293
294 var title = this._deleteTrailingSpaces(this._parseTitle());
295 if (!title.length)
296 return section;
297 section.title = title;
298 if (this._tokenizer.peekToken().type() === WebInspector.WikiParser.Token Type.ClosingBraces) {
299 this._tokenizer.nextToken();
300 return section;
301 }
302 var secondTokenType = this._secondTokenType();
303 if (!secondTokenType || secondTokenType !== WebInspector.WikiParser.Toke nType.EqualSign) {
304 section.singleValue = this._parseString();
305 } else {
306 section.values = {};
307 while (this._tokenizer.hasMoreTokens()) {
308 var field = this._parseField();
309 section.values[field.name] = field.value;
310 if (this._tokenizer.peekToken().type() === WebInspector.WikiPars er.TokenType.ClosingBraces) {
311 this._tokenizer.nextToken();
312 return section;
313 }
314 }
315 }
316 var token = this._tokenizer.nextToken();
317 if (token.type() !== WebInspector.WikiParser.TokenType.ClosingBraces)
318 throw new Error("Two closing braces expected; found " + token.value( ));
319
320 return section;
321 },
322
323 /**
324 * @return {!WebInspector.WikiParser.Field}
325 */
326 _parseField: function()
327 {
328 var field = new WebInspector.WikiParser.Field();
329 field.name = this._parseName();
330 var token = this._tokenizer.peekToken();
331 switch (token.type()) {
332 case WebInspector.WikiParser.TokenType.OpeningBraces:
333 field.value = this._parseArray();
334 break;
335 case WebInspector.WikiParser.TokenType.LineEnd:
336 this._tokenizer.nextToken();
337 break;
338 case WebInspector.WikiParser.TokenType.ClosingBraces:
339 return field;
340 break;
341 default:
342 if (field.name === "Code")
343 field.value = this._parseExampleCode();
344 else
345 field.value = this._parseString();
346 }
347 return field;
348 },
349
350 /**
351 * @return {!Array.<!WebInspector.WikiParser.Section>}
352 */
353 _parseArray: function()
354 {
355 var array = [];
356 while (this._tokenizer.peekToken().type() === WebInspector.WikiParser.To kenType.OpeningBraces)
357 array.push(this._parseSection());
358 if (this._tokenizer.peekToken().type() === WebInspector.WikiParser.Token Type.VerticalLine)
359 this._tokenizer.nextToken();
360 return array;
361 },
362
363 /**
205 * @return {string} 364 * @return {string}
206 */ 365 */
207 _parseValue: function() { 366 _parseTitle: function()
208 var states = WebInspector.WikiParser.ValueState; 367 {
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 = ""; 368 var title = "";
261 var propertyName = ""; 369 while (this._tokenizer.hasMoreTokens()) {
262 var propertyValue = ""; 370 var token = this._tokenizer.peekToken();
263 var states = WebInspector.WikiParser.State; 371 switch (token.type()) {
264 var state = states.FirstOpen; 372 case WebInspector.WikiParser.TokenType.ClosingBraces:
265 while (this._position < this._wikiMarkupText.length) { 373 return title;
266 var skipIncrement = false; 374 case WebInspector.WikiParser.TokenType.VerticalLine:
267 switch (state) { 375 this._tokenizer.nextToken();
268 case states.FirstOpen: 376 return title;
269 if (this._wikiMarkupText[this._position] === "{") 377 case WebInspector.WikiParser.TokenType.Text:
270 state = states.SecondOpen; 378 title += this._tokenizer.nextToken().value();
271 else 379 break;
272 state = states.Error; 380 default:
273 break; 381 throw new Error("Title could not be parsed. Unexpected token " + token.value());
274 case states.SecondOpen: 382 }
275 if (this._wikiMarkupText[this._position] === "{") 383 }
276 state = states.Title; 384 return title;
277 else 385 },
278 state = states.Error; 386
279 break; 387 /**
280 case states.Title: 388 * @return {string}
281 if (this._wikiMarkupText[this._position] === "|") { 389 */
282 title = this._deleteTrailingSpaces(title); 390 _parseName: function()
283 if (title !== "") 391 {
284 obj[title] = {}; 392 var name = "";
285 state = states.PropertyName; 393 while (this._tokenizer.hasMoreTokens()) {
286 } else if (this._wikiMarkupText[this._position] === "}") { 394 var token = this._tokenizer.peekToken();
287 title = this._deleteTrailingSpaces(title); 395 switch (token.type()) {
288 if (title !== "") 396 case WebInspector.WikiParser.TokenType.ClosingBraces:
289 obj[title] = {}; 397 return name;
290 state = states.FirstClose; 398 case WebInspector.WikiParser.TokenType.EqualSign:
291 } else { 399 this._tokenizer.nextToken();
292 title += (this._wikiMarkupText[this._position] === "\n" ? "" : this._wikiMarkupText[this._position]); 400 return name;
293 } 401 case WebInspector.WikiParser.TokenType.VerticalLine:
294 break; 402 case WebInspector.WikiParser.TokenType.Text:
295 case states.PropertyName: 403 name += this._tokenizer.nextToken().value();
296 if (this._wikiMarkupText[this._position] === "=") { 404 break;
297 state = states.PropertyValue; 405 default:
298 this._deleteTrailingSpaces(propertyName); 406 throw new Error("Name could not be parsed. Unexpected token " + token.value());
299 if (propertyName !== "") 407 }
300 obj[title][propertyName] = []; 408 }
301 } else { 409 return name;
302 if (this._wikiMarkupText[this._position] === "}") { 410 },
303 propertyName = this._deleteTrailingSpaces(propertyName); 411
304 obj[title] = propertyName; 412 /**
305 state = states.FirstClose; 413 * @return {!WebInspector.WikiParser.Block}
306 } else { 414 */
307 propertyName += this._wikiMarkupText[this._position]; 415 _parseExampleCode: function()
308 } 416 {
309 } 417 var code = "";
310 break; 418
311 case states.PropertyValue: 419 /**
312 if (this._wikiMarkupText[this._position] === "{" && this._wikiMa rkupText[this._position + 1] === "{") { 420 * @return {!WebInspector.WikiParser.Block}
313 propertyValue = this._parseField(); 421 */
314 obj[title][propertyName].push(propertyValue); 422 function wrapIntoArticleElement()
315 propertyValue = ""; 423 {
316 skipIncrement = true; 424 var plainText = new WebInspector.WikiParser.PlainText(code);
317 } else if (this._wikiMarkupText[this._position] === "|") { 425 var block = new WebInspector.WikiParser.Block([plainText])
318 propertyValue = this._deleteTrailingSpaces(propertyValue); 426 var articleElement = new WebInspector.WikiParser.Block([block]);
319 if (propertyValue !== "") 427 return articleElement;
320 obj[title][propertyName] = propertyValue; 428 }
321 429 while (this._tokenizer.hasMoreTokens()) {
apavlov 2014/09/11 10:40:27 a blank line above for the readability would be ni
iliia 2014/09/11 13:26:29 Done.
322 state = states.PropertyName; 430 var token = this._tokenizer.peekToken();
323 if (Array.isArray(obj[title][propertyName]) && obj[title][pr opertyName].length === 1) { 431 switch (token.type()) {
324 var newObj = obj[title][propertyName][0]; 432 case WebInspector.WikiParser.TokenType.ClosingBraces:
325 obj[title][propertyName] = newObj; 433 return wrapIntoArticleElement();
326 } 434 case WebInspector.WikiParser.TokenType.VerticalLine:
327 435 this._tokenizer.nextToken();
328 propertyName = ""; 436 return wrapIntoArticleElement();
329 propertyValue = ""; 437 case WebInspector.WikiParser.TokenType.Exclamation:
330 } else if (this._position + 1 < this._wikiMarkupText.length && t his._wikiMarkupText[this._position] === "}" && this._wikiMarkupText[this._positi on + 1] === "}") { 438 this._tokenizer.nextToken();
331 propertyValue = this._deleteTrailingSpaces(propertyValue); 439 code += "|";
332 if (propertyValue !== "") 440 break;
333 obj[title][propertyName].push(propertyValue); 441 case WebInspector.WikiParser.TokenType.EqualSignInBraces:
334 if (Array.isArray(obj[title][propertyName]) && obj[title][pr opertyName].length === 1) { 442 this._tokenizer.nextToken();
335 var newObj = obj[title][propertyName][0]; 443 code += "=";
336 obj[title][propertyName] = newObj; 444 break;
337 } 445 default:
338 446 this._tokenizer.nextToken();
339 propertyValue = ""; 447 code += token.value();
340 state = states.FirstClose; 448 }
341 } else { 449 }
342 propertyValue = this._parseValue(); 450 return wrapIntoArticleElement();
343 skipIncrement = true; 451 },
344 } 452
345 break; 453 /**
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} 454 * @return {?WebInspector.WikiParser.Block}
369 */ 455 */
370 parseString: function(str) 456 _parseString: function()
371 { 457 {
372 this._tokenizer = new WebInspector.WikiParser.Tokenizer(str);
373 var children = []; 458 var children = [];
374 var blockChildren = []; 459 var blockChildren = [];
375 var text = ""; 460 var text = "";
376 var self = this; 461 var self = this;
377 462
378 function processSimpleText() 463 function processSimpleText()
379 { 464 {
380 var currentText = self._deleteTrailingSpaces(text); 465 var currentText = self._deleteTrailingSpaces(text);
381 if (!currentText.length) 466 if (!currentText.length)
382 return; 467 return;
383 var simpleText = new WebInspector.WikiParser.PlainText(currentText, false); 468 var simpleText = new WebInspector.WikiParser.PlainText(currentText);
384 blockChildren.push(simpleText); 469 blockChildren.push(simpleText);
385 text = ""; 470 text = "";
386 } 471 }
387 472
388 function processBlock() 473 function processBlock()
389 { 474 {
390 if (blockChildren.length) { 475 if (blockChildren.length) {
391 children.push(new WebInspector.WikiParser.Block(blockChildren, f alse)); 476 children.push(new WebInspector.WikiParser.Block(blockChildren));
392 blockChildren = []; 477 blockChildren = [];
393 } 478 }
394 } 479 }
395 while (this._tokenizer._hasMoreTokens()) { 480
396 var token = this._tokenizer._nextToken(); 481 while (this._tokenizer.hasMoreTokens()) {
482 var token = this._tokenizer.peekToken();
397 switch (token.type()) { 483 switch (token.type()) {
484 case WebInspector.WikiParser.TokenType.VerticalLine:
485 this._tokenizer.nextToken();
486 case WebInspector.WikiParser.TokenType.ClosingBraces:
487 processSimpleText();
488 processBlock();
489 return new WebInspector.WikiParser.Block(children);
398 case WebInspector.WikiParser.TokenType.TripleQuotes: 490 case WebInspector.WikiParser.TokenType.TripleQuotes:
491 this._tokenizer.nextToken();
399 processSimpleText(); 492 processSimpleText();
400 var highlightText = this._parseHighlight(); 493 var highlightText = this._parseHighlight();
401 blockChildren.push(highlightText) 494 blockChildren.push(highlightText)
402 break; 495 break;
403 case WebInspector.WikiParser.TokenType.OpeningBrackets: 496 case WebInspector.WikiParser.TokenType.OpeningBrackets:
497 this._tokenizer.nextToken();
404 processSimpleText(); 498 processSimpleText();
405 var link = this._parseLink(); 499 var link = this._parseLink();
406 blockChildren.push(link); 500 blockChildren.push(link);
407 break; 501 break;
408 case WebInspector.WikiParser.TokenType.OpeningCodeTag: 502 case WebInspector.WikiParser.TokenType.OpeningCodeTag:
503 this._tokenizer.nextToken();
409 processSimpleText(); 504 processSimpleText();
410 var code = this._parseCode(); 505 var code = this._parseCode();
411 blockChildren.push(code); 506 blockChildren.push(code);
412 break; 507 break;
413 case WebInspector.WikiParser.TokenType.Bullet: 508 case WebInspector.WikiParser.TokenType.Bullet:
509 this._tokenizer.nextToken();
414 processSimpleText(); 510 processSimpleText();
415 processBlock(); 511 processBlock();
416 var bulletText = this._parseBullet(); 512 var bulletText = this._parseBullet();
417 children.push(bulletText); 513 children.push(bulletText);
418 break; 514 break;
419 case WebInspector.WikiParser.TokenType.CodeBlock: 515 case WebInspector.WikiParser.TokenType.CodeBlock:
516 this._tokenizer.nextToken();
420 processSimpleText(); 517 processSimpleText();
421 processBlock(); 518 processBlock();
422 var code = new WebInspector.WikiParser.CodeBlock(token.value()); 519 var code = new WebInspector.WikiParser.CodeBlock(this._deleteFro ntLineEnds(token.value()));
423 children.push(code); 520 children.push(code);
424 break; 521 break;
425 case WebInspector.WikiParser.TokenType.LineEnd: 522 case WebInspector.WikiParser.TokenType.LineEnd:
523 this._tokenizer.nextToken();
426 processSimpleText(); 524 processSimpleText();
427 processBlock(); 525 processBlock();
428 break; 526 break;
429 case WebInspector.WikiParser.TokenType.VerticalLine: 527 case WebInspector.WikiParser.TokenType.EqualSignInBraces:
528 this._tokenizer.nextToken();
529 text += "=";
530 break;
531 case WebInspector.WikiParser.TokenType.Exclamation:
532 this._tokenizer.nextToken();
533 text += "|";
534 break;
535 case WebInspector.WikiParser.TokenType.ClosingBrackets:
430 case WebInspector.WikiParser.TokenType.Text: 536 case WebInspector.WikiParser.TokenType.Text:
537 case WebInspector.WikiParser.TokenType.EqualSign:
538 case WebInspector.WikiParser.TokenType.Table:
539 this._tokenizer.nextToken();
431 text += token.value(); 540 text += token.value();
432 break; 541 break;
433 default: 542 default:
543 this._tokenizer.nextToken();
434 return null; 544 return null;
435 } 545 }
436 } 546 }
437 547
438 processSimpleText(); 548 processSimpleText();
439 processBlock(); 549 processBlock();
440 550
441 return new WebInspector.WikiParser.Block(children, false); 551 return new WebInspector.WikiParser.Block(children);
442 }, 552 },
443 553
444 /** 554 /**
445 * @return {!WebInspector.WikiParser.Link} 555 * @return {!WebInspector.WikiParser.Link}
446 */ 556 */
447 _parseLink: function() 557 _parseLink: function()
448 { 558 {
449 var url = ""; 559 var url = "";
450 var children = []; 560 var children = [];
451 while (this._tokenizer._hasMoreTokens()) { 561 while (this._tokenizer.hasMoreTokens()) {
452 var token = this._tokenizer._nextToken(); 562 var token = this._tokenizer.nextToken();
453 switch (token.type()) { 563 switch (token.type()) {
454 case WebInspector.WikiParser.TokenType.ClosingBrackets: 564 case WebInspector.WikiParser.TokenType.ClosingBrackets:
455 return new WebInspector.WikiParser.Link(url, children); 565 return new WebInspector.WikiParser.Link(url, children);
456 case WebInspector.WikiParser.TokenType.VerticalLine: 566 case WebInspector.WikiParser.TokenType.VerticalLine:
567 case WebInspector.WikiParser.TokenType.Exclamation:
457 children.push(this._parseLinkName()); 568 children.push(this._parseLinkName());
458 return new WebInspector.WikiParser.Link(url, children); 569 return new WebInspector.WikiParser.Link(url, children);
459 default: 570 default:
460 url += token.value(); 571 url += token.value();
461 } 572 }
462 } 573 }
463 574
464 return new WebInspector.WikiParser.Link(url, children); 575 return new WebInspector.WikiParser.Link(url, children);
465 }, 576 },
466 577
467 /** 578 /**
468 * @return {!WebInspector.WikiParser.Inline} 579 * @return {!WebInspector.WikiParser.Inline}
469 */ 580 */
470 _parseLinkName: function() 581 _parseLinkName: function()
471 { 582 {
472 var children = []; 583 var children = [];
473 while (this._tokenizer._hasMoreTokens()) { 584 var text = "";
474 var token = this._tokenizer._nextToken(); 585 var self = this;
586 function processSimpleText()
587 {
588 text = self._deleteTrailingSpaces(text);
589 if (!text.length)
590 return;
591 var simpleText = new WebInspector.WikiParser.PlainText(text);
592 children.push(simpleText);
593 text = "";
594 }
595
596 while (this._tokenizer.hasMoreTokens()) {
597 var token = this._tokenizer.nextToken();
475 switch (token.type()) { 598 switch (token.type()) {
476 case WebInspector.WikiParser.TokenType.ClosingBrackets: 599 case WebInspector.WikiParser.TokenType.ClosingBrackets:
600 processSimpleText();
477 return new WebInspector.WikiParser.Inline(WebInspector.WikiParse r.ArticleElement.Type.Inline, children); 601 return new WebInspector.WikiParser.Inline(WebInspector.WikiParse r.ArticleElement.Type.Inline, children);
478 case WebInspector.WikiParser.TokenType.OpeningCodeTag: 602 case WebInspector.WikiParser.TokenType.OpeningCodeTag:
603 processSimpleText();
479 children.push(this._parseCode()); 604 children.push(this._parseCode());
480 break; 605 break;
481 default: 606 default:
482 children.push(new WebInspector.WikiParser.PlainText(token.value( ), false)); 607 text += token.value();
483 break; 608 break;
484 } 609 }
485 } 610 }
486 611
487 return new WebInspector.WikiParser.Inline(WebInspector.WikiParser.Articl eElement.Type.Inline, children); 612 return new WebInspector.WikiParser.Inline(WebInspector.WikiParser.Articl eElement.Type.Inline, children);
488 }, 613 },
489 614
490 /** 615 /**
491 * @return {!WebInspector.WikiParser.Inline} 616 * @return {!WebInspector.WikiParser.Inline}
492 */ 617 */
493 _parseCode : function() 618 _parseCode : function()
494 { 619 {
495 var children = []; 620 var children = [];
496 var text = ""; 621 var text = "";
497 while (this._tokenizer._hasMoreTokens()) { 622 while (this._tokenizer.hasMoreTokens()) {
498 var token = this._tokenizer._nextToken(); 623 var token = this._tokenizer.nextToken();
499 switch (token.type()) { 624 switch (token.type()) {
500 case WebInspector.WikiParser.TokenType.ClosingCodeTag: 625 case WebInspector.WikiParser.TokenType.ClosingCodeTag:
501 text = this._deleteTrailingSpaces(text); 626 text = this._deleteTrailingSpaces(text);
502 if (text.length) { 627 if (text.length) {
503 var simpleText = new WebInspector.WikiParser.PlainText(text, false); 628 var simpleText = new WebInspector.WikiParser.PlainText(text) ;
504 children.push(simpleText); 629 children.push(simpleText);
505 text = ""; 630 text = "";
506 } 631 }
507 var code = new WebInspector.WikiParser.Inline(WebInspector.WikiP arser.ArticleElement.Type.Code, children); 632 var code = new WebInspector.WikiParser.Inline(WebInspector.WikiP arser.ArticleElement.Type.Code, children);
508 return code; 633 return code;
509 case WebInspector.WikiParser.TokenType.OpeningBrackets: 634 case WebInspector.WikiParser.TokenType.OpeningBrackets:
510 var link = this._parseLink(); 635 var link = this._parseLink();
511 children.push(link); 636 children.push(link);
512 break; 637 break;
513 default: 638 default:
514 text += token.value(); 639 text += token.value();
515 } 640 }
516 } 641 }
517 642
518 text = this._deleteTrailingSpaces(text); 643 text = this._deleteTrailingSpaces(text);
519 if (text.length) 644 if (text.length)
520 children.push(new WebInspector.WikiParser.PlainText(text, false)); 645 children.push(new WebInspector.WikiParser.PlainText(text));
521 646
522 return new WebInspector.WikiParser.Inline(WebInspector.WikiParser.Articl eElement.Type.Code, children); 647 return new WebInspector.WikiParser.Inline(WebInspector.WikiParser.Articl eElement.Type.Code, children);
523 }, 648 },
524 649
525 /** 650 /**
526 * @return {!WebInspector.WikiParser.Block} 651 * @return {!WebInspector.WikiParser.Block}
527 */ 652 */
528 _parseBullet: function() 653 _parseBullet: function()
529 { 654 {
530 var children = []; 655 var children = [];
531 while (this._tokenizer._hasMoreTokens()) { 656 while (this._tokenizer.hasMoreTokens()) {
532 var token = this._tokenizer._nextToken() 657 var token = this._tokenizer.nextToken()
533 switch (token.type()) { 658 switch (token.type()) {
534 case WebInspector.WikiParser.TokenType.OpeningBrackets: 659 case WebInspector.WikiParser.TokenType.OpeningBrackets:
535 children.push(this._parseLink()); 660 children.push(this._parseLink());
536 break; 661 break;
537 case WebInspector.WikiParser.TokenType.OpeningCodeTag: 662 case WebInspector.WikiParser.TokenType.OpeningCodeTag:
538 children.push(this._parseCode()); 663 children.push(this._parseCode());
539 break; 664 break;
540 case WebInspector.WikiParser.TokenType.LineEnd: 665 case WebInspector.WikiParser.TokenType.LineEnd:
541 return new WebInspector.WikiParser.Block(children, true); 666 return new WebInspector.WikiParser.Block(children, true);
542 default: 667 default:
543 var text = this._deleteTrailingSpaces(token.value()); 668 var text = this._deleteTrailingSpaces(token.value());
544 if (text.length) { 669 if (text.length) {
545 var simpleText = new WebInspector.WikiParser.PlainText(text, false); 670 var simpleText = new WebInspector.WikiParser.PlainText(text) ;
546 children.push(simpleText); 671 children.push(simpleText);
547 text = ""; 672 text = "";
548 } 673 }
549 } 674 }
550 } 675 }
551 676
552 return new WebInspector.WikiParser.Block(children, true); 677 return new WebInspector.WikiParser.Block(children, true);
553 }, 678 },
554 679
555 /** 680 /**
556 * @return {!WebInspector.WikiParser.PlainText} 681 * @return {!WebInspector.WikiParser.PlainText}
557 */ 682 */
558 _parseHighlight: function() 683 _parseHighlight: function()
559 { 684 {
560 var text = ""; 685 var text = "";
561 while (this._tokenizer._hasMoreTokens()) { 686 while (this._tokenizer.hasMoreTokens()) {
562 var token = this._tokenizer._nextToken() 687 var token = this._tokenizer.nextToken()
563 switch (token.type()) { 688 switch (token.type()) {
564 case WebInspector.WikiParser.TokenType.TripleQuotes: 689 case WebInspector.WikiParser.TokenType.TripleQuotes:
565 text = this._deleteTrailingSpaces(text); 690 text = this._deleteTrailingSpaces(text);
566 return new WebInspector.WikiParser.PlainText(text, true); 691 return new WebInspector.WikiParser.PlainText(text, true);
567 default: 692 default:
568 text += token.value(); 693 text += token.value();
569 } 694 }
570 } 695 }
571 return new WebInspector.WikiParser.PlainText(text, true); 696 return new WebInspector.WikiParser.PlainText(text, true);
572 }, 697 },
573 698
574 /** 699 /**
575 * @param {string} str 700 * @param {string} str
576 * @return {string} 701 * @return {string}
577 */ 702 */
578 _deleteTrailingSpaces: function(str) 703 _deleteTrailingSpaces: function(str)
579 { 704 {
580 return str.replace(/[\n\r]*$/gm, ""); 705 return str.replace(/[\n\r]*$/gm, "");
706 },
707
708 /**
709 * @param {string} str
710 * @return {string} str
711 */
712 _deleteFrontLineEnds: function(str)
713 {
714 return str.replace(/^\n*/, "");
581 } 715 }
582 } 716 }
583 717
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 /** 718 /**
623 * @constructor 719 * @constructor
624 * @param {!WebInspector.WikiParser.ArticleElement.Type} type 720 * @param {!WebInspector.WikiParser.ArticleElement.Type} type
625 */ 721 */
626 WebInspector.WikiParser.ArticleElement = function(type) 722 WebInspector.WikiParser.ArticleElement = function(type)
627 { 723 {
628 this._type = type; 724 this._type = type;
629 } 725 }
630 726
631 WebInspector.WikiParser.ArticleElement.prototype = { 727 WebInspector.WikiParser.ArticleElement.prototype = {
(...skipping 15 matching lines...) Expand all
647 Code: "Code", 743 Code: "Code",
648 Block: "Block", 744 Block: "Block",
649 CodeBlock: "CodeBlock", 745 CodeBlock: "CodeBlock",
650 Inline: "Inline" 746 Inline: "Inline"
651 }; 747 };
652 748
653 /** 749 /**
654 * @constructor 750 * @constructor
655 * @extends {WebInspector.WikiParser.ArticleElement} 751 * @extends {WebInspector.WikiParser.ArticleElement}
656 * @param {string} text 752 * @param {string} text
657 * @param {boolean} highlight 753 * @param {boolean=} highlight
658 */ 754 */
659 WebInspector.WikiParser.PlainText = function(text, highlight) 755 WebInspector.WikiParser.PlainText = function(text, highlight)
660 { 756 {
661 WebInspector.WikiParser.ArticleElement.call(this, WebInspector.WikiParser.Ar ticleElement.Type.PlainText); 757 WebInspector.WikiParser.ArticleElement.call(this, WebInspector.WikiParser.Ar ticleElement.Type.PlainText);
662 this._text = text; 758 this._text = text;
663 this._isHighlighted = highlight; 759 this._isHighlighted = highlight ? highlight : false;
apavlov 2014/09/11 10:40:27 highlight || false
iliia 2014/09/11 13:26:29 Done.
664 } 760 }
665 761
666 WebInspector.WikiParser.PlainText.prototype = { 762 WebInspector.WikiParser.PlainText.prototype = {
667 /** 763 /**
668 * @return {string} 764 * @return {string}
669 */ 765 */
670 text : function() 766 text: function()
671 { 767 {
672 return this._text; 768 return this._text;
673 }, 769 },
674 770
675 /** 771 /**
676 * @return {boolean} 772 * @return {boolean}
677 */ 773 */
678 isHighlighted: function() 774 isHighlighted: function()
679 { 775 {
680 return this._isHighlighted; 776 return this._isHighlighted;
681 }, 777 },
682 778
683 __proto__: WebInspector.WikiParser.ArticleElement.prototype 779 __proto__: WebInspector.WikiParser.ArticleElement.prototype
684 } 780 }
685 781
686 /** 782 /**
687 * @constructor 783 * @constructor
688 * @extends {WebInspector.WikiParser.ArticleElement} 784 * @extends {WebInspector.WikiParser.ArticleElement}
689 * @param {!Array.<!WebInspector.WikiParser.ArticleElement>} children 785 * @param {!Array.<!WebInspector.WikiParser.ArticleElement>} children
690 * @param {boolean} hasBullet 786 * @param {boolean=} hasBullet
691 */ 787 */
692 WebInspector.WikiParser.Block = function(children, hasBullet) 788 WebInspector.WikiParser.Block = function(children, hasBullet)
693 { 789 {
694 WebInspector.WikiParser.ArticleElement.call(this, WebInspector.WikiParser.Ar ticleElement.Type.Block); 790 WebInspector.WikiParser.ArticleElement.call(this, WebInspector.WikiParser.Ar ticleElement.Type.Block);
695 this._children = children; 791 this._children = children;
696 this._hasBullet = hasBullet 792 this._hasBullet = hasBullet ? hasBullet : false;
apavlov 2014/09/11 10:40:27 ditto
iliia 2014/09/11 13:26:29 Done.
697 } 793 }
698 794
699 WebInspector.WikiParser.Block.prototype = { 795 WebInspector.WikiParser.Block.prototype = {
700 /** 796 /**
701 * @return {!Array.<!WebInspector.WikiParser.ArticleElement>} 797 * @return {!Array.<!WebInspector.WikiParser.ArticleElement>}
702 */ 798 */
703 children: function() 799 children: function()
704 { 800 {
705 return this._children; 801 return this._children;
706 }, 802 },
707 803
708 /** 804 /**
709 * @return {boolean} 805 * @return {boolean}
710 */ 806 */
807 hasChildren: function()
808 {
809 return !!this._children && !!this._children.length;
810 },
811
812 /**
813 * @return {boolean}
814 */
711 hasBullet: function() 815 hasBullet: function()
712 { 816 {
713 return this._hasBullet; 817 return this._hasBullet;
714 }, 818 },
715 819
716 __proto__: WebInspector.WikiParser.ArticleElement.prototype 820 __proto__: WebInspector.WikiParser.ArticleElement.prototype
717 } 821 }
718 822
719 /** 823 /**
720 * @constructor 824 * @constructor
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 /** 883 /**
780 * @return {string} 884 * @return {string}
781 */ 885 */
782 url : function() 886 url : function()
783 { 887 {
784 return this._url; 888 return this._url;
785 }, 889 },
786 890
787 __proto__: WebInspector.WikiParser.Inline.prototype 891 __proto__: WebInspector.WikiParser.Inline.prototype
788 } 892 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698