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

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 method secondToken() 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();
lushnikov 2014/09/08 14:08:29 why do we need this?
iliia 2014/09/08 15:20:49 We discuss it with offline. On 2014/09/08 14:08:29
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);
67 } catch (error) {
68 this._createPageForError(error);
lushnikov 2014/09/08 14:08:29 let's fallback to empty page for now. We'll do a "
iliia 2014/09/08 15:20:50 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();
lushnikov 2014/09/08 14:08:29 why this change?
iliia 2014/09/08 15:20:49 We discuss it offline. On 2014/09/08 14:08:29, lus
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
87 _createPageForError: function(message)
88 {
89 this.element.removeChildren();
90 var pageTitle = this.element.createChild("div", "documentation-page-titl e");
91 pageTitle.textContent = WebInspector.UIString("We have some problems");
92 var error = this.element.createChild("div", "documentation-text");
93 error.textContent = WebInspector.UIString("Error message: " + message);
94 },
95
82 __proto__: WebInspector.View.prototype 96 __proto__: WebInspector.View.prototype
83 } 97 }
84 98
85 /** 99 /**
86 * @constructor 100 * @constructor
87 * @param {!WebInspector.JSArticle} article 101 * @param {!WebInspector.JSArticle} article
88 * @param {string} searchItem 102 * @param {string} searchItem
89 */ 103 */
90 WebInspector.DocumentationView.Renderer = function(article, searchItem) 104 WebInspector.DocumentationView.Renderer = function(article, searchItem)
91 { 105 {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 code.textContent = examples[i].code; 234 code.textContent = examples[i].code;
221 if (!examples[i].language) 235 if (!examples[i].language)
222 continue; 236 continue;
223 var syntaxHighlighter = new WebInspector.DOMSyntaxHighlighter(WebIns pector.DocumentationView._languageToMimeType[examples[i].language.toLowerCase()] , true); 237 var syntaxHighlighter = new WebInspector.DOMSyntaxHighlighter(WebIns pector.DocumentationView._languageToMimeType[examples[i].language.toLowerCase()] , true);
224 syntaxHighlighter.syntaxHighlightNode(code); 238 syntaxHighlighter.syntaxHighlightNode(code);
225 } 239 }
226 }, 240 },
227 241
228 /** 242 /**
229 * @param {!WebInspector.WikiParser.ArticleElement} article 243 * @param {!WebInspector.WikiParser.ArticleElement} article
230 * @return {!Element} 244 * @return {?Element}
231 */ 245 */
232 _renderBlock: function(article) 246 _renderBlock: function(article)
233 { 247 {
234 var element; 248 var element;
235 var elementTypes = WebInspector.WikiParser.ArticleElement.Type; 249 var elementTypes = WebInspector.WikiParser.ArticleElement.Type;
236 250
237 switch (article.type()) { 251 switch (article.type()) {
238 case elementTypes.Inline: 252 case elementTypes.Inline:
239 element = document.createElement("span"); 253 element = document.createElement("span");
240 break;
lushnikov 2014/09/08 14:08:30 I believe you still want "break" statement
iliia 2014/09/08 15:20:49 Done.
241 case elementTypes.Link: 254 case elementTypes.Link:
242 element = document.createElementWithClass("a", "documentation-link") ; 255 element = document.createElementWithClass("a", "documentation-link") ;
243 element.href = article.url(); 256 element.href = article.url();
244 if (!article.children().length) 257 if (!article.children().length)
245 element.textContent = article.url(); 258 element.textContent = article.url();
246 break; 259 break;
247 case elementTypes.Code: 260 case elementTypes.Code:
248 element = document.createElementWithClass("span", "documentation-cod e-tag"); 261 element = document.createElementWithClass("span", "documentation-cod e-tag");
249 break; 262 break;
250 case elementTypes.CodeBlock: 263 case elementTypes.CodeBlock:
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 function computeDescriptors(column) 350 function computeDescriptors(column)
338 { 351 {
339 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column); 352 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column);
340 if (!token) 353 if (!token)
341 return []; 354 return [];
342 var tokenText = textEditor.line(textSelection.startLine).substring(t oken.startColumn, token.endColumn); 355 var tokenText = textEditor.line(textSelection.startLine).substring(t oken.startColumn, token.endColumn);
343 return urlProvider.itemDescriptors(tokenText); 356 return urlProvider.itemDescriptors(tokenText);
344 } 357 }
345 } 358 }
346 } 359 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698