mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 17:19:48 +01:00
@@ -3,6 +3,6 @@
|
||||
[{
|
||||
"name": "chjj-marked",
|
||||
"repositoryURL": "https://github.com/npmcomponent/chjj-marked",
|
||||
"version": "0.3.6",
|
||||
"version": "0.3.12",
|
||||
"license": "MIT"
|
||||
}]
|
||||
|
||||
@@ -16,19 +16,26 @@ var block = {
|
||||
newline: /^\n+/,
|
||||
code: /^( {4}[^\n]+\n*)+/,
|
||||
fences: noop,
|
||||
hr: /^( *[-*_]){3,} *(?:\n+|$)/,
|
||||
hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
|
||||
heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
|
||||
nptable: noop,
|
||||
lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
|
||||
blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,
|
||||
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
|
||||
list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
|
||||
html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
|
||||
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
|
||||
def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
|
||||
table: noop,
|
||||
paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
|
||||
lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
|
||||
paragraph: /^([^\n]+(?:\n?(?!hr|heading|lheading| {0,3}>|tag)[^\n]+)+)/,
|
||||
text: /^[^\n]+/
|
||||
};
|
||||
|
||||
block._label = /(?:\\[\[\]]|[^\[\]])+/;
|
||||
block._title = /(?:"(?:\\"|[^"]|"[^"\n]*")*"|'\n?(?:[^'\n]+\n?)*'|\([^()]*\))/;
|
||||
block.def = replace(block.def)
|
||||
('label', block._label)
|
||||
('title', block._title)
|
||||
();
|
||||
|
||||
block.bullet = /(?:[*+-]|\d+\.)/;
|
||||
block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
|
||||
block.item = replace(block.item, 'gm')
|
||||
@@ -37,23 +44,19 @@ block.item = replace(block.item, 'gm')
|
||||
|
||||
block.list = replace(block.list)
|
||||
(/bull/g, block.bullet)
|
||||
('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))')
|
||||
('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))')
|
||||
('def', '\\n+(?=' + block.def.source + ')')
|
||||
();
|
||||
|
||||
block.blockquote = replace(block.blockquote)
|
||||
('def', block.def)
|
||||
();
|
||||
|
||||
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+(?!:/|[^\\w\\s@]*@)\\b';
|
||||
+ '|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b';
|
||||
|
||||
block.html = replace(block.html)
|
||||
('comment', /<!--[\s\S]*?-->/)
|
||||
('closed', /<(tag)[\s\S]+?<\/\1>/)
|
||||
('closing', /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)
|
||||
('closing', /<tag(?:"[^"]*"|'[^']*'|\s[^'"\/>]*)*?\/?>/)
|
||||
(/tag/g, block._tag)
|
||||
();
|
||||
|
||||
@@ -61,9 +64,11 @@ block.paragraph = replace(block.paragraph)
|
||||
('hr', block.hr)
|
||||
('heading', block.heading)
|
||||
('lheading', block.lheading)
|
||||
('blockquote', block.blockquote)
|
||||
('tag', '<' + block._tag)
|
||||
('def', block.def)
|
||||
();
|
||||
|
||||
block.blockquote = replace(block.blockquote)
|
||||
('paragraph', block.paragraph)
|
||||
();
|
||||
|
||||
/**
|
||||
@@ -77,15 +82,15 @@ block.normal = merge({}, block);
|
||||
*/
|
||||
|
||||
block.gfm = merge({}, block.normal, {
|
||||
fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/,
|
||||
fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\n? *\1 *(?:\n+|$)/,
|
||||
paragraph: /^/,
|
||||
heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
|
||||
});
|
||||
|
||||
block.gfm.paragraph = replace(block.paragraph)
|
||||
('(?!', '(?!'
|
||||
+ block.gfm.fences.source.replace('\\1', '\\2') + '|'
|
||||
+ block.list.source.replace('\\1', '\\3') + '|')
|
||||
+ block.gfm.fences.source.replace('\\1', '\\2') + '|'
|
||||
+ block.list.source.replace('\\1', '\\3') + '|')
|
||||
();
|
||||
|
||||
/**
|
||||
@@ -126,7 +131,7 @@ Lexer.rules = block;
|
||||
* Static Lex Method
|
||||
*/
|
||||
|
||||
Lexer.lex = function(src, options) {
|
||||
Lexer.lex = function (src, options) {
|
||||
var lexer = new Lexer(options);
|
||||
return lexer.lex(src);
|
||||
};
|
||||
@@ -135,7 +140,7 @@ Lexer.lex = function(src, options) {
|
||||
* Preprocessing
|
||||
*/
|
||||
|
||||
Lexer.prototype.lex = function(src) {
|
||||
Lexer.prototype.lex = function (src) {
|
||||
src = src
|
||||
.replace(/\r\n|\r/g, '\n')
|
||||
.replace(/\t/g, ' ')
|
||||
@@ -149,7 +154,7 @@ Lexer.prototype.lex = function(src) {
|
||||
* Lexing
|
||||
*/
|
||||
|
||||
Lexer.prototype.token = function(src, top, bq) {
|
||||
Lexer.prototype.token = function (src, top) {
|
||||
var src = src.replace(/^ +$/gm, '')
|
||||
, next
|
||||
, loose
|
||||
@@ -159,6 +164,7 @@ Lexer.prototype.token = function(src, top, bq) {
|
||||
, item
|
||||
, space
|
||||
, i
|
||||
, tag
|
||||
, l;
|
||||
|
||||
while (src) {
|
||||
@@ -239,17 +245,6 @@ Lexer.prototype.token = function(src, top, bq) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// lheading
|
||||
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]
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
// hr
|
||||
if (cap = this.rules.hr.exec(src)) {
|
||||
src = src.substring(cap[0].length);
|
||||
@@ -272,7 +267,7 @@ Lexer.prototype.token = function(src, top, bq) {
|
||||
// Pass `top` to keep the current
|
||||
// "toplevel" state. This is exactly
|
||||
// how markdown.pl works.
|
||||
this.token(cap, top, true);
|
||||
this.token(cap, top);
|
||||
|
||||
this.tokens.push({
|
||||
type: 'blockquote_end'
|
||||
@@ -341,7 +336,7 @@ Lexer.prototype.token = function(src, top, bq) {
|
||||
});
|
||||
|
||||
// Recurse.
|
||||
this.token(item, false, bq);
|
||||
this.token(item, false);
|
||||
|
||||
this.tokens.push({
|
||||
type: 'list_item_end'
|
||||
@@ -370,12 +365,16 @@ Lexer.prototype.token = function(src, top, bq) {
|
||||
}
|
||||
|
||||
// def
|
||||
if ((!bq && top) && (cap = this.rules.def.exec(src))) {
|
||||
if (top && (cap = this.rules.def.exec(src))) {
|
||||
src = src.substring(cap[0].length);
|
||||
this.tokens.links[cap[1].toLowerCase()] = {
|
||||
href: cap[2],
|
||||
title: cap[3]
|
||||
};
|
||||
if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
|
||||
tag = cap[1].toLowerCase();
|
||||
if (!this.tokens.links[tag]) {
|
||||
this.tokens.links[tag] = {
|
||||
href: cap[2],
|
||||
title: cap[3]
|
||||
};
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -413,6 +412,17 @@ Lexer.prototype.token = function(src, top, bq) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// lheading
|
||||
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]
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
// top-level paragraph
|
||||
if (top && (cap = this.rules.paragraph.exec(src))) {
|
||||
src = src.substring(cap[0].length);
|
||||
@@ -451,21 +461,29 @@ Lexer.prototype.token = function(src, top, bq) {
|
||||
|
||||
var inline = {
|
||||
escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
|
||||
autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
|
||||
autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
|
||||
url: noop,
|
||||
tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
|
||||
tag: /^<!--[\s\S]*?-->|^<\/?[a-zA-Z0-9\-]+(?:"[^"]*"|'[^']*'|\s[^<'">\/]*)*?\/?>/,
|
||||
link: /^!?\[(inside)\]\(href\)/,
|
||||
reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
|
||||
nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
|
||||
nolink: /^!?\[((?:\[[^\]]*\]|\\[\[\]]|[^\[\]])*)\]/,
|
||||
strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
|
||||
em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
|
||||
code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
|
||||
em: /^_([^\s_](?:[^_]|__)+?[^\s_])_\b|^\*((?:\*\*|[^*])+?)\*(?!\*)/,
|
||||
code: /^(`+)(\s*)([\s\S]*?[^`]?)\2\1(?!`)/,
|
||||
br: /^ {2,}\n(?!\s*$)/,
|
||||
del: noop,
|
||||
text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
|
||||
text: /^[\s\S]+?(?=[\\<!\[`*]|\b_| {2,}\n|$)/
|
||||
};
|
||||
|
||||
inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;
|
||||
inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
|
||||
inline._email = /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/;
|
||||
|
||||
inline.autolink = replace(inline.autolink)
|
||||
('scheme', inline._scheme)
|
||||
('email', inline._email)
|
||||
()
|
||||
|
||||
inline._inside = /(?:\[[^\]]*\]|\\[\[\]]|[^\[\]]|\](?=[^\[]*\]))*/;
|
||||
inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
|
||||
|
||||
inline.link = replace(inline.link)
|
||||
@@ -498,11 +516,14 @@ inline.pedantic = merge({}, inline.normal, {
|
||||
|
||||
inline.gfm = merge({}, inline.normal, {
|
||||
escape: replace(inline.escape)('])', '~|])')(),
|
||||
url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
|
||||
url: replace(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/)
|
||||
('email', inline._email)
|
||||
(),
|
||||
_backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
|
||||
del: /^~~(?=\S)([\s\S]*?\S)~~/,
|
||||
text: replace(inline.text)
|
||||
(']|', '~]|')
|
||||
('|', '|https?://|')
|
||||
('|', '|https?://|ftp://|www\\.|[a-zA-Z0-9.!#$%&\'*+/=?^_`{\\|}~-]+@|')
|
||||
()
|
||||
});
|
||||
|
||||
@@ -552,7 +573,7 @@ InlineLexer.rules = inline;
|
||||
* Static Lexing/Compiling Method
|
||||
*/
|
||||
|
||||
InlineLexer.output = function(src, links, options) {
|
||||
InlineLexer.output = function (src, links, options) {
|
||||
var inline = new InlineLexer(links, options);
|
||||
return inline.output(src);
|
||||
};
|
||||
@@ -561,7 +582,7 @@ InlineLexer.output = function(src, links, options) {
|
||||
* Lexing/Compiling
|
||||
*/
|
||||
|
||||
InlineLexer.prototype.output = function(src) {
|
||||
InlineLexer.prototype.output = function (src) {
|
||||
var out = ''
|
||||
, link
|
||||
, text
|
||||
@@ -580,10 +601,8 @@ InlineLexer.prototype.output = function(src) {
|
||||
if (cap = this.rules.autolink.exec(src)) {
|
||||
src = src.substring(cap[0].length);
|
||||
if (cap[2] === '@') {
|
||||
text = cap[1].charAt(6) === ':'
|
||||
? this.mangle(cap[1].substring(7))
|
||||
: this.mangle(cap[1]);
|
||||
href = this.mangle('mailto:') + text;
|
||||
text = escape(this.mangle(cap[1]));
|
||||
href = 'mailto:' + text;
|
||||
} else {
|
||||
text = escape(cap[1]);
|
||||
href = text;
|
||||
@@ -594,9 +613,19 @@ InlineLexer.prototype.output = function(src) {
|
||||
|
||||
// url (gfm)
|
||||
if (!this.inLink && (cap = this.rules.url.exec(src))) {
|
||||
cap[0] = this.rules._backpedal.exec(cap[0])[0];
|
||||
src = src.substring(cap[0].length);
|
||||
text = escape(cap[1]);
|
||||
href = text;
|
||||
if (cap[2] === '@') {
|
||||
text = escape(cap[0]);
|
||||
href = 'mailto:' + text;
|
||||
} else {
|
||||
text = escape(cap[0]);
|
||||
if (cap[1] === 'www.') {
|
||||
href = 'http://' + text;
|
||||
} else {
|
||||
href = text;
|
||||
}
|
||||
}
|
||||
out += this.renderer.link(href, null, text);
|
||||
continue;
|
||||
}
|
||||
@@ -631,7 +660,7 @@ InlineLexer.prototype.output = function(src) {
|
||||
|
||||
// reflink, nolink
|
||||
if ((cap = this.rules.reflink.exec(src))
|
||||
|| (cap = this.rules.nolink.exec(src))) {
|
||||
|| (cap = this.rules.nolink.exec(src))) {
|
||||
src = src.substring(cap[0].length);
|
||||
link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
|
||||
link = this.links[link.toLowerCase()];
|
||||
@@ -663,7 +692,7 @@ InlineLexer.prototype.output = function(src) {
|
||||
// code
|
||||
if (cap = this.rules.code.exec(src)) {
|
||||
src = src.substring(cap[0].length);
|
||||
out += this.renderer.codespan(escape(cap[2], true));
|
||||
out += this.renderer.codespan(escape(cap[3].trim(), true));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -701,7 +730,7 @@ InlineLexer.prototype.output = function(src) {
|
||||
* Compile Link
|
||||
*/
|
||||
|
||||
InlineLexer.prototype.outputLink = function(cap, link) {
|
||||
InlineLexer.prototype.outputLink = function (cap, link) {
|
||||
var href = escape(link.href)
|
||||
, title = link.title ? escape(link.title) : null;
|
||||
|
||||
@@ -714,7 +743,7 @@ InlineLexer.prototype.outputLink = function(cap, link) {
|
||||
* Smartypants Transformations
|
||||
*/
|
||||
|
||||
InlineLexer.prototype.smartypants = function(text) {
|
||||
InlineLexer.prototype.smartypants = function (text) {
|
||||
if (!this.options.smartypants) return text;
|
||||
return text
|
||||
// em-dashes
|
||||
@@ -737,7 +766,7 @@ InlineLexer.prototype.smartypants = function(text) {
|
||||
* Mangle Links
|
||||
*/
|
||||
|
||||
InlineLexer.prototype.mangle = function(text) {
|
||||
InlineLexer.prototype.mangle = function (text) {
|
||||
if (!this.options.mangle) return text;
|
||||
var out = ''
|
||||
, l = text.length
|
||||
@@ -763,7 +792,7 @@ function Renderer(options) {
|
||||
this.options = options || {};
|
||||
}
|
||||
|
||||
Renderer.prototype.code = function(code, lang, escaped) {
|
||||
Renderer.prototype.code = function (code, lang, escaped) {
|
||||
if (this.options.highlight) {
|
||||
var out = this.options.highlight(code, lang);
|
||||
if (out != null && out !== code) {
|
||||
@@ -786,15 +815,15 @@ Renderer.prototype.code = function(code, lang, escaped) {
|
||||
+ '\n</code></pre>\n';
|
||||
};
|
||||
|
||||
Renderer.prototype.blockquote = function(quote) {
|
||||
Renderer.prototype.blockquote = function (quote) {
|
||||
return '<blockquote>\n' + quote + '</blockquote>\n';
|
||||
};
|
||||
|
||||
Renderer.prototype.html = function(html) {
|
||||
Renderer.prototype.html = function (html) {
|
||||
return html;
|
||||
};
|
||||
|
||||
Renderer.prototype.heading = function(text, level, raw) {
|
||||
Renderer.prototype.heading = function (text, level, raw) {
|
||||
return '<h'
|
||||
+ level
|
||||
+ ' id="'
|
||||
@@ -807,24 +836,24 @@ Renderer.prototype.heading = function(text, level, raw) {
|
||||
+ '>\n';
|
||||
};
|
||||
|
||||
Renderer.prototype.hr = function() {
|
||||
Renderer.prototype.hr = function () {
|
||||
return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
|
||||
};
|
||||
|
||||
Renderer.prototype.list = function(body, ordered) {
|
||||
Renderer.prototype.list = function (body, ordered) {
|
||||
var type = ordered ? 'ol' : 'ul';
|
||||
return '<' + type + '>\n' + body + '</' + type + '>\n';
|
||||
};
|
||||
|
||||
Renderer.prototype.listitem = function(text) {
|
||||
Renderer.prototype.listitem = function (text) {
|
||||
return '<li>' + text + '</li>\n';
|
||||
};
|
||||
|
||||
Renderer.prototype.paragraph = function(text) {
|
||||
Renderer.prototype.paragraph = function (text) {
|
||||
return '<p>' + text + '</p>\n';
|
||||
};
|
||||
|
||||
Renderer.prototype.table = function(header, body) {
|
||||
Renderer.prototype.table = function (header, body) {
|
||||
return '<table>\n'
|
||||
+ '<thead>\n'
|
||||
+ header
|
||||
@@ -835,11 +864,11 @@ Renderer.prototype.table = function(header, body) {
|
||||
+ '</table>\n';
|
||||
};
|
||||
|
||||
Renderer.prototype.tablerow = function(content) {
|
||||
Renderer.prototype.tablerow = function (content) {
|
||||
return '<tr>\n' + content + '</tr>\n';
|
||||
};
|
||||
|
||||
Renderer.prototype.tablecell = function(content, flags) {
|
||||
Renderer.prototype.tablecell = function (content, flags) {
|
||||
var type = flags.header ? 'th' : 'td';
|
||||
var tag = flags.align
|
||||
? '<' + type + ' style="text-align:' + flags.align + '">'
|
||||
@@ -848,39 +877,42 @@ Renderer.prototype.tablecell = function(content, flags) {
|
||||
};
|
||||
|
||||
// span level renderer
|
||||
Renderer.prototype.strong = function(text) {
|
||||
Renderer.prototype.strong = function (text) {
|
||||
return '<strong>' + text + '</strong>';
|
||||
};
|
||||
|
||||
Renderer.prototype.em = function(text) {
|
||||
Renderer.prototype.em = function (text) {
|
||||
return '<em>' + text + '</em>';
|
||||
};
|
||||
|
||||
Renderer.prototype.codespan = function(text) {
|
||||
Renderer.prototype.codespan = function (text) {
|
||||
return '<code>' + text + '</code>';
|
||||
};
|
||||
|
||||
Renderer.prototype.br = function() {
|
||||
Renderer.prototype.br = function () {
|
||||
return this.options.xhtml ? '<br/>' : '<br>';
|
||||
};
|
||||
|
||||
Renderer.prototype.del = function(text) {
|
||||
Renderer.prototype.del = function (text) {
|
||||
return '<del>' + text + '</del>';
|
||||
};
|
||||
|
||||
Renderer.prototype.link = function(href, title, text) {
|
||||
Renderer.prototype.link = function (href, title, text) {
|
||||
if (this.options.sanitize) {
|
||||
try {
|
||||
var prot = decodeURIComponent(unescape(href))
|
||||
.replace(/[^\w:]/g, '')
|
||||
.toLowerCase();
|
||||
} catch (e) {
|
||||
return '';
|
||||
return text;
|
||||
}
|
||||
if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
|
||||
return '';
|
||||
return text;
|
||||
}
|
||||
}
|
||||
if (this.options.baseUrl && !originIndependentUrl.test(href)) {
|
||||
href = resolveUrl(this.options.baseUrl, href);
|
||||
}
|
||||
var out = '<a href="' + href + '"';
|
||||
if (title) {
|
||||
out += ' title="' + title + '"';
|
||||
@@ -889,7 +921,10 @@ Renderer.prototype.link = function(href, title, text) {
|
||||
return out;
|
||||
};
|
||||
|
||||
Renderer.prototype.image = function(href, title, text) {
|
||||
Renderer.prototype.image = function (href, title, text) {
|
||||
if (this.options.baseUrl && !originIndependentUrl.test(href)) {
|
||||
href = resolveUrl(this.options.baseUrl, href);
|
||||
}
|
||||
var out = '<img src="' + href + '" alt="' + text + '"';
|
||||
if (title) {
|
||||
out += ' title="' + title + '"';
|
||||
@@ -898,10 +933,36 @@ Renderer.prototype.image = function(href, title, text) {
|
||||
return out;
|
||||
};
|
||||
|
||||
Renderer.prototype.text = function(text) {
|
||||
Renderer.prototype.text = function (text) {
|
||||
return text;
|
||||
};
|
||||
|
||||
/**
|
||||
* TextRenderer
|
||||
* returns only the textual part of the token
|
||||
*/
|
||||
|
||||
function TextRenderer() { }
|
||||
|
||||
// no need for block level renderers
|
||||
|
||||
TextRenderer.prototype.strong =
|
||||
TextRenderer.prototype.em =
|
||||
TextRenderer.prototype.codespan =
|
||||
TextRenderer.prototype.del =
|
||||
TextRenderer.prototype.text = function (text) {
|
||||
return text;
|
||||
}
|
||||
|
||||
TextRenderer.prototype.link =
|
||||
TextRenderer.prototype.image = function (href, title, text) {
|
||||
return '' + text;
|
||||
}
|
||||
|
||||
TextRenderer.prototype.br = function () {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsing & Compiling
|
||||
*/
|
||||
@@ -919,8 +980,8 @@ function Parser(options) {
|
||||
* Static Parse Method
|
||||
*/
|
||||
|
||||
Parser.parse = function(src, options, renderer) {
|
||||
var parser = new Parser(options, renderer);
|
||||
Parser.parse = function (src, options) {
|
||||
var parser = new Parser(options);
|
||||
return parser.parse(src);
|
||||
};
|
||||
|
||||
@@ -928,8 +989,10 @@ Parser.parse = function(src, options, renderer) {
|
||||
* Parse Loop
|
||||
*/
|
||||
|
||||
Parser.prototype.parse = function(src) {
|
||||
this.inline = new InlineLexer(src.links, this.options, this.renderer);
|
||||
Parser.prototype.parse = function (src) {
|
||||
this.inline = new InlineLexer(src.links, this.options);
|
||||
// use an InlineLexer with a TextRenderer to extract pure text
|
||||
this.inlineText = new InlineLexer(src.links, merge({}, this.options, { renderer: new TextRenderer }));
|
||||
this.tokens = src.reverse();
|
||||
|
||||
var out = '';
|
||||
@@ -944,7 +1007,7 @@ Parser.prototype.parse = function(src) {
|
||||
* Next Token
|
||||
*/
|
||||
|
||||
Parser.prototype.next = function() {
|
||||
Parser.prototype.next = function () {
|
||||
return this.token = this.tokens.pop();
|
||||
};
|
||||
|
||||
@@ -952,7 +1015,7 @@ Parser.prototype.next = function() {
|
||||
* Preview Next Token
|
||||
*/
|
||||
|
||||
Parser.prototype.peek = function() {
|
||||
Parser.prototype.peek = function () {
|
||||
return this.tokens[this.tokens.length - 1] || 0;
|
||||
};
|
||||
|
||||
@@ -960,7 +1023,7 @@ Parser.prototype.peek = function() {
|
||||
* Parse Text Tokens
|
||||
*/
|
||||
|
||||
Parser.prototype.parseText = function() {
|
||||
Parser.prototype.parseText = function () {
|
||||
var body = this.token.text;
|
||||
|
||||
while (this.peek().type === 'text') {
|
||||
@@ -974,7 +1037,7 @@ Parser.prototype.parseText = function() {
|
||||
* Parse Current Token
|
||||
*/
|
||||
|
||||
Parser.prototype.tok = function() {
|
||||
Parser.prototype.tok = function () {
|
||||
switch (this.token.type) {
|
||||
case 'space': {
|
||||
return '';
|
||||
@@ -986,7 +1049,7 @@ Parser.prototype.tok = function() {
|
||||
return this.renderer.heading(
|
||||
this.inline.output(this.token.text),
|
||||
this.token.depth,
|
||||
this.token.text);
|
||||
unescape(this.inlineText.output(this.token.text)));
|
||||
}
|
||||
case 'code': {
|
||||
return this.renderer.code(this.token.text,
|
||||
@@ -999,13 +1062,11 @@ Parser.prototype.tok = function() {
|
||||
, i
|
||||
, row
|
||||
, cell
|
||||
, flags
|
||||
, j;
|
||||
|
||||
// header
|
||||
cell = '';
|
||||
for (i = 0; i < this.token.header.length; i++) {
|
||||
flags = { header: true, align: this.token.align[i] };
|
||||
cell += this.renderer.tablecell(
|
||||
this.inline.output(this.token.header[i]),
|
||||
{ header: true, align: this.token.align[i] }
|
||||
@@ -1096,8 +1157,8 @@ function escape(html, encode) {
|
||||
}
|
||||
|
||||
function unescape(html) {
|
||||
// explicitly match decimal, hex, and named HTML entities
|
||||
return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function(_, n) {
|
||||
// explicitly match decimal, hex, and named HTML entities
|
||||
return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function (_, n) {
|
||||
n = n.toLowerCase();
|
||||
if (n === 'colon') return ':';
|
||||
if (n.charAt(0) === '#') {
|
||||
@@ -1121,7 +1182,31 @@ function replace(regex, opt) {
|
||||
};
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
function resolveUrl(base, href) {
|
||||
if (!baseUrls[' ' + base]) {
|
||||
// we can ignore everything in base after the last slash of its path component,
|
||||
// but we might need to add _that_
|
||||
// https://tools.ietf.org/html/rfc3986#section-3
|
||||
if (/^[^:]+:\/*[^/]*$/.test(base)) {
|
||||
baseUrls[' ' + base] = base + '/';
|
||||
} else {
|
||||
baseUrls[' ' + base] = base.replace(/[^/]*$/, '');
|
||||
}
|
||||
}
|
||||
base = baseUrls[' ' + base];
|
||||
|
||||
if (href.slice(0, 2) === '//') {
|
||||
return base.replace(/:[\s\S]*/, ':') + href;
|
||||
} else if (href.charAt(0) === '/') {
|
||||
return base.replace(/(:\/*[^/]*)[\s\S]*/, '$1') + href;
|
||||
} else {
|
||||
return base + href;
|
||||
}
|
||||
}
|
||||
var baseUrls = {};
|
||||
var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
|
||||
|
||||
function noop() { }
|
||||
noop.exec = noop;
|
||||
|
||||
function merge(obj) {
|
||||
@@ -1147,6 +1232,14 @@ function merge(obj) {
|
||||
*/
|
||||
|
||||
function marked(src, opt, callback) {
|
||||
// throw error in case of non string input
|
||||
if (typeof src == 'undefined' || src === null)
|
||||
throw new Error('marked(): input parameter is undefined or null');
|
||||
if (typeof src != 'string')
|
||||
throw new Error('marked(): input parameter is of type ' +
|
||||
Object.prototype.toString.call(src) + ', string expected');
|
||||
|
||||
|
||||
if (callback || typeof opt === 'function') {
|
||||
if (!callback) {
|
||||
callback = opt;
|
||||
@@ -1168,7 +1261,7 @@ function marked(src, opt, callback) {
|
||||
|
||||
pending = tokens.length;
|
||||
|
||||
var done = function(err) {
|
||||
var done = function (err) {
|
||||
if (err) {
|
||||
opt.highlight = highlight;
|
||||
return callback(err);
|
||||
@@ -1198,11 +1291,11 @@ function marked(src, opt, callback) {
|
||||
if (!pending) return done();
|
||||
|
||||
for (; i < tokens.length; i++) {
|
||||
(function(token) {
|
||||
(function (token) {
|
||||
if (token.type !== 'code') {
|
||||
return --pending || done();
|
||||
}
|
||||
return highlight(token.text, token.lang, function(err, code) {
|
||||
return highlight(token.text, token.lang, function (err, code) {
|
||||
if (err) return done(err);
|
||||
if (code == null || code === token.text) {
|
||||
return --pending || done();
|
||||
@@ -1235,10 +1328,10 @@ function marked(src, opt, callback) {
|
||||
*/
|
||||
|
||||
marked.options =
|
||||
marked.setOptions = function(opt) {
|
||||
merge(marked.defaults, opt);
|
||||
return marked;
|
||||
};
|
||||
marked.setOptions = function (opt) {
|
||||
merge(marked.defaults, opt);
|
||||
return marked;
|
||||
};
|
||||
|
||||
marked.defaults = {
|
||||
gfm: true,
|
||||
@@ -1255,7 +1348,8 @@ marked.defaults = {
|
||||
smartypants: false,
|
||||
headerPrefix: '',
|
||||
renderer: new Renderer,
|
||||
xhtml: false
|
||||
xhtml: false,
|
||||
baseUrl: null
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1266,6 +1360,7 @@ marked.Parser = Parser;
|
||||
marked.parser = Parser.parse;
|
||||
|
||||
marked.Renderer = Renderer;
|
||||
marked.TextRenderer = TextRenderer;
|
||||
|
||||
marked.Lexer = Lexer;
|
||||
marked.lexer = Lexer.lex;
|
||||
|
||||
Reference in New Issue
Block a user