Skip to content

Commit 3a4f7a5

Browse files
authored
Merge pull request #976 from UziTech/v0.3.9
V0.3.9
2 parents 900e50e + 43fc870 commit 3a4f7a5

15 files changed

+157
-51
lines changed

bower.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"name": "marked",
3-
"version": "0.3.4",
43
"homepage": "https://github.com/chjj/marked",
54
"authors": [
65
"Christopher Jeffrey <[email protected]>"

lib/marked.js

+40-11
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ block.list = replace(block.list)
3939
('def', '\\n+(?=' + block.def.source + ')')
4040
();
4141

42-
block.blockquote = replace(block.blockquote)
43-
('def', block.def)
44-
();
45-
4642
block._tag = '(?!(?:'
4743
+ 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
4844
+ '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
@@ -457,7 +453,7 @@ var inline = {
457453
nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
458454
strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
459455
em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
460-
code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
456+
code: /^(`+)([\s\S]*?[^`])\1(?!`)/,
461457
br: /^ {2,}\n(?!\s*$)/,
462458
del: noop,
463459
text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
@@ -578,9 +574,11 @@ InlineLexer.prototype.output = function(src) {
578574
if (cap = this.rules.autolink.exec(src)) {
579575
src = src.substring(cap[0].length);
580576
if (cap[2] === '@') {
581-
text = cap[1].charAt(6) === ':'
577+
text = escape(
578+
cap[1].charAt(6) === ':'
582579
? this.mangle(cap[1].substring(7))
583-
: this.mangle(cap[1]);
580+
: this.mangle(cap[1])
581+
);
584582
href = this.mangle('mailto:') + text;
585583
} else {
586584
text = escape(cap[1]);
@@ -661,7 +659,7 @@ InlineLexer.prototype.output = function(src) {
661659
// code
662660
if (cap = this.rules.code.exec(src)) {
663661
src = src.substring(cap[0].length);
664-
out += this.renderer.codespan(escape(cap[2], true));
662+
out += this.renderer.codespan(escape(cap[2].trim(), true));
665663
continue;
666664
}
667665

@@ -879,6 +877,9 @@ Renderer.prototype.link = function(href, title, text) {
879877
return '';
880878
}
881879
}
880+
if (this.options.baseUrl && !originIndependentUrl.test(href)) {
881+
href = resolveUrl(this.options.baseUrl, href);
882+
}
882883
var out = '<a href="' + href + '"';
883884
if (title) {
884885
out += ' title="' + title + '"';
@@ -888,6 +889,9 @@ Renderer.prototype.link = function(href, title, text) {
888889
};
889890

890891
Renderer.prototype.image = function(href, title, text) {
892+
if (this.options.baseUrl && !originIndependentUrl.test(href)) {
893+
href = resolveUrl(this.options.baseUrl, href);
894+
}
891895
var out = '<img src="' + href + '" alt="' + text + '"';
892896
if (title) {
893897
out += ' title="' + title + '"';
@@ -1094,8 +1098,8 @@ function escape(html, encode) {
10941098
}
10951099

10961100
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) {
1101+
// explicitly match decimal, hex, and named HTML entities
1102+
return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function(_, n) {
10991103
n = n.toLowerCase();
11001104
if (n === 'colon') return ':';
11011105
if (n.charAt(0) === '#') {
@@ -1119,6 +1123,30 @@ function replace(regex, opt) {
11191123
};
11201124
}
11211125

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

@@ -1253,7 +1281,8 @@ marked.defaults = {
12531281
smartypants: false,
12541282
headerPrefix: '',
12551283
renderer: new Renderer,
1256-
xhtml: false
1284+
xhtml: false,
1285+
baseUrl: null
12571286
};
12581287

12591288
/**

marked.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "marked",
33
"description": "A markdown parser built for speed",
44
"author": "Christopher Jeffrey",
5-
"version": "0.3.7",
5+
"version": "0.3.9",
66
"main": "./lib/marked.js",
77
"bin": "./bin/marked",
88
"man": "./man/marked.1",

test/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ main:
101101
});
102102
flags.forEach(function(key) {
103103
var val = true;
104-
if (key.indexOf('no') === 0) {
104+
if(key.indexOf('=') !== -1) {
105+
val = decodeURIComponent(key.substring(key.indexOf('=') + 1));
106+
key = key.substring(0, key.indexOf('='));
107+
} else if (key.indexOf('no') === 0) {
105108
key = key.substring(2);
106109
val = false;
107110
}

test/tests/def_blocks.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
<hr>
77

88
<blockquote>
9-
<p>hello</p>
9+
<p>hello
10+
[2]: hello</p>
1011
</blockquote>
1112

1213

@@ -24,5 +25,6 @@
2425
<blockquote>
2526
<p>foo
2627
bar
28+
[1]: foo
2729
bar</p>
2830
</blockquote>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<p><a href="mailto:&lt;svg/onload=&quot;alert(1)&quot;//@x">&lt;svg/onload=&quot;alert(1)&quot;//@x</a></p>
2+
3+
<p><a href="mailto:bar&quot;onclick=&quot;alert(&#39;XSS&#39;)&quot;@foo">bar&quot;onclick=&quot;alert(&#39;XSS&#39;)&quot;@foo</a></p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<<svg/onload="alert(1)"//@x>
2+
3+
<bar"onclick="alert('XSS')"@foo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<h1 id="absolutization-of-rfc-3986-uris">Absolutization of RFC 3986 URIs</h1>
2+
3+
<h2 id="absolute-uri">Absolute URI</h2>
4+
5+
<p><a href="http://example.com/"><img src="http://example.com/logo" alt="section 4.3"></a></p>
6+
7+
<h2 id="network-path-reference">Network-path reference</h2>
8+
9+
<p><a href="http://example.com/"><img src="http://example.com/logo" alt="section 4.2"></a></p>
10+
11+
<h2 id="absolute-path">Absolute path</h2>
12+
13+
<p><a href="http://example.com/path/to/content"><img src="http://example.com/path/to/img" alt="section 4.2"></a></p>
14+
15+
<h2 id="relative-path">Relative path</h2>
16+
17+
<p><a href="http://example.com/base/content"><img src="http://example.com/base/img" alt="section 4.2"></a></p>
18+
19+
<h2 id="dot-relative-path">Dot-relative path</h2>
20+
21+
<p><a href="http://example.com/base/./content"><img src="http://example.com/base/./img" alt="section 3.3"></a></p>
22+
23+
<p><a href="http://example.com/base/../content"><img src="http://example.com/base/../img" alt="section 3.3"></a></p>
24+
25+
<h2 id="same-document-query">Same-document query</h2>
26+
27+
<p><a href="?"><img src="?type=image" alt="section 4.4"></a></p>
28+
29+
<h2 id="same-document-fragment">Same-document fragment</h2>
30+
31+
<p><a href="#"><img src="#img" alt="section 4.4"></a></p>
32+
33+
<h2 id="empty">Empty</h2>
34+
35+
<p><a href="">section 4.2</a></p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Absolutization of RFC 3986 URIs
2+
3+
## Absolute URI
4+
[![section 4.3](http://example.com/logo)](http://example.com/)
5+
6+
## Network-path reference
7+
[![section 4.2](//example.com/logo)](//example.com/)
8+
9+
## Absolute path
10+
[![section 4.2](/path/to/img)](/path/to/content)
11+
12+
## Relative path
13+
[![section 4.2](img)](content)
14+
15+
## Dot-relative path
16+
[![section 3.3](./img)](./content)
17+
18+
[![section 3.3](../img)](../content)
19+
20+
## Same-document query
21+
[![section 4.4](?type=image)](?)
22+
23+
## Same-document fragment
24+
[![section 4.4](#img)](#)
25+
26+
## Empty
27+
[section 4.2]()

test/tests/toplevel_paragraphs.gfm.html

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
<p>hello world
2-
how are you
3-
how are you</p>
2+
text after spaces
3+
text after spaces</p>
44

5-
<p>hello world</p>
6-
<pre><code>how are you</code></pre>
5+
<p>paragraph before code</p>
6+
<pre><code>text inside block code</code></pre>
77

8-
<p>hello world</p>
8+
<p>paragraph before hr</p>
99
<hr>
1010

11-
<p>hello world</p>
11+
<p>paragraph before head with hash</p>
1212
<h1 id="how-are-you">how are you</h1>
1313

14-
<p>hello world</p>
14+
<p>paragraph before head with equals</p>
1515
<h1 id="how-are-you">how are you</h1>
1616

17-
<p>hello world</p>
18-
<blockquote><p>how are you</p></blockquote>
17+
<p>paragraph before blockquote</p>
18+
<blockquote><p>text for blockquote</p></blockquote>
1919

20-
<p>hello world</p>
21-
<ul><li>how are you</li></ul>
20+
<p>paragraph before list</p>
21+
<ul><li>text inside list</li></ul>
2222

23-
<p>hello world</p>
24-
<div>how are you</div>
23+
<p>paragraph before div</p>
24+
<div>text inside div</div>
2525

26-
<p>hello world
27-
<span>how are you</span></p>
26+
<p>paragraph with span
27+
<span>text inside span</span></p>
2828

2929
<p>hello <a href="/are/you">world</a>
3030
</p>

test/tests/toplevel_paragraphs.gfm.text

+16-15
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
hello world
2-
how are you
3-
how are you
2+
text after spaces
3+
text after spaces
44

5-
hello world
5+
paragraph before code
66
```
7-
how are you
7+
text inside block code
88
```
99

10-
hello world
10+
paragraph before hr
1111
* * *
1212

13-
hello world
13+
paragraph before head with hash
1414
# how are you
1515

16-
hello world
16+
paragraph before head with equals
1717
how are you
1818
===========
1919

20-
hello world
21-
> how are you
20+
paragraph before blockquote
21+
> text for blockquote
2222

23-
hello world
24-
* how are you
23+
paragraph before list
24+
* text inside list
2525

26-
hello world
27-
<div>how are you</div>
26+
paragraph before div
27+
<div>text inside div</div>
2828

29-
hello world
30-
<span>how are you</span>
29+
paragraph with span
30+
<span>text inside span</span>
3131

3232
hello [world][how]
33+
3334
[how]: /are/you
3435

3536
<div>hello</div>
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<p>lowerlower
2+
upperupper</p>
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lower[click me](javascript&#x3a;...)lower
2+
upper[click me](javascript&#X3a;...)upper

0 commit comments

Comments
 (0)