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

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

Issue 530003002: DevTools: [Documentation] Add syntax highlight for code examples (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@iliia-patch
Patch Set: Fix documentation for RegExp methods 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 view.element.removeChildren();
26 WebInspector.inspectorView.showCloseableViewInDrawer("documentation", WebIns pector.UIString("Documentation"), view); 26 WebInspector.inspectorView.showCloseableViewInDrawer("documentation", WebIns pector.UIString("Documentation"), view);
27 view._revealTermDocument(url, searchItem); 27 view._revealTermDocument(url, searchItem);
28 } 28 }
29 29
30 WebInspector.DocumentationView._languageToMimeType = {
31 "JavaScript": "text/javascript",
32 "HTML": "text/html"
33 }
lushnikov 2014/09/03 15:10:25 semicolon
semeny 2014/09/03 15:34:27 Done.
34
30 WebInspector.DocumentationView.prototype = { 35 WebInspector.DocumentationView.prototype = {
31 /** 36 /**
32 * @param {string} url 37 * @param {string} url
33 * @param {string} searchItem 38 * @param {string} searchItem
34 */ 39 */
35 _revealTermDocument: function(url, searchItem) 40 _revealTermDocument: function(url, searchItem)
36 { 41 {
37 if (!url) { 42 if (!url) {
38 this._createEmptyPage(); 43 this._createEmptyPage();
39 return; 44 return;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 var exampleDescription = example.createChild("div", "documentation-e xample-description-section"); 206 var exampleDescription = example.createChild("div", "documentation-e xample-description-section");
202 if (examples[i].liveUrl) { 207 if (examples[i].liveUrl) {
203 var liveUrl = exampleDescription.createChild("a", "documentation -example-link"); 208 var liveUrl = exampleDescription.createChild("a", "documentation -example-link");
204 liveUrl.href = examples[i].liveUrl; 209 liveUrl.href = examples[i].liveUrl;
205 liveUrl.textContent = WebInspector.UIString("Example"); 210 liveUrl.textContent = WebInspector.UIString("Example");
206 } 211 }
207 exampleDescription.appendChild(this._renderBlock(examples[i].descrip tion)); 212 exampleDescription.appendChild(this._renderBlock(examples[i].descrip tion));
208 var code = example.createChild("div", "documentation-example-code"); 213 var code = example.createChild("div", "documentation-example-code");
209 code.classList.add("source-code"); 214 code.classList.add("source-code");
210 code.textContent = examples[i].code; 215 code.textContent = examples[i].code;
216 var syntaxHighlighter = new WebInspector.DOMSyntaxHighlighter(WebIns pector.DocumentationView._languageToMimeType[examples[i].language], true);
lushnikov 2014/09/03 15:10:25 what if they pass JAVASCRIPT in there? this gonna
semeny 2014/09/03 15:34:27 Done.
217 syntaxHighlighter.syntaxHighlightNode(code);
211 } 218 }
212 }, 219 },
213 220
214 /** 221 /**
215 * @param {!WebInspector.WikiParser.ArticleElement} article 222 * @param {!WebInspector.WikiParser.ArticleElement} article
216 * @return {?Element} 223 * @return {?Element}
217 */ 224 */
218 _renderBlock: function(article) 225 _renderBlock: function(article)
219 { 226 {
220 var element; 227 var element;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 function computeDescriptors(column) 325 function computeDescriptors(column)
319 { 326 {
320 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column); 327 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column);
321 if (!token) 328 if (!token)
322 return []; 329 return [];
323 var tokenText = textEditor.line(textSelection.startLine).substring(t oken.startColumn, token.endColumn); 330 var tokenText = textEditor.line(textSelection.startLine).substring(t oken.startColumn, token.endColumn);
324 return urlProvider.itemDescriptors(tokenText); 331 return urlProvider.itemDescriptors(tokenText);
325 } 332 }
326 } 333 }
327 } 334 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698