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

Unified Diff: Source/devtools/front_end/documentation/JSArticle.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 side-by-side diff with in-line comments
Download patch
Index: Source/devtools/front_end/documentation/JSArticle.js
diff --git a/Source/devtools/front_end/documentation/JSArticle.js b/Source/devtools/front_end/documentation/JSArticle.js
index beb88dfad5833e84c2722a05166a07f5ca5ee412..94cfda31614da75d8434670891d42c2d4e48de86 100644
--- a/Source/devtools/front_end/documentation/JSArticle.js
+++ b/Source/devtools/front_end/documentation/JSArticle.js
@@ -25,43 +25,55 @@ WebInspector.JSArticle = function()
/**
* @constructor
- * @param {string} name
- * @param {string} dataType
- * @param {string} optional
+ * @param {?WebInspector.WikiParser.Block} name
+ * @param {?WebInspector.WikiParser.Block} dataType
+ * @param {?WebInspector.WikiParser.Block} optional
* @param {?WebInspector.WikiParser.Block} description
*/
WebInspector.JSArticle.Parameter = function(name, dataType, optional, description)
{
- this.name = name;
- this.dataType = dataType;
- this.optional = optional.toUpperCase() === "YES";
+ this.name = WebInspector.JSArticle.textContent(name);
+ this.dataType = WebInspector.JSArticle.textContent(dataType);
+ this.optional = WebInspector.JSArticle.textContent(optional) ? WebInspector.JSArticle.textContent(optional).toUpperCase() === "YES" : false;
apavlov 2014/09/10 14:09:23 This is computing the text content twice in a row.
iliia 2014/09/11 09:26:30 Done.
this.description = description;
}
/**
* @constructor
- * @param {string} language
- * @param {string} code
- * @param {string} liveUrl
+ * @param {?WebInspector.WikiParser.Block} language
+ * @param {!WebInspector.WikiParser.Block} code
+ * @param {?WebInspector.WikiParser.Block} liveUrl
* @param {?WebInspector.WikiParser.Block} description
*/
WebInspector.JSArticle.Example = function(language, code, liveUrl, description)
{
- this.language = language;
- this.code = code;
- this.liveUrl = liveUrl;
+ this.language = WebInspector.JSArticle.textContent(language);
+ this.code = WebInspector.JSArticle.textContent(code);
+ this.liveUrl = WebInspector.JSArticle.textContent(liveUrl);
this.description = description;
}
/**
* @constructor
- * @param {string} returnValueName
- * @param {string} returnValueDescription
+ * @param {?WebInspector.WikiParser.Block} returnValueName
+ * @param {?WebInspector.WikiParser.Block} returnValueDescription
*/
WebInspector.JSArticle.Method = function(returnValueName, returnValueDescription)
{
- this.returnValueName = returnValueName;
- this.returnValueDescription = returnValueDescription;
+ this.returnValueName = WebInspector.JSArticle.textContent(returnValueName);
+ this.returnValueDescription = WebInspector.JSArticle.textContent(returnValueDescription);
+}
+
+/**
+ * @param {?WebInspector.WikiParser.Block} block
+ * @return {null|string}
apavlov 2014/09/10 14:09:23 {?string}
iliia 2014/09/11 09:26:30 Done.
+ */
+WebInspector.JSArticle.textContent = function(block)
+{
+ if (block && Array.isArray(block.children()) && block.children().length > 0
apavlov 2014/09/10 14:09:23 Let's introduce WI.WikiParser.Block.prototype.hasC
iliia 2014/09/11 09:26:30 Done.
+ && Array.isArray(block.children()[0].children()) && block.children()[0].children().length > 0)
+ return block.children()[0].children()[0].text();
apavlov 2014/09/10 14:09:23 Is this the universally correct way to compute the
iliia 2014/09/11 09:26:30 Yes, earlier there was only one simple string. But
+ return null;
}
/**
@@ -70,22 +82,8 @@ WebInspector.JSArticle.Method = function(returnValueName, returnValueDescription
*/
WebInspector.JSArticle.parse = function(wikiMarkupText)
{
- /**
- * @param {string} string
- * @param {string} debugInfo
- * @return {?WebInspector.WikiParser.Block}
- */
- function parseString(string, debugInfo)
- {
- var result = wikiParser.parseString(string);
- if (!result)
- console.error("Can't parse " + debugInfo);
- return result;
- }
-
var wikiParser = new WebInspector.WikiParser(wikiMarkupText);
var wikiDocument = wikiParser.document();
-
var article = new WebInspector.JSArticle();
article.pageTitle = wikiDocument["Page_Title"];
if (typeof article.pageTitle !== "string")
@@ -101,23 +99,18 @@ WebInspector.JSArticle.parse = function(wikiMarkupText)
article.methods = new WebInspector.JSArticle.Method(returnValueName, returnValue);
}
- var remarks = wikiDocument["Remarks_Section"] ? wikiDocument["Remarks_Section"]["Remarks"] : null;
- if (remarks)
- article.remarks = parseString(remarks, "remarks");
-
- var summary = wikiDocument["Summary_Section"];
- if (summary)
- article.summary = parseString(summary, "summary");
+ article.remarks = wikiDocument["Remarks_Section"] ? wikiDocument["Remarks_Section"]["Remarks"] : null;
+ article.summary = wikiDocument["Summary_Section"];
var examples = wikiDocument["Examples_Section"] ? wikiDocument["Examples_Section"]["Examples"] : [];
if (!Array.isArray(examples) && typeof examples !== "undefined")
examples = [examples];
for (var i = 0; i < examples.length; ++i) {
- var language = examples[i]["Single Example"]["Language"];
- var code = examples[i]["Single Example"]["Code"];
- var liveUrl = examples[i]["Single Example"]["LiveURL"];
- var description = parseString(examples[i]["Single Example"]["Description"], "example description");
+ var language = examples[i].values["Language"];
+ var code = examples[i].values["Code"];
+ var liveUrl = examples[i].values["LiveURL"];
+ var description = examples[i].values["Description"];
article.examples.push(new WebInspector.JSArticle.Example(language, code, liveUrl, description));
}
@@ -126,10 +119,10 @@ WebInspector.JSArticle.parse = function(wikiMarkupText)
parameters = [parameters];
for (var i = 0; i < parameters.length; ++i) {
- var name = parameters[i]["Method Parameter"]["Name"];
- var dataType = parameters[i]["Method Parameter"]["Data type"];
- var optional = parameters[i]["Method Parameter"]["Optional"];
- var description = parseString(parameters[i]["Method Parameter"]["Description"], "method description");
+ var name = parameters[i].values["Name"];
+ var dataType = parameters[i].values["Data type"];
+ var optional = parameters[i].values["Optional"];
+ var description = parameters[i].values["Description"];
article.parameters.push(new WebInspector.JSArticle.Parameter(name, dataType, optional, description));
}

Powered by Google App Engine
This is Rietveld 408576698