Skip to content

Commit 69a2b5a

Browse files
Portugal, MarceloPortugal, Marcelo
Portugal, Marcelo
authored and
Portugal, Marcelo
committed
gh-pages v4.4.2
1 parent 40dd4a3 commit 69a2b5a

File tree

431 files changed

+67848
-819
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

431 files changed

+67848
-819
lines changed

docs/grunt-scripts/marked.js

+48-14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
;(function() {
8+
'use strict';
89

910
/**
1011
* Block-Level Grammar
@@ -449,21 +450,21 @@ Lexer.prototype.token = function(src, top, bq) {
449450

450451
var inline = {
451452
escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
452-
autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
453+
autolink: /^<([^ <>]+(@|:\/)[^ <>]+)>/,
453454
url: noop,
454-
tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
455+
tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^<'">])*?>/,
455456
link: /^!?\[(inside)\]\(href\)/,
456457
reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
457458
nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
458459
strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
459460
em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
460-
code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
461+
code: /^(`+)([\s\S]*?[^`])\1(?!`)/,
461462
br: /^ {2,}\n(?!\s*$)/,
462463
del: noop,
463464
text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
464465
};
465466

466-
inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;
467+
inline._inside = /(?:\[[^\]]*\]|\\[\[\]]|[^\[\]]|\](?=[^\[]*\]))*/;
467468
inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
468469

469470
inline.link = replace(inline.link)
@@ -578,9 +579,11 @@ InlineLexer.prototype.output = function(src) {
578579
if (cap = this.rules.autolink.exec(src)) {
579580
src = src.substring(cap[0].length);
580581
if (cap[2] === '@') {
581-
text = cap[1].charAt(6) === ':'
582+
text = escape(
583+
cap[1].charAt(6) === ':'
582584
? this.mangle(cap[1].substring(7))
583-
: this.mangle(cap[1]);
585+
: this.mangle(cap[1])
586+
);
584587
href = this.mangle('mailto:') + text;
585588
} else {
586589
text = escape(cap[1]);
@@ -661,7 +664,7 @@ InlineLexer.prototype.output = function(src) {
661664
// code
662665
if (cap = this.rules.code.exec(src)) {
663666
src = src.substring(cap[0].length);
664-
out += this.renderer.codespan(escape(cap[2], true));
667+
out += this.renderer.codespan(escape(cap[2].trim(), true));
665668
continue;
666669
}
667670

@@ -873,12 +876,15 @@ Renderer.prototype.link = function(href, title, text) {
873876
.replace(/[^\w:]/g, '')
874877
.toLowerCase();
875878
} catch (e) {
876-
return '';
879+
return text;
877880
}
878-
if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0) {
879-
return '';
881+
if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
882+
return text;
880883
}
881884
}
885+
if (this.options.baseUrl && !originIndependentUrl.test(href)) {
886+
href = resolveUrl(this.options.baseUrl, href);
887+
}
882888
var out = '<a href="' + href + '"';
883889
if (title) {
884890
out += ' title="' + title + '"';
@@ -888,6 +894,9 @@ Renderer.prototype.link = function(href, title, text) {
888894
};
889895

890896
Renderer.prototype.image = function(href, title, text) {
897+
if (this.options.baseUrl && !originIndependentUrl.test(href)) {
898+
href = resolveUrl(this.options.baseUrl, href);
899+
}
891900
var out = '<img src="' + href + '" alt="' + text + '"';
892901
if (title) {
893902
out += ' title="' + title + '"';
@@ -1094,8 +1103,8 @@ function escape(html, encode) {
10941103
}
10951104

10961105
function unescape(html) {
1097-
// explicitly match decimal, hex, and named HTML entities
1098-
return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function(_, n) {
1106+
// explicitly match decimal, hex, and named HTML entities
1107+
return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function(_, n) {
10991108
n = n.toLowerCase();
11001109
if (n === 'colon') return ':';
11011110
if (n.charAt(0) === '#') {
@@ -1119,6 +1128,30 @@ function replace(regex, opt) {
11191128
};
11201129
}
11211130

1131+
function resolveUrl(base, href) {
1132+
if (!baseUrls[' ' + base]) {
1133+
// we can ignore everything in base after the last slash of its path component,
1134+
// but we might need to add _that_
1135+
// https://tools.ietf.org/html/rfc3986#section-3
1136+
if (/^[^:]+:\/*[^/]*$/.test(base)) {
1137+
baseUrls[' ' + base] = base + '/';
1138+
} else {
1139+
baseUrls[' ' + base] = base.replace(/[^/]*$/, '');
1140+
}
1141+
}
1142+
base = baseUrls[' ' + base];
1143+
1144+
if (href.slice(0, 2) === '//') {
1145+
return base.replace(/:[\s\S]*/, ':') + href;
1146+
} else if (href.charAt(0) === '/') {
1147+
return base.replace(/(:\/*[^/]*)[\s\S]*/, '$1') + href;
1148+
} else {
1149+
return base + href;
1150+
}
1151+
}
1152+
var baseUrls = {};
1153+
var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
1154+
11221155
function noop() {}
11231156
noop.exec = noop;
11241157

@@ -1220,7 +1253,7 @@ function marked(src, opt, callback) {
12201253
} catch (e) {
12211254
e.message += '\nPlease report this to https://github.com/chjj/marked.';
12221255
if ((opt || marked.defaults).silent) {
1223-
return '<p>An error occured:</p><pre>'
1256+
return '<p>An error occurred:</p><pre>'
12241257
+ escape(e.message + '', true)
12251258
+ '</pre>';
12261259
}
@@ -1253,7 +1286,8 @@ marked.defaults = {
12531286
smartypants: false,
12541287
headerPrefix: '',
12551288
renderer: new Renderer,
1256-
xhtml: false
1289+
xhtml: false,
1290+
baseUrl: null
12571291
};
12581292

12591293
/**

0 commit comments

Comments
 (0)