Run Prettier

This commit is contained in:
Frank Li 2017-07-10 16:38:35 -07:00
parent a7b5148e06
commit fbae29b0ff
29 changed files with 1311 additions and 987 deletions

View file

@ -7,9 +7,9 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
const React = require('react');
const Prism = require('./Prism.js');
const Header = require('./Header.js');
const React = require("react");
const Prism = require("./Prism.js");
const Header = require("./Header.js");
/**
* Block-Level Grammar
@ -29,23 +29,36 @@ const block = {
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
table: noop,
paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
text: /^[^\n]+/,
text: /^[^\n]+/
};
block.bullet = /(?:[*+-]|\d+\.)/;
block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
block.item = replace(block.item, 'gm')(/bull/g, block.bullet)();
block.item = replace(block.item, "gm")(/bull/g, block.bullet)();
block.list = replace(block.list)(/bull/g, block.bullet)('hr', /\n+(?=(?: *[-*_]){3,} *(?:\n+|$))/)();
block.list = replace(block.list)(/bull/g, block.bullet)(
"hr",
/\n+(?=(?: *[-*_]){3,} *(?:\n+|$))/
)();
block._tag = '(?!(?:'
+ 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
+ '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
+ '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|@)\\b';
block._tag =
"(?!(?:" +
"a|em|strong|small|s|cite|q|dfn|abbr|data|time|code" +
"|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo" +
"|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|@)\\b";
block.html = replace(block.html)('comment', /<!--[\s\S]*?-->/)('closed', /<(tag)[\s\S]+?<\/\1>/)('closing', /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)(/tag/g, block._tag)();
block.html = replace(block.html)("comment", /<!--[\s\S]*?-->/)(
"closed",
/<(tag)[\s\S]+?<\/\1>/
)("closing", /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)(/tag/g, block._tag)();
block.paragraph = replace(block.paragraph)('hr', block.hr)('heading', block.heading)('lheading', block.lheading)('blockquote', block.blockquote)('tag', '<' + block._tag)('def', block.def)();
block.paragraph = replace(block.paragraph)("hr", block.hr)(
"heading",
block.heading
)("lheading", block.lheading)("blockquote", block.blockquote)(
"tag",
"<" + block._tag
)("def", block.def)();
/**
* Normal Block Grammar
@ -59,10 +72,13 @@ block.normal = merge({}, block);
block.gfm = merge({}, block.normal, {
fences: /^ *(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n+|$)/,
paragraph: /^/,
paragraph: /^/
});
block.gfm.paragraph = replace(block.paragraph)('(?!', '(?!' + block.gfm.fences.source.replace('\\1', '\\2') + '|')();
block.gfm.paragraph = replace(block.paragraph)(
"(?!",
"(?!" + block.gfm.fences.source.replace("\\1", "\\2") + "|"
)();
/**
* GFM + Tables Block Grammar
@ -70,7 +86,7 @@ block.gfm.paragraph = replace(block.paragraph)('(?!', '(?!' + block.gfm.fences.s
block.tables = merge({}, block.gfm, {
nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,
table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/,
table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/
});
/**
@ -113,10 +129,10 @@ Lexer.lex = function(src, options) {
Lexer.prototype.lex = function(src) {
src = src
.replace(/\r\n|\r/g, '\n')
.replace(/\t/g, ' ')
.replace(/\u00a0/g, ' ')
.replace(/\u2424/g, '\n');
.replace(/\r\n|\r/g, "\n")
.replace(/\t/g, " ")
.replace(/\u00a0/g, " ")
.replace(/\u2424/g, "\n");
return this.token(src, true);
};
@ -126,7 +142,7 @@ Lexer.prototype.lex = function(src) {
*/
Lexer.prototype.token = function(_src, top) {
let src = _src.replace(/^ +$/gm, '');
let src = _src.replace(/^ +$/gm, "");
let next;
let loose;
let cap;
@ -139,46 +155,44 @@ Lexer.prototype.token = function(_src, top) {
while (src) {
// newline
if (cap = this.rules.newline.exec(src)) {
if ((cap = this.rules.newline.exec(src))) {
src = src.substring(cap[0].length);
if (cap[0].length > 1) {
this.tokens.push({
type: 'space',
type: "space"
});
}
}
// code
if (cap = this.rules.code.exec(src)) {
if ((cap = this.rules.code.exec(src))) {
src = src.substring(cap[0].length);
cap = cap[0].replace(/^ {4}/gm, '');
cap = cap[0].replace(/^ {4}/gm, "");
this.tokens.push({
type: 'code',
text: !this.options.pedantic
? cap.replace(/\n+$/, '')
: cap,
type: "code",
text: !this.options.pedantic ? cap.replace(/\n+$/, "") : cap
});
continue;
}
// fences (gfm)
if (cap = this.rules.fences.exec(src)) {
if ((cap = this.rules.fences.exec(src))) {
src = src.substring(cap[0].length);
this.tokens.push({
type: 'code',
type: "code",
lang: cap[2],
text: cap[3],
text: cap[3]
});
continue;
}
// heading
if (cap = this.rules.heading.exec(src)) {
if ((cap = this.rules.heading.exec(src))) {
src = src.substring(cap[0].length);
this.tokens.push({
type: 'heading',
type: "heading",
depth: cap[1].length,
text: cap[2],
text: cap[2]
});
continue;
}
@ -188,19 +202,19 @@ Lexer.prototype.token = function(_src, top) {
src = src.substring(cap[0].length);
item = {
type: 'table',
header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
cells: cap[3].replace(/\n$/, '').split('\n'),
type: "table",
header: cap[1].replace(/^ *| *\| *$/g, "").split(/ *\| */),
align: cap[2].replace(/^ *|\| *$/g, "").split(/ *\| */),
cells: cap[3].replace(/\n$/, "").split("\n")
};
for (i = 0; i < item.align.length; i++) {
if (/^ *-+: *$/.test(item.align[i])) {
item.align[i] = 'right';
item.align[i] = "right";
} else if (/^ *:-+: *$/.test(item.align[i])) {
item.align[i] = 'center';
item.align[i] = "center";
} else if (/^ *:-+ *$/.test(item.align[i])) {
item.align[i] = 'left';
item.align[i] = "left";
} else {
item.align[i] = null;
}
@ -216,34 +230,34 @@ Lexer.prototype.token = function(_src, top) {
}
// lheading
if (cap = this.rules.lheading.exec(src)) {
if ((cap = this.rules.lheading.exec(src))) {
src = src.substring(cap[0].length);
this.tokens.push({
type: 'heading',
depth: cap[2] === '=' ? 1 : 2,
text: cap[1],
type: "heading",
depth: cap[2] === "=" ? 1 : 2,
text: cap[1]
});
continue;
}
// hr
if (cap = this.rules.hr.exec(src)) {
if ((cap = this.rules.hr.exec(src))) {
src = src.substring(cap[0].length);
this.tokens.push({
type: 'hr',
type: "hr"
});
continue;
}
// blockquote
if (cap = this.rules.blockquote.exec(src)) {
if ((cap = this.rules.blockquote.exec(src))) {
src = src.substring(cap[0].length);
this.tokens.push({
type: 'blockquote_start',
type: "blockquote_start"
});
cap = cap[0].replace(/^ *> ?/gm, '');
cap = cap[0].replace(/^ *> ?/gm, "");
// Pass `top` to keep the current
// "toplevel" state. This is exactly
@ -251,20 +265,20 @@ Lexer.prototype.token = function(_src, top) {
this.token(cap, top);
this.tokens.push({
type: 'blockquote_end',
type: "blockquote_end"
});
continue;
}
// list
if (cap = this.rules.list.exec(src)) {
if ((cap = this.rules.list.exec(src))) {
src = src.substring(cap[0].length);
bull = cap[2];
this.tokens.push({
type: 'list_start',
ordered: bull.length > 1,
type: "list_start",
ordered: bull.length > 1
});
// Get each top-level item.
@ -280,15 +294,16 @@ Lexer.prototype.token = function(_src, top) {
// Remove the list item's bullet
// so it is seen as the next token.
space = item.length;
item = item.replace(/^ *([*+-]|\d+\.) +/, '');
item = item.replace(/^ *([*+-]|\d+\.) +/, "");
// Outdent whatever the
// list item contains. Hacky.
if (~item.indexOf('\n ')) { // eslint-disable-line
if (~item.indexOf("\n ")) {
// eslint-disable-line
space -= item.length;
item = !this.options.pedantic
? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
: item.replace(/^ {1,4}/gm, '');
? item.replace(new RegExp("^ {1," + space + "}", "gm"), "")
: item.replace(/^ {1,4}/gm, "");
}
// Determine whether the next list item belongs here.
@ -296,7 +311,7 @@ Lexer.prototype.token = function(_src, top) {
if (this.options.smartLists && i !== l - 1) {
b = block.bullet.exec(cap[i + 1])[0];
if (bull !== b && !(bull.length > 1 && b.length > 1)) {
src = cap.slice(i + 1).join('\n') + src;
src = cap.slice(i + 1).join("\n") + src;
i = l - 1;
}
}
@ -306,40 +321,38 @@ Lexer.prototype.token = function(_src, top) {
// for discount behavior.
loose = next || /\n\n(?!\s*$)/.test(item);
if (i !== l - 1) {
next = item[item.length - 1] === '\n';
if (!loose) {loose = next;}
next = item[item.length - 1] === "\n";
if (!loose) {
loose = next;
}
}
this.tokens.push({
type: loose
? 'loose_item_start'
: 'list_item_start',
type: loose ? "loose_item_start" : "list_item_start"
});
// Recurse.
this.token(item, false);
this.tokens.push({
type: 'list_item_end',
type: "list_item_end"
});
}
this.tokens.push({
type: 'list_end',
type: "list_end"
});
continue;
}
// html
if (cap = this.rules.html.exec(src)) {
if ((cap = this.rules.html.exec(src))) {
src = src.substring(cap[0].length);
this.tokens.push({
type: this.options.sanitize
? 'paragraph'
: 'html',
pre: cap[1] === 'pre' || cap[1] === 'script',
text: cap[0],
type: this.options.sanitize ? "paragraph" : "html",
pre: cap[1] === "pre" || cap[1] === "script",
text: cap[0]
});
continue;
}
@ -349,7 +362,7 @@ Lexer.prototype.token = function(_src, top) {
src = src.substring(cap[0].length);
this.tokens.links[cap[1].toLowerCase()] = {
href: cap[2],
title: cap[3],
title: cap[3]
};
continue;
}
@ -359,19 +372,19 @@ Lexer.prototype.token = function(_src, top) {
src = src.substring(cap[0].length);
item = {
type: 'table',
header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n'),
type: "table",
header: cap[1].replace(/^ *| *\| *$/g, "").split(/ *\| */),
align: cap[2].replace(/^ *|\| *$/g, "").split(/ *\| */),
cells: cap[3].replace(/(?: *\| *)?\n$/, "").split("\n")
};
for (i = 0; i < item.align.length; i++) {
if (/^ *-+: *$/.test(item.align[i])) {
item.align[i] = 'right';
item.align[i] = "right";
} else if (/^ *:-+: *$/.test(item.align[i])) {
item.align[i] = 'center';
item.align[i] = "center";
} else if (/^ *:-+ *$/.test(item.align[i])) {
item.align[i] = 'left';
item.align[i] = "left";
} else {
item.align[i] = null;
}
@ -379,7 +392,7 @@ Lexer.prototype.token = function(_src, top) {
for (i = 0; i < item.cells.length; i++) {
item.cells[i] = item.cells[i]
.replace(/^ *\| *| *\| *$/g, '')
.replace(/^ *\| *| *\| *$/g, "")
.split(/ *\| */);
}
@ -392,28 +405,25 @@ Lexer.prototype.token = function(_src, top) {
if (top && (cap = this.rules.paragraph.exec(src))) {
src = src.substring(cap[0].length);
this.tokens.push({
type: 'paragraph',
text: cap[1][cap[1].length - 1] === '\n'
? cap[1].slice(0, -1)
: cap[1],
type: "paragraph",
text: cap[1][cap[1].length - 1] === "\n" ? cap[1].slice(0, -1) : cap[1]
});
continue;
}
// text
if (cap = this.rules.text.exec(src)) {
if ((cap = this.rules.text.exec(src))) {
// Top-level should never reach here.
src = src.substring(cap[0].length);
this.tokens.push({
type: 'text',
text: cap[0],
type: "text",
text: cap[0]
});
continue;
}
if (src) {
throw new
Error('Infinite loop on byte: ' + src.charCodeAt(0));
throw new Error("Infinite loop on byte: " + src.charCodeAt(0));
}
}
@ -437,15 +447,18 @@ const inline = {
code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
br: /^ {2,}\n(?!\s*$)/,
del: noop,
text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/,
text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
};
inline._inside = /(?:\[[^\]]*\]|[^\]]|\](?=[^\[]*\]))*/;
inline._href = /\s*<?([^\s]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
inline.link = replace(inline.link)('inside', inline._inside)('href', inline._href)();
inline.link = replace(inline.link)("inside", inline._inside)(
"href",
inline._href
)();
inline.reflink = replace(inline.reflink)('inside', inline._inside)();
inline.reflink = replace(inline.reflink)("inside", inline._inside)();
/**
* Normal Inline Grammar
@ -459,7 +472,7 @@ inline.normal = merge({}, inline);
inline.pedantic = merge({}, inline.normal, {
strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,
em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/
});
/**
@ -467,10 +480,10 @@ inline.pedantic = merge({}, inline.normal, {
*/
inline.gfm = merge({}, inline.normal, {
escape: replace(inline.escape)('])', '~|])')(),
escape: replace(inline.escape)("])", "~|])")(),
url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
del: /^~~(?=\S)([\s\S]*?\S)~~/,
text: replace(inline.text)(']|', '~]|')('|', '|https?://|')(),
text: replace(inline.text)("]|", "~]|")("|", "|https?://|")()
});
/**
@ -478,8 +491,8 @@ inline.gfm = merge({}, inline.normal, {
*/
inline.breaks = merge({}, inline.gfm, {
br: replace(inline.br)('{2,}', '*')(),
text: replace(inline.gfm.text)('{2,}', '*')(),
br: replace(inline.br)("{2,}", "*")(),
text: replace(inline.gfm.text)("{2,}", "*")()
});
/**
@ -492,8 +505,7 @@ function InlineLexer(links, options) {
this.rules = inline.normal;
if (!this.links) {
throw new
Error('Tokens array requires a `links` property.');
throw new Error("Tokens array requires a `links` property.");
}
if (this.options.gfm) {
@ -535,39 +547,37 @@ InlineLexer.prototype.output = function(src) {
while (src) {
// escape
if (cap = this.rules.escape.exec(src)) {
if ((cap = this.rules.escape.exec(src))) {
src = src.substring(cap[0].length);
out.push(cap[1]);
continue;
}
// autolink
if (cap = this.rules.autolink.exec(src)) {
if ((cap = this.rules.autolink.exec(src))) {
src = src.substring(cap[0].length);
if (cap[2] === '@') {
text = cap[1][6] === ':'
? cap[1].substring(7)
: cap[1];
href = 'mailto:' + text;
if (cap[2] === "@") {
text = cap[1][6] === ":" ? cap[1].substring(7) : cap[1];
href = "mailto:" + text;
} else {
text = cap[1];
href = text;
}
out.push(React.DOM.a({href: this.sanitizeUrl(href)}, text));
out.push(React.DOM.a({ href: this.sanitizeUrl(href) }, text));
continue;
}
// url (gfm)
if (cap = this.rules.url.exec(src)) {
if ((cap = this.rules.url.exec(src))) {
src = src.substring(cap[0].length);
text = cap[1];
href = text;
out.push(React.DOM.a({href: this.sanitizeUrl(href)}, text));
out.push(React.DOM.a({ href: this.sanitizeUrl(href) }, text));
continue;
}
// tag
if (cap = this.rules.tag.exec(src)) {
if ((cap = this.rules.tag.exec(src))) {
src = src.substring(cap[0].length);
// TODO(alpert): Don't escape if sanitize is false
out.push(cap[0]);
@ -575,20 +585,24 @@ InlineLexer.prototype.output = function(src) {
}
// link
if (cap = this.rules.link.exec(src)) {
if ((cap = this.rules.link.exec(src))) {
src = src.substring(cap[0].length);
out.push(this.outputLink(cap, {
href: cap[2],
title: cap[3],
}));
out.push(
this.outputLink(cap, {
href: cap[2],
title: cap[3]
})
);
continue;
}
// reflink, nolink
if ((cap = this.rules.reflink.exec(src))
|| (cap = this.rules.nolink.exec(src))) {
if (
(cap = this.rules.reflink.exec(src)) ||
(cap = this.rules.nolink.exec(src))
) {
src = src.substring(cap[0].length);
link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
link = (cap[2] || cap[1]).replace(/\s+/g, " ");
link = this.links[link.toLowerCase()];
if (!link || !link.href) {
out.push.apply(out, this.output(cap[0][0]));
@ -600,50 +614,49 @@ InlineLexer.prototype.output = function(src) {
}
// strong
if (cap = this.rules.strong.exec(src)) {
if ((cap = this.rules.strong.exec(src))) {
src = src.substring(cap[0].length);
out.push(React.DOM.strong(null, this.output(cap[2] || cap[1])));
continue;
}
// em
if (cap = this.rules.em.exec(src)) {
if ((cap = this.rules.em.exec(src))) {
src = src.substring(cap[0].length);
out.push(React.DOM.em(null, this.output(cap[2] || cap[1])));
continue;
}
// code
if (cap = this.rules.code.exec(src)) {
if ((cap = this.rules.code.exec(src))) {
src = src.substring(cap[0].length);
out.push(React.DOM.code(null, cap[2]));
continue;
}
// br
if (cap = this.rules.br.exec(src)) {
if ((cap = this.rules.br.exec(src))) {
src = src.substring(cap[0].length);
out.push(React.DOM.br(null, null));
continue;
}
// del (gfm)
if (cap = this.rules.del.exec(src)) {
if ((cap = this.rules.del.exec(src))) {
src = src.substring(cap[0].length);
out.push(React.DOM.del(null, this.output(cap[1])));
continue;
}
// text
if (cap = this.rules.text.exec(src)) {
if ((cap = this.rules.text.exec(src))) {
src = src.substring(cap[0].length);
out.push(this.smartypants(cap[0]));
continue;
}
if (src) {
throw new
Error('Infinite loop on byte: ' + src.charCodeAt(0));
throw new Error("Infinite loop on byte: " + src.charCodeAt(0));
}
}
@ -658,13 +671,14 @@ InlineLexer.prototype.sanitizeUrl = function(url) {
if (this.options.sanitize) {
try {
const prot = decodeURIComponent(url)
.replace(/[^A-Za-z0-9:]/g, '')
.toLowerCase();
if (prot.indexOf('javascript:') === 0) { // eslint-disable-line
return '#';
.replace(/[^A-Za-z0-9:]/g, "")
.toLowerCase();
if (prot.indexOf("javascript:") === 0) {
// eslint-disable-line
return "#";
}
} catch (e) {
return '#';
return "#";
}
}
return url;
@ -675,22 +689,27 @@ InlineLexer.prototype.sanitizeUrl = function(url) {
*/
InlineLexer.prototype.outputLink = function(cap, link) {
if (cap[0][0] !== '!') {
if (cap[0][0] !== "!") {
const shouldOpenInNewWindow =
link.href.charAt(0) !== '/'
&& link.href.charAt(0) !== '#';
link.href.charAt(0) !== "/" && link.href.charAt(0) !== "#";
return React.DOM.a({
href: this.sanitizeUrl(link.href),
title: link.title,
target: shouldOpenInNewWindow ? '_blank' : '',
}, this.output(cap[1]));
return React.DOM.a(
{
href: this.sanitizeUrl(link.href),
title: link.title,
target: shouldOpenInNewWindow ? "_blank" : ""
},
this.output(cap[1])
);
} else {
return React.DOM.img({
src: this.sanitizeUrl(link.href),
alt: cap[1],
title: link.title,
}, null);
return React.DOM.img(
{
src: this.sanitizeUrl(link.href),
alt: cap[1],
title: link.title
},
null
);
}
};
@ -699,12 +718,14 @@ InlineLexer.prototype.outputLink = function(cap, link) {
*/
InlineLexer.prototype.smartypants = function(text) {
if (!this.options.smartypants) {return text;}
if (!this.options.smartypants) {
return text;
}
return text
.replace(/--/g, '\u2014')
.replace(/'([^']*)'/g, '\u2018$1\u2019')
.replace(/"([^"]*)"/g, '\u201C$1\u201D')
.replace(/\.{3}/g, '\u2026');
.replace(/--/g, "\u2014")
.replace(/'([^']*)'/g, "\u2018$1\u2019")
.replace(/"([^"]*)"/g, "\u201C$1\u201D")
.replace(/\.{3}/g, "\u2026");
};
/**
@ -747,7 +768,7 @@ Parser.prototype.parse = function(src) {
*/
Parser.prototype.next = function() {
return this.token = this.tokens.pop();
return (this.token = this.tokens.pop());
};
/**
@ -765,8 +786,8 @@ Parser.prototype.peek = function() {
Parser.prototype.parseText = function() {
let body = this.token.text;
while (this.peek().type === 'text') {
body += '\n' + this.next().text;
while (this.peek().type === "text") {
body += "\n" + this.next().text;
}
return this.inline.output(body);
@ -776,25 +797,30 @@ Parser.prototype.parseText = function() {
* Parse Current Token
*/
Parser.prototype.tok = function() { // eslint-disable-line
Parser.prototype.tok = function() {
// eslint-disable-line
switch (this.token.type) {
case 'space': {
case "space": {
return [];
}
case 'hr': {
case "hr": {
return React.DOM.hr(null, null);
}
case 'heading': {
case "heading": {
return (
<Header level={this.token.depth} toSlug={this.token.text}>
{this.inline.output(this.token.text)}
</Header>
);
}
case 'code': {
return <Prism>{this.token.text}</Prism>;
case "code": {
return (
<Prism>
{this.token.text}
</Prism>
);
}
case 'table': {
case "table": {
const table = [];
const body = [];
let row = [];
@ -806,12 +832,14 @@ Parser.prototype.tok = function() { // eslint-disable-line
// header
for (i = 0; i < this.token.header.length; i++) {
heading = this.inline.output(this.token.header[i]);
row.push(React.DOM.th(
this.token.align[i]
? {style: {textAlign: this.token.align[i]}}
: null,
heading
));
row.push(
React.DOM.th(
this.token.align[i]
? { style: { textAlign: this.token.align[i] } }
: null,
heading
)
);
}
table.push(React.DOM.thead(null, React.DOM.tr(null, row)));
@ -820,12 +848,14 @@ Parser.prototype.tok = function() { // eslint-disable-line
row = [];
cells = this.token.cells[i];
for (j = 0; j < cells.length; j++) {
row.push(React.DOM.td(
this.token.align[j]
? {style: {textAlign: this.token.align[j]}}
: null,
this.inline.output(cells[j])
));
row.push(
React.DOM.td(
this.token.align[j]
? { style: { textAlign: this.token.align[j] } }
: null,
this.inline.output(cells[j])
)
);
}
body.push(React.DOM.tr(null, row));
}
@ -833,58 +863,59 @@ Parser.prototype.tok = function() { // eslint-disable-line
return React.DOM.table(null, table);
}
case 'blockquote_start': {
case "blockquote_start": {
const body = [];
while (this.next().type !== 'blockquote_end') {
while (this.next().type !== "blockquote_end") {
body.push(this.tok());
}
return React.DOM.blockquote(null, body);
}
case 'list_start': {
const type = this.token.ordered ? 'ol' : 'ul';
case "list_start": {
const type = this.token.ordered ? "ol" : "ul";
const body = [];
while (this.next().type !== 'list_end') {
while (this.next().type !== "list_end") {
body.push(this.tok());
}
return React.DOM[type](null, body);
}
case 'list_item_start': {
case "list_item_start": {
const body = [];
while (this.next().type !== 'list_item_end') {
body.push(this.token.type === 'text'
? this.parseText()
: this.tok());
while (this.next().type !== "list_item_end") {
body.push(this.token.type === "text" ? this.parseText() : this.tok());
}
return React.DOM.li(null, body);
}
case 'loose_item_start': {
case "loose_item_start": {
const body = [];
while (this.next().type !== 'list_item_end') {
while (this.next().type !== "list_item_end") {
body.push(this.tok());
}
return React.DOM.li(null, body);
}
case 'html': {
case "html": {
return React.DOM.div({
dangerouslySetInnerHTML: {
__html: this.token.text,
},
__html: this.token.text
}
});
}
case 'paragraph': {
case "paragraph": {
return this.options.paragraphFn
? this.options.paragraphFn.call(null, this.inline.output(this.token.text))
? this.options.paragraphFn.call(
null,
this.inline.output(this.token.text)
)
: React.DOM.p(null, this.inline.output(this.token.text));
}
case 'text': {
case "text": {
return this.options.paragraphFn
? this.options.paragraphFn.call(null, this.parseText())
: React.DOM.p(null, this.parseText());
@ -898,11 +929,13 @@ Parser.prototype.tok = function() { // eslint-disable-line
function replace(regex, opt) {
regex = regex.source;
opt = opt || '';
opt = opt || "";
return function self(name, val) {
if (!name) {return new RegExp(regex, opt);}
if (!name) {
return new RegExp(regex, opt);
}
val = val.source || val;
val = val.replace(/(^|[^\[])\^/g, '$1');
val = val.replace(/(^|[^\[])\^/g, "$1");
regex = regex.replace(name, val);
return self;
};
@ -933,13 +966,15 @@ function merge(obj) {
*/
function marked(src, opt, callback) {
if (callback || typeof opt === 'function') {
if (callback || typeof opt === "function") {
if (!callback) {
callback = opt;
opt = null;
}
if (opt) {opt = merge({}, marked.defaults, opt);}
if (opt) {
opt = merge({}, marked.defaults, opt);
}
const highlight = opt.highlight;
let tokens;
@ -969,20 +1004,20 @@ function marked(src, opt, callback) {
opt.highlight = highlight;
return err
? callback(err)
: callback(null, out);
return err ? callback(err) : callback(null, out);
};
if (!highlight || highlight.length < 3) {
return done(true);
}
if (!pending) {return done();}
if (!pending) {
return done();
}
for (; i < tokens.length; i++) {
(function(token) {
if (token.type !== 'code') {
if (token.type !== "code") {
return --pending || done();
}
return highlight(token.text, token.lang, (err, code) => {
@ -1000,13 +1035,17 @@ function marked(src, opt, callback) {
return undefined;
}
try {
if (opt) {opt = merge({}, marked.defaults, opt);}
if (opt) {
opt = merge({}, marked.defaults, opt);
}
return Parser.parse(Lexer.lex(src, opt), opt);
} catch (e) {
e.message += '\nPlease report this to https://github.com/chjj/marked.';
e.message += "\nPlease report this to https://github.com/chjj/marked.";
if ((opt || marked.defaults).silent) {
return [React.DOM.p(null, 'An error occurred:'),
React.DOM.pre(null, e.message)];
return [
React.DOM.p(null, "An error occurred:"),
React.DOM.pre(null, e.message)
];
}
throw e;
}
@ -1016,8 +1055,7 @@ function marked(src, opt, callback) {
* Options
*/
marked.options =
marked.setOptions = function(opt) {
marked.options = marked.setOptions = function(opt) {
merge(marked.defaults, opt);
return marked;
};
@ -1031,9 +1069,9 @@ marked.defaults = {
smartLists: false,
silent: false,
highlight: null,
langPrefix: 'lang-',
langPrefix: "lang-",
smartypants: false,
paragraphFn: null,
paragraphFn: null
};
/**
@ -1053,7 +1091,11 @@ marked.parse = marked;
class Marked extends React.Component {
render() {
return <div>{marked(this.props.children, this.props)}</div>;
return (
<div>
{marked(this.props.children, this.props)}
</div>
);
}
}