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

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: 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 * @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 try {
66 var article = WebInspector.JSArticle.parse(wikiMarkupText);
lushnikov 2014/09/09 12:40:46 lets avoid varaibel hoisting and declare it outsid
iliia 2014/09/09 14:29:17 Done.
67 } catch (error) {
68 this._createEmptyPage();
lushnikov 2014/09/09 12:40:46 article = null; console.error(error);
iliia 2014/09/09 14:29:17 Done.
69 }
65 if (!article) { 70 if (!article) {
66 this._createEmptyPage(); 71 this._createEmptyPage();
67 return; 72 return;
68 } 73 }
69 74
75 this.element.removeChildren();
70 var renderer = new WebInspector.DocumentationView.Renderer(article, sear chItem); 76 var renderer = new WebInspector.DocumentationView.Renderer(article, sear chItem);
71 this.element.removeChildren();
72 this.element.appendChild(renderer.renderJSArticle()); 77 this.element.appendChild(renderer.renderJSArticle());
73 }, 78 },
74 79
75 _createEmptyPage: function() 80 _createEmptyPage: function()
76 { 81 {
77 this.element.removeChildren(); 82 this.element.removeChildren();
78 var pageTitle = this.element.createChild("div", "documentation-page-titl e"); 83 var pageTitle = this.element.createChild("div", "documentation-page-titl e");
79 pageTitle.textContent = WebInspector.UIString("Documentation not availab le"); 84 pageTitle.textContent = WebInspector.UIString("Documentation not availab le");
80 }, 85 },
81 86
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 title.textContent = "Examples"; 212 title.textContent = "Examples";
208 213
209 for (var i = 0; i < examples.length; ++i) { 214 for (var i = 0; i < examples.length; ++i) {
210 var example = section.createChild("div", "documentation-example"); 215 var example = section.createChild("div", "documentation-example");
211 var exampleDescription = example.createChild("div", "documentation-e xample-description-section"); 216 var exampleDescription = example.createChild("div", "documentation-e xample-description-section");
212 if (examples[i].liveUrl) { 217 if (examples[i].liveUrl) {
213 var liveUrl = exampleDescription.createChild("a", "documentation -example-link"); 218 var liveUrl = exampleDescription.createChild("a", "documentation -example-link");
214 liveUrl.href = examples[i].liveUrl; 219 liveUrl.href = examples[i].liveUrl;
215 liveUrl.textContent = WebInspector.UIString("Example"); 220 liveUrl.textContent = WebInspector.UIString("Example");
216 } 221 }
217 exampleDescription.appendChild(this._renderBlock(examples[i].descrip tion)); 222 if (examples[i].description)
223 exampleDescription.appendChild(this._renderBlock(examples[i].des cription));
218 var code = example.createChild("div", "documentation-example-code"); 224 var code = example.createChild("div", "documentation-example-code");
219 code.classList.add("source-code"); 225 code.classList.add("source-code");
220 code.textContent = examples[i].code; 226 code.textContent = examples[i].code;
221 if (!examples[i].language) 227 if (!examples[i].language)
222 continue; 228 continue;
223 var syntaxHighlighter = new WebInspector.DOMSyntaxHighlighter(WebIns pector.DocumentationView._languageToMimeType[examples[i].language.toLowerCase()] , true); 229 var syntaxHighlighter = new WebInspector.DOMSyntaxHighlighter(WebIns pector.DocumentationView._languageToMimeType[examples[i].language.toLowerCase()] , true);
224 syntaxHighlighter.syntaxHighlightNode(code); 230 syntaxHighlighter.syntaxHighlightNode(code);
225 } 231 }
226 }, 232 },
227 233
228 /** 234 /**
229 * @param {!WebInspector.WikiParser.ArticleElement} article 235 * @param {!WebInspector.WikiParser.ArticleElement} article
230 * @return {!Element} 236 * @return {?Element}
231 */ 237 */
232 _renderBlock: function(article) 238 _renderBlock: function(article)
233 { 239 {
234 var element; 240 var element;
235 var elementTypes = WebInspector.WikiParser.ArticleElement.Type; 241 var elementTypes = WebInspector.WikiParser.ArticleElement.Type;
236 242
237 switch (article.type()) { 243 switch (article.type()) {
238 case elementTypes.Inline: 244 case elementTypes.Inline:
239 element = document.createElement("span"); 245 element = document.createElement("span");
240 break; 246 break;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 function computeDescriptors(column) 343 function computeDescriptors(column)
338 { 344 {
339 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column); 345 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column);
340 if (!token) 346 if (!token)
341 return []; 347 return [];
342 var tokenText = textEditor.line(textSelection.startLine).substring(t oken.startColumn, token.endColumn); 348 var tokenText = textEditor.line(textSelection.startLine).substring(t oken.startColumn, token.endColumn);
343 return urlProvider.itemDescriptors(tokenText); 349 return urlProvider.itemDescriptors(tokenText);
344 } 350 }
345 } 351 }
346 } 352 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698