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

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

Issue 539353004: DevTools: [Documentation] Update parser for WikiText (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add annotation to WikiParser._parse() 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 * @extends {WebInspector.View} 7 * @extends {WebInspector.View}
8 */ 8 */
9 WebInspector.DocumentationView = function() 9 WebInspector.DocumentationView = function()
10 { 10 {
11 WebInspector.View.call(this); 11 WebInspector.View.call(this);
12 this.element.classList.add("documentation-view"); 12 this.element.classList.add("documentation-view");
13 this.registerRequiredCSS("documentationView.css"); 13 this.registerRequiredCSS("documentationView.css");
14 } 14 }
15 15
16 /** 16 /**
17 * @param {string} url 17 * @param {string} url
18 * @param {string} searchItem 18 * @param {string} searchItem
19 */ 19 */
20 WebInspector.DocumentationView.showDocumentationURL = function(url, searchItem) 20 WebInspector.DocumentationView.showDocumentationURL = function(url, searchItem)
21 { 21 {
22 if (!WebInspector.DocumentationView._view) 22 if (!WebInspector.DocumentationView._view)
23 WebInspector.DocumentationView._view = new WebInspector.DocumentationVie w(); 23 WebInspector.DocumentationView._view = new WebInspector.DocumentationVie w();
24 var view = WebInspector.DocumentationView._view; 24 var view = WebInspector.DocumentationView._view;
25 view.element.removeChildren();
25 WebInspector.inspectorView.showCloseableViewInDrawer("documentation", WebIns pector.UIString("Documentation"), view); 26 WebInspector.inspectorView.showCloseableViewInDrawer("documentation", WebIns pector.UIString("Documentation"), view);
26 view.showDocumentation(url, searchItem); 27 view.showDocumentation(url, searchItem);
27 } 28 }
28 29
29 WebInspector.DocumentationView._languageToMimeType = { 30 WebInspector.DocumentationView._languageToMimeType = {
30 "javascript": "text/javascript", 31 "javascript": "text/javascript",
31 "html": "text/html" 32 "html": "text/html"
32 }; 33 };
33 34
34 WebInspector.DocumentationView.prototype = { 35 WebInspector.DocumentationView.prototype = {
(...skipping 19 matching lines...) Expand all
54 _createArticle: function(searchItem, responseText) 55 _createArticle: function(searchItem, responseText)
55 { 56 {
56 var json = JSON.parse(responseText); 57 var json = JSON.parse(responseText);
57 var pages = json["query"]["pages"]; 58 var pages = json["query"]["pages"];
58 var wikiKeys = Object.keys(pages); 59 var wikiKeys = Object.keys(pages);
59 if (wikiKeys.length === 1 && wikiKeys[0] === "-1") { 60 if (wikiKeys.length === 1 && wikiKeys[0] === "-1") {
60 this._createEmptyPage(); 61 this._createEmptyPage();
61 return; 62 return;
62 } 63 }
63 var wikiMarkupText = pages[wikiKeys[0]]["revisions"]["0"]["*"]; 64 var wikiMarkupText = pages[wikiKeys[0]]["revisions"]["0"]["*"];
64 var article = WebInspector.JSArticle.parse(wikiMarkupText); 65 var article;
66 try {
67 article = WebInspector.JSArticle.parse(wikiMarkupText);
68 } catch (error) {
69 this._createEmptyPage();
apavlov 2014/09/10 14:09:23 This and the following line can be dropped: if (!a
iliia 2014/09/11 09:26:30 Done.
70 article = null;
71 console.error(error);
apavlov 2014/09/10 14:09:23 Should this be error.message?
iliia 2014/09/11 09:26:30 Done.
apavlov 2014/09/11 10:40:26 Not done - still, the "error" object is used inste
iliia 2014/09/11 13:26:28 Done.
72 }
65 if (!article) { 73 if (!article) {
66 this._createEmptyPage(); 74 this._createEmptyPage();
67 return; 75 return;
68 } 76 }
69 77
78 this.element.removeChildren();
70 var renderer = new WebInspector.DocumentationView.Renderer(article, sear chItem); 79 var renderer = new WebInspector.DocumentationView.Renderer(article, sear chItem);
71 this.element.removeChildren();
72 this.element.appendChild(renderer.renderJSArticle()); 80 this.element.appendChild(renderer.renderJSArticle());
73 }, 81 },
74 82
75 _createEmptyPage: function() 83 _createEmptyPage: function()
76 { 84 {
77 this.element.removeChildren(); 85 this.element.removeChildren();
78 var emptyPage = this.element.createChild("div", "documentation-empty-pag e fill"); 86 var emptyPage = this.element.createChild("div", "documentation-empty-pag e fill");
79 var pageTitle = emptyPage.createChild("div", "documentation-not-found"); 87 var pageTitle = emptyPage.createChild("div", "documentation-not-found");
80 pageTitle.textContent = "No documentation found."; 88 pageTitle.textContent = "No documentation found.";
81 emptyPage.createChild("div", "documentation-empty-page-align"); 89 emptyPage.createChild("div", "documentation-empty-page-align");
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 code.textContent = examples[i].code; 259 code.textContent = examples[i].code;
252 if (!examples[i].language) 260 if (!examples[i].language)
253 continue; 261 continue;
254 var syntaxHighlighter = new WebInspector.DOMSyntaxHighlighter(WebIns pector.DocumentationView._languageToMimeType[examples[i].language.toLowerCase()] , true); 262 var syntaxHighlighter = new WebInspector.DOMSyntaxHighlighter(WebIns pector.DocumentationView._languageToMimeType[examples[i].language.toLowerCase()] , true);
255 syntaxHighlighter.syntaxHighlightNode(code); 263 syntaxHighlighter.syntaxHighlightNode(code);
256 } 264 }
257 }, 265 },
258 266
259 /** 267 /**
260 * @param {!WebInspector.WikiParser.ArticleElement} article 268 * @param {!WebInspector.WikiParser.ArticleElement} article
261 * @return {!Element} 269 * @return {?Element}
apavlov 2014/09/10 14:09:23 Any reason for this being nullable?
iliia 2014/09/11 09:26:30 element could be undefined if something's going wr
262 */ 270 */
263 _renderBlock: function(article) 271 _renderBlock: function(article)
264 { 272 {
265 var element; 273 var element;
266 var elementTypes = WebInspector.WikiParser.ArticleElement.Type; 274 var elementTypes = WebInspector.WikiParser.ArticleElement.Type;
267 275
268 switch (article.type()) { 276 switch (article.type()) {
269 case elementTypes.Inline: 277 case elementTypes.Inline:
270 element = document.createElement("span"); 278 element = document.createElement("span");
271 break; 279 break;
(...skipping 10 matching lines...) Expand all
282 element = document.createElementWithClass("pre", "documentation-code source-code"); 290 element = document.createElementWithClass("pre", "documentation-code source-code");
283 element.textContent = article.code(); 291 element.textContent = article.code();
284 break; 292 break;
285 case elementTypes.PlainText: 293 case elementTypes.PlainText:
286 element = document.createElement("span"); 294 element = document.createElement("span");
287 element.textContent = article.text(); 295 element.textContent = article.text();
288 if (article.isHighlighted()) 296 if (article.isHighlighted())
289 element.classList.add("documentation-highlighted-text"); 297 element.classList.add("documentation-highlighted-text");
290 break; 298 break;
291 default: 299 default:
292 console.error("Unknown ArticleElement type " + article.type()); 300 console.error("Unknown ArticleElement type " + article.type());
apavlov 2014/09/10 14:09:23 Is this intentionally missing a break; ? Or should
iliia 2014/09/11 09:26:30 Done.
293 case elementTypes.Block: 301 case elementTypes.Block:
294 element = document.createElement(article.hasBullet() ? "li" : "p"); 302 element = document.createElement(article.hasBullet() ? "li" : "p");
295 break; 303 break;
296 } 304 }
297 305
298 if (article instanceof WebInspector.WikiParser.Block || article instance of WebInspector.WikiParser.Inline) { 306 if (article instanceof WebInspector.WikiParser.Block || article instance of WebInspector.WikiParser.Inline) {
apavlov 2014/09/10 14:09:23 Now we can check article.type()
iliia 2014/09/11 09:26:30 Done.
299 for (var i = 0; i < article.children().length; ++i) { 307 for (var i = 0; i < article.children().length; ++i) {
300 var child = this._renderBlock(article.children()[i]); 308 var child = this._renderBlock(article.children()[i]);
301 if (child) 309 if (child)
302 element.appendChild(child); 310 element.appendChild(child);
303 } 311 }
304 } 312 }
305 313
306 return element; 314 return element;
307 } 315 }
308 } 316 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 function computeDescriptors(column) 378 function computeDescriptors(column)
371 { 379 {
372 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column); 380 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column);
373 if (!token) 381 if (!token)
374 return []; 382 return [];
375 var tokenText = textEditor.line(textSelection.startLine).substring(t oken.startColumn, token.endColumn); 383 var tokenText = textEditor.line(textSelection.startLine).substring(t oken.startColumn, token.endColumn);
376 return urlProvider.itemDescriptors(tokenText); 384 return urlProvider.itemDescriptors(tokenText);
377 } 385 }
378 } 386 }
379 } 387 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698