Commit 655be0e8 authored by iliia@google.com's avatar iliia@google.com

DevTools: [Documentation] Update parser for WikiText

BUG=391593

Review URL: https://codereview.chromium.org/539353004

git-svn-id: svn://svn.chromium.org/blink/trunk@181901 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 76fc0b6d
Running: testWikiParser
"{{A|B={{C|D=blablabla}}}}" is parsed
"{{A|text=<code>it's not a code <code>}}" is parsed
{
A : {
text : {
_children : [
{
_children : [
{
_isHighlighted : false
_text : "<code>it's not a code <code>"
_type : "PlainText"
}
]
_hasBullet : false
_type : "Block"
}
]
_hasBullet : false
_type : "Block"
}
}
}
"{{A|Code={{=}} }}" is parsed
{
A : {
Code : {
_children : [
{
_children : [
{
_isHighlighted : false
_text : "="
_type : "PlainText"
}
]
_hasBullet : false
_type : "Block"
}
]
_hasBullet : false
_type : "Block"
}
}
}
"{{ABC|Array={{A|B=c}}{{X|y=Z}}|text=blabla}}" is parsed
{
ABC : {
Array : [
{
title : "A"
values : {
B : {
_children : [
{
_children : [
{
_isHighlighted : false
_text : "c"
_type : "PlainText"
}
]
_hasBullet : false
_type : "Block"
}
]
_hasBullet : false
_type : "Block"
}
}
}
{
title : "X"
values : {
y : {
_children : [
{
_children : [
{
_isHighlighted : false
_text : "Z"
_type : "PlainText"
}
]
_hasBullet : false
_type : "Block"
}
]
_hasBullet : false
_type : "Block"
}
}
}
]
text : {
_children : [
{
_children : [
{
_isHighlighted : false
_text : "blabla"
_type : "PlainText"
}
]
_hasBullet : false
_type : "Block"
}
]
_hasBullet : false
_type : "Block"
}
}
}
"{{A|B=C}}" is parsed
{
A : {
B : {
C : {
D : "blablabla"
_children : [
{
_children : [
{
_isHighlighted : false
_text : "C"
_type : "PlainText"
}
]
_hasBullet : false
_type : "Block"
}
]
_hasBullet : false
_type : "Block"
}
}
}
"{{A|B={{C|D=blablabla}}}}" is parsed
{
A : {
B : [
{
title : "C"
values : {
D : {
_children : [
{
_children : [
{
_isHighlighted : false
_text : "blablabla"
_type : "PlainText"
}
]
_hasBullet : false
_type : "Block"
}
]
_hasBullet : false
_type : "Block"
}
}
}
]
}
}
"{{A|B={{C|D=bla}}|x=y}}" is parsed
{
A : {
B : [
{
title : "C"
values : {
D : {
_children : [
{
_children : [
{
_isHighlighted : false
_text : "bla"
_type : "PlainText"
}
]
_hasBullet : false
_type : "Block"
}
]
_hasBullet : false
_type : "Block"
}
}
}
]
x : {
_children : [
{
_children : [
{
_isHighlighted : false
_text : "y"
_type : "PlainText"
}
]
_hasBullet : false
_type : "Block"
}
]
_hasBullet : false
_type : "Block"
}
}
}
"{{CS|Init=black|Values={{CSS Property Value
|Data Type=color
|Description=[[css/color|CSS color value]]}}
|Description= [[css/color|CSS color value]]}}
}}" is parsed
{
CS : {
Init : "black"
Values : {
CSS Property Value : {
Data Type : "color"
Description : "[[css/color|CSS color value]]"
}
Init : {
_children : [
{
_children : [
{
_isHighlighted : false
_text : "black"
_type : "PlainText"
}
]
_hasBullet : false
_type : "Block"
}
]
_hasBullet : false
_type : "Block"
}
Values : [
{
title : "CSS Property Value"
values : {
Data Type : {
_children : [
{
_children : [
{
_isHighlighted : false
_text : "color"
_type : "PlainText"
}
]
_hasBullet : false
_type : "Block"
}
]
_hasBullet : false
_type : "Block"
}
Description : {
_children : [
{
_children : [
{
_children : [
{
_children : [
{
_isHighlighted : false
_text : "CSS color value"
_type : "PlainText"
}
]
_type : "Inline"
}
]
_type : "Link"
_url : "css/color"
}
]
_hasBullet : false
_type : "Block"
}
]
_hasBullet : false
_type : "Block"
}
}
}
]
}
}
"{{A}}" is parsed
{
A : undefined
}
"{{A|B= [[google.com{{!}}Google]]}}" is parsed
{
A : {
B : {
_children : [
{
_children : [
{
_children : [
{
_children : [
{
_isHighlighted : false
_text : "Google"
_type : "PlainText"
}
]
_type : "Inline"
}
]
_type : "Link"
_url : "google.com"
}
]
_hasBullet : false
_type : "Block"
}
]
_hasBullet : false
_type : "Block"
}
}
}
"{{A|B=bla<a=c>bla}}" is parsed
"{{AbC|xyz
\r}}" is parsed
{
A : {
B : "bla<a=c>bla"
AbC : {
_children : [
{
_children : [
{
_isHighlighted : false
_text : "xyz"
_type : "PlainText"
}
]
_hasBullet : false
_type : "Block"
}
]
_hasBullet : false
_type : "Block"
}
}
"{{A}}" is parsed
"{{Table|there is a table {{{!}}
}}" is parsed
{
A : {
Table : {
_children : [
{
_children : [
{
_isHighlighted : false
_text : "there is a table {{{!}}"
_type : "PlainText"
}
]
_hasBullet : false
_type : "Block"
}
]
_hasBullet : false
_type : "Block"
}
}
"{{AbC|xyz
\r}}" is parsed
"{{External_Attribution|MSDN_link=[http://msdn.microsoft.com/en-us/library/ie/ms536365(v=vs.85).aspx cloneNode Method]|HTML5Rocks_link=}}" is parsed
{
AbC : "xyz
"
External_Attribution : {
HTML5Rocks_link : undefined
MSDN_link : {
_children : [
{
_children : [
{
_isHighlighted : false
_text : "[http://msdn.microsoft.com/en-us/library/ie/ms536365(v=vs.85).aspx cloneNode Method]"
_type : "PlainText"
}
]
_hasBullet : false
_type : "Block"
}
]
_hasBullet : false
_type : "Block"
}
}
}
"{{JS_Syntax|Formats={{JS Syntax Format|Format='''JSON.stringify(''' value [ , replacer] [ , space] ''')'''}}
}}" is parsed
{
JS_Syntax : {
Formats : [
{
title : "JS Syntax Format"
values : {
Format : {
_children : [
{
_children : [
{
_isHighlighted : true
_text : "JSON.stringify("
_type : "PlainText"
}
{
_isHighlighted : false
_text : " value"
_type : "PlainText"
}
{
_children : [
]
_type : "Link"
_url : " , replacer"
}
{
_children : [
]
_type : "Link"
_url : " , space"
}
{
_isHighlighted : false
_text : " "
_type : "PlainText"
}
{
_isHighlighted : true
_text : ")"
_type : "PlainText"
}
]
_hasBullet : false
_type : "Block"
}
]
_hasBullet : false
_type : "Block"
}
}
}
]
}
}
Running: testJS
......@@ -123,6 +521,7 @@ Running: testJS
_hasBullet : false
_type : "Block"
}
summary : undefined
}
Running: testSmall
......@@ -131,6 +530,7 @@ Running: testSmall
]
parameters : [
]
remarks : null
summary : {
_children : [
{
......@@ -161,6 +561,7 @@ Running: testHighlightAndLink
]
parameters : [
]
remarks : null
summary : {
_children : [
{
......@@ -269,6 +670,7 @@ Running: testNamedLink
]
parameters : [
]
remarks : null
summary : {
_children : [
{
......@@ -305,6 +707,7 @@ Running: testBullet
]
parameters : [
]
remarks : null
summary : {
_children : [
{
......@@ -444,6 +847,7 @@ console.log(Object.keys(my_array));
_hasBullet : false
_type : "Block"
}
summary : undefined
}
Running: testComplexLinkName
......@@ -452,6 +856,7 @@ Running: testComplexLinkName
]
parameters : [
]
remarks : null
summary : {
_children : [
{
......@@ -498,6 +903,7 @@ Running: testCodeInsideBullet
]
parameters : [
]
remarks : null
summary : {
_children : [
{
......@@ -528,7 +934,6 @@ Running: testCodeInsideBullet
}
Running: testInvalidInput
error: Can't parse remarks
[object Object]
Running: testLinkInsideCode
......@@ -537,6 +942,7 @@ Running: testLinkInsideCode
]
parameters : [
]
remarks : null
summary : {
_children : [
{
......@@ -635,6 +1041,8 @@ Running: testExamples
]
parameters : [
]
remarks : null
summary : undefined
}
Running: testJsMethod
......@@ -691,15 +1099,10 @@ Running: testJsMethod
optional : true
}
]
remarks : null
summary : undefined
}
Running: testLinkWithoutSpace
error: Can't parse summary
{
examples : [
]
parameters : [
]
summary : null
}
Expected error: Error: Two closing braces expected; found WRONG_LINK
......@@ -11,12 +11,19 @@ function test()
function testWikiParser(next)
{
var testCases = [
"{{A|text=&lt;code>it's not a code &lt;code>}}",
"{{A|Code={{=}} }}",
"{{ABC|Array={{A|B=c}}{{X|y=Z}}|text=blabla}}",
"{{A|B=C}}",
"{{A|B={{C|D=blablabla}}}}",
"{{CS|Init=black|Values={{CSS Property Value\n|Data Type=color\n|Description=[[css/color|CSS color value]]}}\n}}",
"{{A|B={{C|D=bla}}|x=y}}",
"{{CS|Init=black|Values={{CSS Property Value\n|Data Type=color\n|Description= [[css/color|CSS color value]]}}\n}}",
"{{A}}",
"{{A|B=bla<a=c>bla}}",
"{{A}}",
"{{AbC|xyz \n \t \r}}"];
"{{A|B= [[google.com{{!}}Google]]}}",
"{{AbC|xyz \n\t \r}}",
"{{Table|there is a table {{{!}}\n}}",
"{{External_Attribution|MSDN_link=[http://msdn.microsoft.com/en-us/library/ie/ms536365(v=vs.85).aspx cloneNode Method]|HTML5Rocks_link=}}",
"{{JS_Syntax|Formats={{JS Syntax Format|Format='''JSON.stringify(''' value [ , replacer] [ , space] ''')'''}}\n}}"];
for (var i = 0; i < testCases.length; i++) {
var wikiParser = new WebInspector.WikiParser(testCases[i]);
InspectorTest.addResult("\"" + testCases[i].replace("\r", "\\r") + "\" is parsed");
......@@ -99,7 +106,7 @@ function test()
function testLinkInsideCode(next)
{
var linkInsideCode = "{{Summary_Section|<code> [[google.com|GOOGLE!]] < /code>}}";
var linkInsideCode = "{{Summary_Section|<code> [[google.com|GOOGLE!]] </code >}}";
var article = WebInspector.JSArticle.parse(linkInsideCode);
InspectorTest.addObject(article);
next();
......@@ -124,13 +131,16 @@ function test()
function testLinkWithoutSpace(next)
{
var linkWithoutSpaceTest = "{{Summary_Section|[[http://wrong.com|WRONG_LINK]]}}";
var article = WebInspector.JSArticle.parse(linkWithoutSpaceTest);
InspectorTest.addObject(article);
try {
var article = WebInspector.JSArticle.parse(linkWithoutSpaceTest);
InspectorTest.addObject(article);
} catch (error) {
InspectorTest.addResult("Expected error: " + error);
}
next();
}
]);
}
</script>
</head>
......
......@@ -166,6 +166,20 @@ String.prototype.escapeHTML = function()
return this.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;"); //" doublequotes just for editor
}
/**
* @return {string}
*/
String.prototype.unescapeHTML = function()
{
return this.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">")
.replace(/&#58;/g, ":")
.replace(/&quot;/g, "\"")
.replace(/&#60;/g, "<")
.replace(/&#62;/g, ">")
.replace(/&amp;/g, "&");
}
/**
* @return {string}
*/
......
......@@ -22,6 +22,7 @@ WebInspector.DocumentationView.showDocumentationURL = function(url, searchItem)
if (!WebInspector.DocumentationView._view)
WebInspector.DocumentationView._view = new WebInspector.DocumentationView();
var view = WebInspector.DocumentationView._view;
view.element.removeChildren();
WebInspector.inspectorView.showCloseableViewInDrawer("documentation", WebInspector.UIString("Documentation"), view);
view.showDocumentation(url, searchItem);
}
......@@ -61,14 +62,19 @@ WebInspector.DocumentationView.prototype = {
return;
}
var wikiMarkupText = pages[wikiKeys[0]]["revisions"]["0"]["*"];
var article = WebInspector.JSArticle.parse(wikiMarkupText);
var article;
try {
article = WebInspector.JSArticle.parse(wikiMarkupText);
} catch (error) {
console.error("Article could not be parsed. " + error.message);
}
if (!article) {
this._createEmptyPage();
return;
}
var renderer = new WebInspector.DocumentationView.Renderer(article, searchItem);
this.element.removeChildren();
var renderer = new WebInspector.DocumentationView.Renderer(article, searchItem);
this.element.appendChild(renderer.renderJSArticle());
},
......@@ -171,7 +177,7 @@ WebInspector.DocumentationView.Renderer.prototype = {
if (i > 0)
signature.createTextChild(", ")
var parameterType = signature.createChild("span", "documentation-parameter-data-type-value");
parameterType.textContent = parameters[i].dataType + (parameters[i].optional ? "=" : "");;
parameterType.textContent = parameters[i].dataType + (parameters[i].optional ? "=" : "");
}
signature.createTextChild("): ");
var returnTypeElement = signature.createChild("span", "documentation-parameter-data-type-value");
......@@ -258,11 +264,11 @@ WebInspector.DocumentationView.Renderer.prototype = {
/**
* @param {!WebInspector.WikiParser.ArticleElement} article
* @return {!Element}
* @return {?Element}
*/
_renderBlock: function(article)
{
var element;
var element = null;
var elementTypes = WebInspector.WikiParser.ArticleElement.Type;
switch (article.type()) {
......@@ -288,14 +294,17 @@ WebInspector.DocumentationView.Renderer.prototype = {
if (article.isHighlighted())
element.classList.add("documentation-highlighted-text");
break;
default:
console.error("Unknown ArticleElement type " + article.type());
case elementTypes.Block:
element = document.createElement(article.hasBullet() ? "li" : "p");
break;
default:
console.error("Unknown ArticleElement type " + article.type());
return null;
}
if (article instanceof WebInspector.WikiParser.Block || article instanceof WebInspector.WikiParser.Inline) {
if (article.type() === WebInspector.WikiParser.ArticleElement.Type.Block
|| article.type() === WebInspector.WikiParser.ArticleElement.Type.Code
|| article.type() === WebInspector.WikiParser.ArticleElement.Type.Inline) {
for (var i = 0; i < article.children().length; ++i) {
var child = this._renderBlock(article.children()[i]);
if (child)
......
......@@ -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.unfoldStringValue(name);
this.dataType = WebInspector.JSArticle.unfoldStringValue(dataType);
var textContent = WebInspector.JSArticle.unfoldStringValue(optional);
this.optional = textContent ? textContent.toUpperCase() === "YES" : false;
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.unfoldStringValue(language);
this.code = WebInspector.JSArticle.unfoldStringValue(code);
this.liveUrl = WebInspector.JSArticle.unfoldStringValue(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.unfoldStringValue(returnValueName);
this.returnValueDescription = WebInspector.JSArticle.unfoldStringValue(returnValueDescription);
}
/**
* @param {?WebInspector.WikiParser.Block} block
* @return {?string}
*/
WebInspector.JSArticle.unfoldStringValue = function(block)
{
if (block && block.hasChildren() && block.children()[0].hasChildren())
return block.children()[0].children()[0].text();
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));
}
......
......@@ -8,72 +8,66 @@
*/
WebInspector.WikiParser = function(wikiMarkupText)
{
this._position = 0;
this._wikiMarkupText = wikiMarkupText;
var text = wikiMarkupText;
this._tokenizer = new WebInspector.WikiParser.Tokenizer(text);
this._document = this._parse();
/** @type {?WebInspector.WikiParser.Tokenizer} */
this._tokenizer;
}
/**
* @package
* @enum {string}
* @constructor
*/
WebInspector.WikiParser.State = {
Error: "Error",
FirstOpen: "FirstOpen",
SecondOpen: "SecondOpen",
Title: "Title",
PropertyName: "PropertyName",
PropertyValue: "PropertyValue",
FirstClose: "FirstClose",
SecondClose: "SecondClose"
}
WebInspector.WikiParser.Section = function()
{
/** @type {string} */
this.title;
/**
* @package
* @enum {string}
*/
WebInspector.WikiParser.LinkStates = {
Error: "Error",
LinkUrl: "LinkUrl",
LinkName: "LinkName"
}
/** @type {?WebInspector.WikiParser.Values} */
this.values;
/**
* @package
* @enum {string}
*/
WebInspector.WikiParser.HtmlStates = {
Error: "Error",
Entry: "Entry",
InsideTag: "InsideTag",
Exit: "Exit"
/** @type {?WebInspector.WikiParser.ArticleElement} */
this.singleValue;
}
/**
* @package
* @enum {string}
* @constructor
*/
WebInspector.WikiParser.ValueState = {
Error: "Error",
Outside: "Outside",
InsideSquare: "InsideSquare"
WebInspector.WikiParser.Field = function()
{
/** @type {string} */
this.name;
/** @type {?WebInspector.WikiParser.FieldValue} */
this.value;
}
/** @typedef {(?WebInspector.WikiParser.ArticleElement|!Array.<!WebInspector.WikiParser.Section>)} */
WebInspector.WikiParser.FieldValue;
/** @typedef {?Object.<string, !WebInspector.WikiParser.FieldValue>} */
WebInspector.WikiParser.Values;
/** @typedef {(?WebInspector.WikiParser.Value|?WebInspector.WikiParser.ArticleElement)} */
WebInspector.WikiParser.Value;
/**
* @package
* @enum {string}
*/
WebInspector.WikiParser.TokenType = {
TripleQuotes: "TripleQuotes",
Text: "Text",
Table: "Table",
OpeningBraces: "OpeningBraces",
ClosingBraces: "ClosingBraces",
Exclamation: "Exclamation",
OpeningBrackets: "OpeningBrackets",
OpeningCodeTag: "OpeningCodeTag",
ClosingBrackets: "ClosingBrackets",
EqualSign: "EqualSign",
EqualSignInBraces: "EqualSignInBraces",
VerticalLine: "VerticalLine",
TripleQuotes: "TripleQuotes",
OpeningCodeTag: "OpeningCodeTag",
ClosingCodeTag: "ClosingCodeTag",
Bullet: "Bullet",
Text: "Text",
VerticalLine: "VerticalLine",
LineEnd: "LineEnd",
CodeBlock: "CodeBlock"
}
......@@ -114,22 +108,41 @@ WebInspector.WikiParser.Token.prototype = {
WebInspector.WikiParser.Tokenizer = function(str)
{
this._text = str;
this._token = this._internalNextToken();
}
WebInspector.WikiParser.Tokenizer.prototype = {
/**
* @return {!WebInspector.WikiParser.Token}
*/
_nextToken: function()
peekToken: function()
{
return this._token;
},
/**
* @return {!WebInspector.WikiParser.Token}
*/
nextToken: function()
{
var token = this._token;
this._token = this._internalNextToken();
return token;
},
/**
* @return {!WebInspector.WikiParser.Token}
*/
_internalNextToken: function()
{
if (WebInspector.WikiParser.newLineWithSpace.test(this._text)) {
var result = WebInspector.WikiParser.newLineWithSpace.exec(this._text);
var begin = result.index + result[0].length;
var begin = result.index;
var end = this._text.length;
var lineEnd = WebInspector.WikiParser.newLineWithoutSpace.exec(this._text);
if (lineEnd)
end = lineEnd.index;
var token = this._text.substring(begin, end).replace(/\n */g, "\n");
var token = this._text.substring(begin, end).replace(/\n /g, "\n").replace(/{{=}}/g, "=");
this._text = this._text.substring(end + 1);
return new WebInspector.WikiParser.Token(token, WebInspector.WikiParser.TokenType.CodeBlock);
}
......@@ -158,15 +171,76 @@ WebInspector.WikiParser.Tokenizer.prototype = {
return new WebInspector.WikiParser.Token(token, WebInspector.WikiParser.TokenType.Text);
},
/**
* @return {!WebInspector.WikiParser.Tokenizer}
*/
clone: function()
{
var tokenizer = new WebInspector.WikiParser.Tokenizer(this._text);
tokenizer._token = this._token;
tokenizer._text = this._text;
return tokenizer;
},
/**
* @return {boolean}
*/
_hasMoreTokens: function()
hasMoreTokens: function()
{
return !!this._text.length;
}
}
WebInspector.WikiParser.table = /^{{{!}}/;
WebInspector.WikiParser.exclamation = /^{{!}}/;
WebInspector.WikiParser.openingBraces = /^{{/;
WebInspector.WikiParser.equalSign = /^=/;
WebInspector.WikiParser.equalSignInBraces = /^{{=}}/;
WebInspector.WikiParser.closingBraces = /^\s*}}/;
WebInspector.WikiParser.oneOpeningBracketWithSpace = /^\n* \[/;
WebInspector.WikiParser.twoOpeningBracketsWithSpace = /^\n* \[\[/;
WebInspector.WikiParser.oneClosingBracket = /^\n*\]/;
WebInspector.WikiParser.twoClosingBrackets = /^\n*\]\]/;
WebInspector.WikiParser.tripleQuotes = /^\n*'''/;
WebInspector.WikiParser.openingCodeTag = /^<code\s*>/;
WebInspector.WikiParser.closingCodeTag = /^<\/code\s*>/;
WebInspector.WikiParser.closingBullet = /^\*/;
WebInspector.WikiParser.lineEnd = /^\n/;
WebInspector.WikiParser.verticalLine = /^\n*\|/;
WebInspector.WikiParser.newLineWithSpace = /^\n [^ ]/;
WebInspector.WikiParser.newLineWithoutSpace = /\n[^ ]/;
/**
* @constructor
* @param {!RegExp} regex
* @param {!WebInspector.WikiParser.TokenType} type
*/
WebInspector.WikiParser.TokenDescriptor = function(regex, type)
{
this.regex = regex;
this.type = type;
}
WebInspector.WikiParser._tokenDescriptors = [
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.exclamation, WebInspector.WikiParser.TokenType.Exclamation),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.equalSignInBraces, WebInspector.WikiParser.TokenType.EqualSignInBraces),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.equalSign, WebInspector.WikiParser.TokenType.EqualSign),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.table, WebInspector.WikiParser.TokenType.Table),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.openingBraces, WebInspector.WikiParser.TokenType.OpeningBraces),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.verticalLine, WebInspector.WikiParser.TokenType.VerticalLine),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingBraces, WebInspector.WikiParser.TokenType.ClosingBraces),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.twoOpeningBracketsWithSpace, WebInspector.WikiParser.TokenType.OpeningBrackets),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.twoClosingBrackets, WebInspector.WikiParser.TokenType.ClosingBrackets),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.oneOpeningBracketWithSpace, WebInspector.WikiParser.TokenType.OpeningBrackets),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.oneClosingBracket, WebInspector.WikiParser.TokenType.ClosingBrackets),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.newLineWithSpace, WebInspector.WikiParser.TokenType.CodeBlock),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.tripleQuotes, WebInspector.WikiParser.TokenType.TripleQuotes),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.openingCodeTag, WebInspector.WikiParser.TokenType.OpeningCodeTag),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingCodeTag, WebInspector.WikiParser.TokenType.ClosingCodeTag),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingBullet, WebInspector.WikiParser.TokenType.Bullet),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.lineEnd, WebInspector.WikiParser.TokenType.LineEnd)
]
WebInspector.WikiParser.prototype = {
/**
* @return {!Object}
......@@ -177,199 +251,206 @@ WebInspector.WikiParser.prototype = {
},
/**
* @return {!Object}
* @return {?WebInspector.WikiParser.TokenType}
*/
_secondTokenType: function()
{
var tokenizer = this._tokenizer.clone();
if (!tokenizer.hasMoreTokens())
return null;
tokenizer.nextToken();
if (!tokenizer.hasMoreTokens())
return null;
return tokenizer.nextToken().type();
},
/**
* @return {!Object.<string, ?WebInspector.WikiParser.Value>}
*/
_parse: function()
{
var obj = {};
this._wikiMarkupText = this._wikiMarkupText.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">")
.replace(/&#58;/g, ":")
.replace(/&quot;/g, "\"")
.replace(/&#60;/g, "<")
.replace(/&#62;/g, ">")
.replace(/{{=}}/g, "=")
.replace(/{{!}}/g, "|")
.replace(/&amp;/g, "&");
while (this._position < this._wikiMarkupText.length) {
var field = this._parseField();
for (var key in field) {
console.assert(typeof obj[key] === "undefined", "Duplicate key: " + key);
obj[key] = field[key];
}
while (this._tokenizer.hasMoreTokens()) {
var section = this._parseSection();
if (section.title)
obj[section.title] = section.singleValue || section.values;
}
return obj;
},
/**
* @return {string}
* @return {!WebInspector.WikiParser.Section}
*/
_parseValue: function() {
var states = WebInspector.WikiParser.ValueState;
var state = states.Outside;
var value = "";
while (this._position < this._wikiMarkupText.length) {
switch (state) {
case states.Outside:
if (this._wikiMarkupText[this._position] === "|" || (this._wikiMarkupText[this._position] === "}" && this._wikiMarkupText[this._position + 1] === "}"))
return value;
switch (this._wikiMarkupText[this._position]) {
case "<":
var indexClose = this._wikiMarkupText.indexOf(">", this._position);
if (indexClose !== -1) {
value += this._wikiMarkupText.substring(this._position, indexClose + 1);
this._position = indexClose;
}
break;
case "[":
state = states.InsideSquare;
value += this._wikiMarkupText[this._position];
break;
default:
value += this._wikiMarkupText[this._position];
}
break;
case states.InsideSquare:
if (this._wikiMarkupText[this._position] === "[") {
var indexClose = this._wikiMarkupText.indexOf("]]", this._position);
if (indexClose !== -1) {
value += this._wikiMarkupText.substring(this._position, indexClose + 2);
this._position = indexClose + 1;
}
} else {
var indexClose = this._wikiMarkupText.indexOf("]", this._position);
if (indexClose !== -1) {
value += this._wikiMarkupText.substring(this._position, indexClose + 1);
this._position = indexClose;
}
_parseSection: function()
{
var section = new WebInspector.WikiParser.Section();
if (!this._tokenizer.hasMoreTokens() || this._tokenizer.nextToken().type() !== WebInspector.WikiParser.TokenType.OpeningBraces)
return section;
var title = this._deleteTrailingSpaces(this._parseSectionTitle());
if (!title.length)
return section;
section.title = title;
if (this._tokenizer.peekToken().type() === WebInspector.WikiParser.TokenType.ClosingBraces) {
this._tokenizer.nextToken();
return section;
}
var secondTokenType = this._secondTokenType();
if (!secondTokenType || secondTokenType !== WebInspector.WikiParser.TokenType.EqualSign) {
section.singleValue = this._parseMarkupText();
} else {
section.values = {};
while (this._tokenizer.hasMoreTokens()) {
var field = this._parseField();
section.values[field.name] = field.value;
if (this._tokenizer.peekToken().type() === WebInspector.WikiParser.TokenType.ClosingBraces) {
this._tokenizer.nextToken();
return section;
}
state = states.Outside;
break;
}
this._position++;
}
return value;
var token = this._tokenizer.nextToken();
if (token.type() !== WebInspector.WikiParser.TokenType.ClosingBraces)
throw new Error("Two closing braces expected; found " + token.value());
return section;
},
/**
* @return {!Object}
* @return {!WebInspector.WikiParser.Field}
*/
_parseField: function()
{
var obj = {};
var field = new WebInspector.WikiParser.Field();
field.name = this._parseFieldName();
var token = this._tokenizer.peekToken();
switch (token.type()) {
case WebInspector.WikiParser.TokenType.OpeningBraces:
field.value = this._parseArray();
break;
case WebInspector.WikiParser.TokenType.LineEnd:
this._tokenizer.nextToken();
break;
case WebInspector.WikiParser.TokenType.ClosingBraces:
return field;
default:
if (field.name.toUpperCase() === "CODE")
field.value = this._parseExampleCode();
else
field.value = this._parseMarkupText();
}
return field;
},
/**
* @return {!Array.<!WebInspector.WikiParser.Section>}
*/
_parseArray: function()
{
var array = [];
while (this._tokenizer.peekToken().type() === WebInspector.WikiParser.TokenType.OpeningBraces)
array.push(this._parseSection());
if (this._tokenizer.peekToken().type() === WebInspector.WikiParser.TokenType.VerticalLine)
this._tokenizer.nextToken();
return array;
},
/**
* @return {string}
*/
_parseSectionTitle: function()
{
var title = "";
var propertyName = "";
var propertyValue = "";
var states = WebInspector.WikiParser.State;
var state = states.FirstOpen;
while (this._position < this._wikiMarkupText.length) {
var skipIncrement = false;
switch (state) {
case states.FirstOpen:
if (this._wikiMarkupText[this._position] === "{")
state = states.SecondOpen;
else
state = states.Error;
break;
case states.SecondOpen:
if (this._wikiMarkupText[this._position] === "{")
state = states.Title;
else
state = states.Error;
break;
case states.Title:
if (this._wikiMarkupText[this._position] === "|") {
title = this._deleteTrailingSpaces(title);
if (title !== "")
obj[title] = {};
state = states.PropertyName;
} else if (this._wikiMarkupText[this._position] === "}") {
title = this._deleteTrailingSpaces(title);
if (title !== "")
obj[title] = {};
state = states.FirstClose;
} else {
title += (this._wikiMarkupText[this._position] === "\n" ? "" : this._wikiMarkupText[this._position]);
}
while (this._tokenizer.hasMoreTokens()) {
var token = this._tokenizer.peekToken();
switch (token.type()) {
case WebInspector.WikiParser.TokenType.ClosingBraces:
return title;
case WebInspector.WikiParser.TokenType.VerticalLine:
this._tokenizer.nextToken();
return title;
case WebInspector.WikiParser.TokenType.Text:
title += this._tokenizer.nextToken().value();
break;
case states.PropertyName:
if (this._wikiMarkupText[this._position] === "=") {
state = states.PropertyValue;
this._deleteTrailingSpaces(propertyName);
if (propertyName !== "")
obj[title][propertyName] = [];
} else {
if (this._wikiMarkupText[this._position] === "}") {
propertyName = this._deleteTrailingSpaces(propertyName);
obj[title] = propertyName;
state = states.FirstClose;
} else {
propertyName += this._wikiMarkupText[this._position];
}
}
default:
throw new Error("Title could not be parsed. Unexpected token " + token.value());
}
}
return title;
},
/**
* @return {string}
*/
_parseFieldName: function()
{
var name = "";
while (this._tokenizer.hasMoreTokens()) {
var token = this._tokenizer.peekToken();
switch (token.type()) {
case WebInspector.WikiParser.TokenType.ClosingBraces:
return name;
case WebInspector.WikiParser.TokenType.EqualSign:
this._tokenizer.nextToken();
return name;
case WebInspector.WikiParser.TokenType.VerticalLine:
case WebInspector.WikiParser.TokenType.Text:
name += this._tokenizer.nextToken().value();
break;
case states.PropertyValue:
if (this._wikiMarkupText[this._position] === "{" && this._wikiMarkupText[this._position + 1] === "{") {
propertyValue = this._parseField();
obj[title][propertyName].push(propertyValue);
propertyValue = "";
skipIncrement = true;
} else if (this._wikiMarkupText[this._position] === "|") {
propertyValue = this._deleteTrailingSpaces(propertyValue);
if (propertyValue !== "")
obj[title][propertyName] = propertyValue;
state = states.PropertyName;
if (Array.isArray(obj[title][propertyName]) && obj[title][propertyName].length === 1) {
var newObj = obj[title][propertyName][0];
obj[title][propertyName] = newObj;
}
propertyName = "";
propertyValue = "";
} else if (this._position + 1 < this._wikiMarkupText.length && this._wikiMarkupText[this._position] === "}" && this._wikiMarkupText[this._position + 1] === "}") {
propertyValue = this._deleteTrailingSpaces(propertyValue);
if (propertyValue !== "")
obj[title][propertyName].push(propertyValue);
if (Array.isArray(obj[title][propertyName]) && obj[title][propertyName].length === 1) {
var newObj = obj[title][propertyName][0];
obj[title][propertyName] = newObj;
}
propertyValue = "";
state = states.FirstClose;
} else {
propertyValue = this._parseValue();
skipIncrement = true;
}
default:
throw new Error("Name could not be parsed. Unexpected token " + token.value());
}
}
return name;
},
/**
* @return {!WebInspector.WikiParser.Block}
*/
_parseExampleCode: function()
{
var code = "";
/**
* @return {!WebInspector.WikiParser.Block}
*/
function wrapIntoArticleElement()
{
var plainText = new WebInspector.WikiParser.PlainText(code);
var block = new WebInspector.WikiParser.Block([plainText])
var articleElement = new WebInspector.WikiParser.Block([block]);
return articleElement;
}
while (this._tokenizer.hasMoreTokens()) {
var token = this._tokenizer.peekToken();
switch (token.type()) {
case WebInspector.WikiParser.TokenType.ClosingBraces:
return wrapIntoArticleElement();
case WebInspector.WikiParser.TokenType.VerticalLine:
this._tokenizer.nextToken();
return wrapIntoArticleElement();
case WebInspector.WikiParser.TokenType.Exclamation:
this._tokenizer.nextToken();
code += "|";
break;
case states.FirstClose:
if (this._wikiMarkupText[this._position] === "}")
state = states.SecondClose;
else
state = states.Error;
case WebInspector.WikiParser.TokenType.EqualSignInBraces:
this._tokenizer.nextToken();
code += "=";
break;
case states.SecondClose:
while (this._position < this._wikiMarkupText.length && this._wikiMarkupText[this._position] === "\n")
this._position++;
return obj;
case states.Error:
this._position = this._wikiMarkupText.length;
return {};
default:
this._tokenizer.nextToken();
code += token.value();
}
if (!skipIncrement)
this._position++;
}
return obj;
return wrapIntoArticleElement();
},
/**
* @param {string} str
* @return {?WebInspector.WikiParser.Block}
*/
parseString: function(str)
_parseMarkupText: function()
{
this._tokenizer = new WebInspector.WikiParser.Tokenizer(str);
var children = [];
var blockChildren = [];
var text = "";
......@@ -380,7 +461,7 @@ WebInspector.WikiParser.prototype = {
var currentText = self._deleteTrailingSpaces(text);
if (!currentText.length)
return;
var simpleText = new WebInspector.WikiParser.PlainText(currentText, false);
var simpleText = new WebInspector.WikiParser.PlainText(currentText);
blockChildren.push(simpleText);
text = "";
}
......@@ -388,49 +469,75 @@ WebInspector.WikiParser.prototype = {
function processBlock()
{
if (blockChildren.length) {
children.push(new WebInspector.WikiParser.Block(blockChildren, false));
children.push(new WebInspector.WikiParser.Block(blockChildren));
blockChildren = [];
}
}
while (this._tokenizer._hasMoreTokens()) {
var token = this._tokenizer._nextToken();
while (this._tokenizer.hasMoreTokens()) {
var token = this._tokenizer.peekToken();
switch (token.type()) {
case WebInspector.WikiParser.TokenType.VerticalLine:
case WebInspector.WikiParser.TokenType.ClosingBraces:
if (token.type() === WebInspector.WikiParser.TokenType.VerticalLine)
this._tokenizer.nextToken();
processSimpleText();
processBlock();
return new WebInspector.WikiParser.Block(children);
case WebInspector.WikiParser.TokenType.TripleQuotes:
this._tokenizer.nextToken();
processSimpleText();
var highlightText = this._parseHighlight();
blockChildren.push(highlightText)
break;
case WebInspector.WikiParser.TokenType.OpeningBrackets:
this._tokenizer.nextToken();
processSimpleText();
var link = this._parseLink();
blockChildren.push(link);
break;
case WebInspector.WikiParser.TokenType.OpeningCodeTag:
this._tokenizer.nextToken();
processSimpleText();
var code = this._parseCode();
blockChildren.push(code);
break;
case WebInspector.WikiParser.TokenType.Bullet:
this._tokenizer.nextToken();
processSimpleText();
processBlock();
var bulletText = this._parseBullet();
children.push(bulletText);
break;
case WebInspector.WikiParser.TokenType.CodeBlock:
this._tokenizer.nextToken();
processSimpleText();
processBlock();
var code = new WebInspector.WikiParser.CodeBlock(token.value());
var code = new WebInspector.WikiParser.CodeBlock(this._trimLeadingNewLines(token.value()));
children.push(code);
break;
case WebInspector.WikiParser.TokenType.LineEnd:
this._tokenizer.nextToken();
processSimpleText();
processBlock();
break;
case WebInspector.WikiParser.TokenType.VerticalLine:
case WebInspector.WikiParser.TokenType.EqualSignInBraces:
this._tokenizer.nextToken();
text += "=";
break;
case WebInspector.WikiParser.TokenType.Exclamation:
this._tokenizer.nextToken();
text += "|";
break;
case WebInspector.WikiParser.TokenType.ClosingBrackets:
case WebInspector.WikiParser.TokenType.Text:
case WebInspector.WikiParser.TokenType.EqualSign:
case WebInspector.WikiParser.TokenType.Table:
this._tokenizer.nextToken();
text += token.value();
break;
default:
this._tokenizer.nextToken();
return null;
}
}
......@@ -438,7 +545,7 @@ WebInspector.WikiParser.prototype = {
processSimpleText();
processBlock();
return new WebInspector.WikiParser.Block(children, false);
return new WebInspector.WikiParser.Block(children);
},
/**
......@@ -448,12 +555,13 @@ WebInspector.WikiParser.prototype = {
{
var url = "";
var children = [];
while (this._tokenizer._hasMoreTokens()) {
var token = this._tokenizer._nextToken();
while (this._tokenizer.hasMoreTokens()) {
var token = this._tokenizer.nextToken();
switch (token.type()) {
case WebInspector.WikiParser.TokenType.ClosingBrackets:
return new WebInspector.WikiParser.Link(url, children);
case WebInspector.WikiParser.TokenType.VerticalLine:
case WebInspector.WikiParser.TokenType.Exclamation:
children.push(this._parseLinkName());
return new WebInspector.WikiParser.Link(url, children);
default:
......@@ -470,16 +578,30 @@ WebInspector.WikiParser.prototype = {
_parseLinkName: function()
{
var children = [];
while (this._tokenizer._hasMoreTokens()) {
var token = this._tokenizer._nextToken();
var text = "";
var self = this;
function processSimpleText()
{
text = self._deleteTrailingSpaces(text);
if (!text.length)
return;
var simpleText = new WebInspector.WikiParser.PlainText(text);
children.push(simpleText);
text = "";
}
while (this._tokenizer.hasMoreTokens()) {
var token = this._tokenizer.nextToken();
switch (token.type()) {
case WebInspector.WikiParser.TokenType.ClosingBrackets:
processSimpleText();
return new WebInspector.WikiParser.Inline(WebInspector.WikiParser.ArticleElement.Type.Inline, children);
case WebInspector.WikiParser.TokenType.OpeningCodeTag:
processSimpleText();
children.push(this._parseCode());
break;
default:
children.push(new WebInspector.WikiParser.PlainText(token.value(), false));
text += token.value();
break;
}
}
......@@ -494,13 +616,13 @@ WebInspector.WikiParser.prototype = {
{
var children = [];
var text = "";
while (this._tokenizer._hasMoreTokens()) {
var token = this._tokenizer._nextToken();
while (this._tokenizer.hasMoreTokens()) {
var token = this._tokenizer.nextToken();
switch (token.type()) {
case WebInspector.WikiParser.TokenType.ClosingCodeTag:
text = this._deleteTrailingSpaces(text);
if (text.length) {
var simpleText = new WebInspector.WikiParser.PlainText(text, false);
var simpleText = new WebInspector.WikiParser.PlainText(text);
children.push(simpleText);
text = "";
}
......@@ -517,7 +639,7 @@ WebInspector.WikiParser.prototype = {
text = this._deleteTrailingSpaces(text);
if (text.length)
children.push(new WebInspector.WikiParser.PlainText(text, false));
children.push(new WebInspector.WikiParser.PlainText(text));
return new WebInspector.WikiParser.Inline(WebInspector.WikiParser.ArticleElement.Type.Code, children);
},
......@@ -528,8 +650,8 @@ WebInspector.WikiParser.prototype = {
_parseBullet: function()
{
var children = [];
while (this._tokenizer._hasMoreTokens()) {
var token = this._tokenizer._nextToken()
while (this._tokenizer.hasMoreTokens()) {
var token = this._tokenizer.nextToken()
switch (token.type()) {
case WebInspector.WikiParser.TokenType.OpeningBrackets:
children.push(this._parseLink());
......@@ -542,7 +664,7 @@ WebInspector.WikiParser.prototype = {
default:
var text = this._deleteTrailingSpaces(token.value());
if (text.length) {
var simpleText = new WebInspector.WikiParser.PlainText(text, false);
var simpleText = new WebInspector.WikiParser.PlainText(text);
children.push(simpleText);
text = "";
}
......@@ -558,8 +680,8 @@ WebInspector.WikiParser.prototype = {
_parseHighlight: function()
{
var text = "";
while (this._tokenizer._hasMoreTokens()) {
var token = this._tokenizer._nextToken()
while (this._tokenizer.hasMoreTokens()) {
var token = this._tokenizer.nextToken()
switch (token.type()) {
case WebInspector.WikiParser.TokenType.TripleQuotes:
text = this._deleteTrailingSpaces(text);
......@@ -578,47 +700,18 @@ WebInspector.WikiParser.prototype = {
_deleteTrailingSpaces: function(str)
{
return str.replace(/[\n\r]*$/gm, "");
}
}
WebInspector.WikiParser.oneOpeningBracket = /^\n* \[[^\[]/;
WebInspector.WikiParser.twoOpeningBrackets = /^\n* \[\[/;
WebInspector.WikiParser.oneClosingBracket = /^\n*\][^\]] /;
WebInspector.WikiParser.twoClosingBrackets = /^\n*\]\]/;
WebInspector.WikiParser.tripleQuotes = /^\n*'''/;
WebInspector.WikiParser.openingCodeTag = /^<\s*code\s*>/;
WebInspector.WikiParser.closingCodeTag = /^<\s*\/\s*code\s*>/;
WebInspector.WikiParser.closingBullet = /^\*/;
WebInspector.WikiParser.lineEnd = /^\n/;
WebInspector.WikiParser.verticalLine = /^\|/;
WebInspector.WikiParser.newLineWithSpace = /^\n /;
WebInspector.WikiParser.newLineWithoutSpace = /\n[^ ]/;
},
/**
* @constructor
* @param {!RegExp} regex
* @param {!WebInspector.WikiParser.TokenType} type
*/
WebInspector.WikiParser.TokenDescriptor = function(regex, type)
{
this.regex = regex;
this.type = type;
/**
* @param {string} str
* @return {string}
*/
_trimLeadingNewLines: function(str)
{
return str.replace(/^\n*/, "");
}
}
WebInspector.WikiParser._tokenDescriptors = [
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.newLineWithSpace, WebInspector.WikiParser.TokenType.CodeBlock),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.tripleQuotes, WebInspector.WikiParser.TokenType.TripleQuotes),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.oneOpeningBracket, WebInspector.WikiParser.TokenType.OpeningBrackets),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.twoOpeningBrackets, WebInspector.WikiParser.TokenType.OpeningBrackets),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.oneClosingBracket, WebInspector.WikiParser.TokenType.ClosingBrackets),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.twoClosingBrackets, WebInspector.WikiParser.TokenType.ClosingBrackets),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.openingCodeTag, WebInspector.WikiParser.TokenType.OpeningCodeTag),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingCodeTag, WebInspector.WikiParser.TokenType.ClosingCodeTag),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingBullet, WebInspector.WikiParser.TokenType.Bullet),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.verticalLine, WebInspector.WikiParser.TokenType.VerticalLine),
new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.lineEnd, WebInspector.WikiParser.TokenType.LineEnd)
];
/**
* @constructor
* @param {!WebInspector.WikiParser.ArticleElement.Type} type
......@@ -654,20 +747,20 @@ WebInspector.WikiParser.ArticleElement.Type = {
* @constructor
* @extends {WebInspector.WikiParser.ArticleElement}
* @param {string} text
* @param {boolean} highlight
* @param {boolean=} highlight
*/
WebInspector.WikiParser.PlainText = function(text, highlight)
{
WebInspector.WikiParser.ArticleElement.call(this, WebInspector.WikiParser.ArticleElement.Type.PlainText);
this._text = text;
this._isHighlighted = highlight;
this._text = text.unescapeHTML();
this._isHighlighted = highlight || false;
}
WebInspector.WikiParser.PlainText.prototype = {
/**
* @return {string}
*/
text : function()
text: function()
{
return this._text;
},
......@@ -687,13 +780,13 @@ WebInspector.WikiParser.PlainText.prototype = {
* @constructor
* @extends {WebInspector.WikiParser.ArticleElement}
* @param {!Array.<!WebInspector.WikiParser.ArticleElement>} children
* @param {boolean} hasBullet
* @param {boolean=} hasBullet
*/
WebInspector.WikiParser.Block = function(children, hasBullet)
{
WebInspector.WikiParser.ArticleElement.call(this, WebInspector.WikiParser.ArticleElement.Type.Block);
this._children = children;
this._hasBullet = hasBullet
this._hasBullet = hasBullet || false;
}
WebInspector.WikiParser.Block.prototype = {
......@@ -705,6 +798,14 @@ WebInspector.WikiParser.Block.prototype = {
return this._children;
},
/**
* @return {boolean}
*/
hasChildren: function()
{
return !!this._children && !!this._children.length;
},
/**
* @return {boolean}
*/
......@@ -724,7 +825,7 @@ WebInspector.WikiParser.Block.prototype = {
WebInspector.WikiParser.CodeBlock = function(text)
{
WebInspector.WikiParser.ArticleElement.call(this, WebInspector.WikiParser.ArticleElement.Type.CodeBlock);
this._code = text;
this._code = text.unescapeHTML();
}
WebInspector.WikiParser.CodeBlock.prototype = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment