You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ab...@apache.org on 2018/05/17 16:24:17 UTC
[ambari] branch trunk updated: AMBARI-23881 Remove dependency on
marked.js 0.3.2 in Ambari Web. (ababiichuk)
This is an automated email from the ASF dual-hosted git repository.
ababiichuk pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push:
new 0460f44 AMBARI-23881 Remove dependency on marked.js 0.3.2 in Ambari Web. (ababiichuk)
0460f44 is described below
commit 0460f442618255d057627e9595d7561cd30af15b
Author: ababiichuk <ab...@hortonworks.com>
AuthorDate: Thu May 17 18:40:08 2018 +0300
AMBARI-23881 Remove dependency on marked.js 0.3.2 in Ambari Web. (ababiichuk)
---
ambari-web/api-docs/lib/marked.js | 464 ++++++++++++++++++++++++--------------
1 file changed, 290 insertions(+), 174 deletions(-)
diff --git a/ambari-web/api-docs/lib/marked.js b/ambari-web/api-docs/lib/marked.js
index c2a678d..5552616 100644
--- a/ambari-web/api-docs/lib/marked.js
+++ b/ambari-web/api-docs/lib/marked.js
@@ -1,10 +1,11 @@
/**
* marked - a markdown parser
* Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed)
- * https://github.com/chjj/marked
+ * https://github.com/markedjs/marked
*/
-;(function() {
+;(function(root) {
+'use strict';
/**
* Block-Level Grammar
@@ -14,55 +15,60 @@ 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 = edit(block.def)
+ .replace('label', block._label)
+ .replace('title', block._title)
+ .getRegex();
+
block.bullet = /(?:[*+-]|\d+\.)/;
block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
-block.item = replace(block.item, 'gm')
- (/bull/g, block.bullet)
- ();
+block.item = edit(block.item, 'gm')
+ .replace(/bull/g, block.bullet)
+ .getRegex();
-block.list = replace(block.list)
- (/bull/g, block.bullet)
- ('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))')
- ('def', '\\n+(?=' + block.def.source + ')')
- ();
-
-block.blockquote = replace(block.blockquote)
- ('def', block.def)
- ();
+block.list = edit(block.list)
+ .replace(/bull/g, block.bullet)
+ .replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))')
+ .replace('def', '\\n+(?=' + block.def.source + ')')
+ .getRegex();
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';
-
-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)
- ();
+ + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b';
+
+block.html = edit(block.html)
+ .replace('comment', /<!--[\s\S]*?-->/)
+ .replace('closed', /<(tag)[\s\S]+?<\/\1>/)
+ .replace('closing', /<tag(?:"[^"]*"|'[^']*'|\s[^'"\/>\s]*)*?\/?>/)
+ .replace(/tag/g, block._tag)
+ .getRegex();
+
+block.paragraph = edit(block.paragraph)
+ .replace('hr', block.hr)
+ .replace('heading', block.heading)
+ .replace('lheading', block.lheading)
+ .replace('tag', '<' + block._tag)
+ .getRegex();
+
+block.blockquote = edit(block.blockquote)
+ .replace('paragraph', block.paragraph)
+ .getRegex();
/**
* Normal Block Grammar
@@ -75,15 +81,16 @@ block.normal = merge({}, block);
*/
block.gfm = merge({}, block.normal, {
- fences: /^ *(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n+|$)/,
- paragraph: /^/
+ fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\n? *\1 *(?:\n+|$)/,
+ paragraph: /^/,
+ heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
});
-block.gfm.paragraph = replace(block.paragraph)
- ('(?!', '(?!'
+block.gfm.paragraph = edit(block.paragraph)
+ .replace('(?!', '(?!'
+ block.gfm.fences.source.replace('\\1', '\\2') + '|'
+ block.list.source.replace('\\1', '\\3') + '|')
- ();
+ .getRegex();
/**
* GFM + Tables Block Grammar
@@ -146,17 +153,19 @@ Lexer.prototype.lex = function(src) {
* Lexing
*/
-Lexer.prototype.token = function(src, top, bq) {
- var src = src.replace(/^ +$/gm, '')
- , next
- , loose
- , cap
- , bull
- , b
- , item
- , space
- , i
- , l;
+Lexer.prototype.token = function(src, top) {
+ src = src.replace(/^ +$/gm, '');
+ var next,
+ loose,
+ cap,
+ bull,
+ b,
+ item,
+ space,
+ i,
+ tag,
+ l,
+ isordered;
while (src) {
// newline
@@ -188,7 +197,7 @@ Lexer.prototype.token = function(src, top, bq) {
this.tokens.push({
type: 'code',
lang: cap[2],
- text: cap[3]
+ text: cap[3] || ''
});
continue;
}
@@ -236,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);
@@ -269,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'
@@ -282,10 +280,12 @@ Lexer.prototype.token = function(src, top, bq) {
if (cap = this.rules.list.exec(src)) {
src = src.substring(cap[0].length);
bull = cap[2];
+ isordered = bull.length > 1;
this.tokens.push({
type: 'list_start',
- ordered: bull.length > 1
+ ordered: isordered,
+ start: isordered ? +bull : ''
});
// Get each top-level item.
@@ -338,7 +338,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'
@@ -359,19 +359,24 @@ Lexer.prototype.token = function(src, top, bq) {
type: this.options.sanitize
? 'paragraph'
: 'html',
- pre: cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style',
+ pre: !this.options.sanitizer
+ && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
text: cap[0]
});
continue;
}
// 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;
}
@@ -409,6 +414,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);
@@ -433,8 +449,7 @@ Lexer.prototype.token = function(src, top, bq) {
}
if (src) {
- throw new
- Error('Infinite loop on byte: ' + src.charCodeAt(0));
+ throw new Error('Infinite loop on byte: ' + src.charCodeAt(0));
}
}
@@ -447,31 +462,39 @@ 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[^<'">\/\s]*)*?\/?>/,
link: /^!?\[(inside)\]\(href\)/,
reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
- nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
+ nolink: /^!?\[((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\]/,
strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
- em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
- code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
+ em: /^_([^\s_](?:[^_]|__)+?[^\s_])_\b|^\*((?:\*\*|[^*])+?)\*(?!\*)/,
+ code: /^(`+)\s*([\s\S]*?[^`]?)\s*\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 = edit(inline.autolink)
+ .replace('scheme', inline._scheme)
+ .replace('email', inline._email)
+ .getRegex()
+
+inline._inside = /(?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]]|\](?=[^\[]*\]))*/;
inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
-inline.link = replace(inline.link)
- ('inside', inline._inside)
- ('href', inline._href)
- ();
+inline.link = edit(inline.link)
+ .replace('inside', inline._inside)
+ .replace('href', inline._href)
+ .getRegex();
-inline.reflink = replace(inline.reflink)
- ('inside', inline._inside)
- ();
+inline.reflink = edit(inline.reflink)
+ .replace('inside', inline._inside)
+ .getRegex();
/**
* Normal Inline Grammar
@@ -493,13 +516,16 @@ inline.pedantic = merge({}, inline.normal, {
*/
inline.gfm = merge({}, inline.normal, {
- escape: replace(inline.escape)('])', '~|])')(),
- url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
+ escape: edit(inline.escape).replace('])', '~|])').getRegex(),
+ url: edit(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/)
+ .replace('email', inline._email)
+ .getRegex(),
+ _backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
del: /^~~(?=\S)([\s\S]*?\S)~~/,
- text: replace(inline.text)
- (']|', '~]|')
- ('|', '|https?://|')
- ()
+ text: edit(inline.text)
+ .replace(']|', '~]|')
+ .replace('|', '|https?://|ftp://|www\\.|[a-zA-Z0-9.!#$%&\'*+/=?^_`{\\|}~-]+@|')
+ .getRegex()
});
/**
@@ -507,8 +533,8 @@ inline.gfm = merge({}, inline.normal, {
*/
inline.breaks = merge({}, inline.gfm, {
- br: replace(inline.br)('{2,}', '*')(),
- text: replace(inline.gfm.text)('{2,}', '*')()
+ br: edit(inline.br).replace('{2,}', '*').getRegex(),
+ text: edit(inline.gfm.text).replace('{2,}', '*').getRegex()
});
/**
@@ -519,12 +545,11 @@ function InlineLexer(links, options) {
this.options = options || marked.defaults;
this.links = links;
this.rules = inline.normal;
- this.renderer = this.options.renderer || new Renderer;
+ this.renderer = this.options.renderer || new Renderer();
this.renderer.options = this.options;
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) {
@@ -558,11 +583,11 @@ InlineLexer.output = function(src, links, options) {
*/
InlineLexer.prototype.output = function(src) {
- var out = ''
- , link
- , text
- , href
- , cap;
+ var out = '',
+ link,
+ text,
+ href,
+ cap;
while (src) {
// escape
@@ -576,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;
@@ -590,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;
}
@@ -606,8 +639,10 @@ InlineLexer.prototype.output = function(src) {
}
src = src.substring(cap[0].length);
out += this.options.sanitize
- ? escape(cap[0])
- : cap[0];
+ ? this.options.sanitizer
+ ? this.options.sanitizer(cap[0])
+ : escape(cap[0])
+ : cap[0]
continue;
}
@@ -657,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[2].trim(), true));
continue;
}
@@ -678,13 +713,12 @@ InlineLexer.prototype.output = function(src) {
// text
if (cap = this.rules.text.exec(src)) {
src = src.substring(cap[0].length);
- out += escape(this.smartypants(cap[0]));
+ out += this.renderer.text(escape(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));
}
}
@@ -696,8 +730,8 @@ InlineLexer.prototype.output = function(src) {
*/
InlineLexer.prototype.outputLink = function(cap, link) {
- var href = escape(link.href)
- , title = link.title ? escape(link.title) : null;
+ var href = escape(link.href),
+ title = link.title ? escape(link.title) : null;
return cap[0].charAt(0) !== '!'
? this.renderer.link(href, title, this.output(cap[1]))
@@ -712,7 +746,9 @@ InlineLexer.prototype.smartypants = function(text) {
if (!this.options.smartypants) return text;
return text
// em-dashes
- .replace(/--/g, '\u2014')
+ .replace(/---/g, '\u2014')
+ // en-dashes
+ .replace(/--/g, '\u2013')
// opening singles
.replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
// closing singles & apostrophes
@@ -730,10 +766,11 @@ InlineLexer.prototype.smartypants = function(text) {
*/
InlineLexer.prototype.mangle = function(text) {
- var out = ''
- , l = text.length
- , i = 0
- , ch;
+ if (!this.options.mangle) return text;
+ var out = '',
+ l = text.length,
+ i = 0,
+ ch;
for (; i < l; i++) {
ch = text.charCodeAt(i);
@@ -802,9 +839,10 @@ Renderer.prototype.hr = function() {
return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
};
-Renderer.prototype.list = function(body, ordered) {
- var type = ordered ? 'ol' : 'ul';
- return '<' + type + '>\n' + body + '</' + type + '>\n';
+Renderer.prototype.list = function(body, ordered, start) {
+ var type = ordered ? 'ol' : 'ul',
+ startatt = (ordered && start !== 1) ? (' start="' + start + '"') : '';
+ return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
};
Renderer.prototype.listitem = function(text) {
@@ -866,12 +904,15 @@ Renderer.prototype.link = function(href, title, text) {
.replace(/[^\w:]/g, '')
.toLowerCase();
} catch (e) {
- return '';
+ return text;
}
- if (prot.indexOf('javascript:') === 0) {
- return '';
+ if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
+ 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 + '"';
@@ -881,6 +922,9 @@ Renderer.prototype.link = 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 + '"';
@@ -889,6 +933,36 @@ Renderer.prototype.image = function(href, title, text) {
return out;
};
+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
*/
@@ -897,7 +971,7 @@ function Parser(options) {
this.tokens = [];
this.token = null;
this.options = options || marked.defaults;
- this.options.renderer = this.options.renderer || new Renderer;
+ this.options.renderer = this.options.renderer || new Renderer();
this.renderer = this.options.renderer;
this.renderer.options = this.options;
}
@@ -906,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);
};
@@ -916,7 +990,12 @@ Parser.parse = function(src, options, renderer) {
*/
Parser.prototype.parse = function(src) {
- this.inline = new InlineLexer(src.links, this.options, this.renderer);
+ 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 = '';
@@ -973,7 +1052,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,
@@ -981,18 +1060,16 @@ Parser.prototype.tok = function() {
this.token.escaped);
}
case 'table': {
- var header = ''
- , body = ''
- , i
- , row
- , cell
- , flags
- , j;
+ var header = '',
+ body = '',
+ i,
+ row,
+ cell,
+ 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] }
@@ -1016,7 +1093,7 @@ Parser.prototype.tok = function() {
return this.renderer.table(header, body);
}
case 'blockquote_start': {
- var body = '';
+ body = '';
while (this.next().type !== 'blockquote_end') {
body += this.tok();
@@ -1025,17 +1102,18 @@ Parser.prototype.tok = function() {
return this.renderer.blockquote(body);
}
case 'list_start': {
- var body = ''
- , ordered = this.token.ordered;
+ body = '';
+ var ordered = this.token.ordered,
+ start = this.token.start;
while (this.next().type !== 'list_end') {
body += this.tok();
}
- return this.renderer.list(body, ordered);
+ return this.renderer.list(body, ordered, start);
}
case 'list_item_start': {
- var body = '';
+ body = '';
while (this.next().type !== 'list_item_end') {
body += this.token.type === 'text'
@@ -1046,7 +1124,7 @@ Parser.prototype.tok = function() {
return this.renderer.listitem(body);
}
case 'loose_item_start': {
- var body = '';
+ body = '';
while (this.next().type !== 'list_item_end') {
body += this.tok();
@@ -1083,7 +1161,8 @@ function escape(html, encode) {
}
function unescape(html) {
- return html.replace(/&([#\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) === '#') {
@@ -1095,25 +1174,53 @@ function unescape(html) {
});
}
-function replace(regex, opt) {
+function edit(regex, opt) {
regex = regex.source;
opt = opt || '';
- return function self(name, val) {
- if (!name) return new RegExp(regex, opt);
- val = val.source || val;
- val = val.replace(/(^|[^\[])\^/g, '$1');
- regex = regex.replace(name, val);
- return self;
+ return {
+ replace: function(name, val) {
+ val = val.source || val;
+ val = val.replace(/(^|[^\[])\^/g, '$1');
+ regex = regex.replace(name, val);
+ return this;
+ },
+ getRegex: function() {
+ return new RegExp(regex, opt);
+ }
};
}
+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) {
- var i = 1
- , target
- , key;
+ var i = 1,
+ target,
+ key;
for (; i < arguments.length; i++) {
target = arguments[i];
@@ -1127,12 +1234,20 @@ function merge(obj) {
return obj;
}
-
/**
* Marked
*/
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;
@@ -1141,10 +1256,10 @@ function marked(src, opt, callback) {
opt = merge({}, marked.defaults, opt || {});
- var highlight = opt.highlight
- , tokens
- , pending
- , i = 0;
+ var highlight = opt.highlight,
+ tokens,
+ pending,
+ i = 0;
try {
tokens = Lexer.lex(src, opt)
@@ -1206,9 +1321,9 @@ function marked(src, opt, callback) {
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/markedjs/marked.';
if ((opt || marked.defaults).silent) {
- return '<p>An error occured:</p><pre>'
+ return '<p>An error occurred:</p><pre>'
+ escape(e.message + '', true)
+ '</pre>';
}
@@ -1232,14 +1347,17 @@ marked.defaults = {
breaks: false,
pedantic: false,
sanitize: false,
+ sanitizer: null,
+ mangle: true,
smartLists: false,
silent: false,
highlight: null,
langPrefix: 'lang-',
smartypants: false,
headerPrefix: '',
- renderer: new Renderer,
- xhtml: false
+ renderer: new Renderer(),
+ xhtml: false,
+ baseUrl: null
};
/**
@@ -1250,6 +1368,7 @@ marked.Parser = Parser;
marked.parser = Parser.parse;
marked.Renderer = Renderer;
+marked.TextRenderer = TextRenderer;
marked.Lexer = Lexer;
marked.lexer = Lexer.lex;
@@ -1264,9 +1383,6 @@ if (typeof module !== 'undefined' && typeof exports === 'object') {
} else if (typeof define === 'function' && define.amd) {
define(function() { return marked; });
} else {
- this.marked = marked;
+ root.marked = marked;
}
-
-}).call(function() {
- return this || (typeof window !== 'undefined' ? window : global);
-}());
\ No newline at end of file
+})(this || (typeof window !== 'undefined' ? window : global));
--
To stop receiving notification emails like this one, please contact
ababiichuk@apache.org.