Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,8 @@ inline.pedantic = merge({}, inline.normal, {

inline.gfm = merge({}, inline.normal, {
escape: edit(inline.escape).replace('])', '~|])').getRegex(),
url: edit(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/)
.replace('email', inline._email)
.getRegex(),
_extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
_backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
del: /^~+(?=\S)([\s\S]*?\S)~+/,
text: edit(inline.text)
Expand All @@ -616,6 +615,9 @@ inline.gfm = merge({}, inline.normal, {
.getRegex()
});

inline.gfm.url = edit(inline.gfm.url)
.replace('email', inline.gfm._extended_email)
.getRegex();
/**
* GFM + Line Breaks Inline Grammar
*/
Expand Down Expand Up @@ -703,22 +705,23 @@ InlineLexer.prototype.output = function(src) {

// url (gfm)
if (!this.inLink && (cap = this.rules.url.exec(src))) {
do {
prevCapZero = cap[0];
cap[0] = this.rules._backpedal.exec(cap[0])[0];
} while (prevCapZero !== cap[0]);
src = src.substring(cap[0].length);
if (cap[2] === '@') {
text = escape(cap[0]);
href = 'mailto:' + text;
} else {
// do extended autolink path validation
do {
prevCapZero = cap[0];
cap[0] = this.rules._backpedal.exec(cap[0])[0];
} while (prevCapZero !== cap[0]);
text = escape(cap[0]);
if (cap[1] === 'www.') {
href = 'http://' + text;
} else {
href = text;
}
}
src = src.substring(cap[0].length);
out += this.renderer.link(href, null, text);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion test/specs/marked/marked-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Marked Autolinks', function() {
describe('Marked Code spans', function() {
var section = 'Code spans';

var shouldPassButFails = [1];
var shouldPassButFails = [];

var willNotBeAttemptedByCoreTeam = [];

Expand Down
50 changes: 31 additions & 19 deletions test/specs/marked/marked.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
[
{
"section": "Autolinks",
"markdown": "(See https://www.example.com/fhqwhgads.)",
"html": "<p>(See <a href=\"https://www.example.com/fhqwhgads\">https://www.example.com/fhqwhgads</a>.)</p>",
"example": 10
},
{
"section": "Autolinks",
"markdown": "((http://foo.com))",
"html": "<p>((<a href=\"http://foo.com\">http://foo.com</a>))</p>",
"example": 11
},
{
"section": "Autolinks",
"markdown": "((http://foo.com.))",
"html": "<p>((<a href=\"http://foo.com\">http://foo.com</a>.))</p>",
"example": 12
},
{
"section": "Code spans",
"markdown": "`[email protected]`",
Expand Down Expand Up @@ -76,5 +58,35 @@
"markdown": "Link: [constructor][].\n\n[constructor]: https://example.org/",
"html": "<p>Link: <a href=\"https://example.org/\">constructor</a>.</p>",
"example": 10
},
{
"section": "Autolinks",
"markdown": "(See https://www.example.com/fhqwhgads.)",
"html": "<p>(See <a href=\"https://www.example.com/fhqwhgads\">https://www.example.com/fhqwhgads</a>.)</p>",
"example": 11
},
{
"section": "Autolinks",
"markdown": "((http://foo.com))",
"html": "<p>((<a href=\"http://foo.com\">http://foo.com</a>))</p>",
"example": 12
},
{
"section": "Autolinks",
"markdown": "((http://foo.com.))",
"html": "<p>((<a href=\"http://foo.com\">http://foo.com</a>.))</p>",
"example": 13
},
{
"section": "Autolinks",
"markdown": "[email protected]~~",
"html": "<p><del><a href=\"mailto:[email protected]\">[email protected]</a></del></p>",
"example": 1307
},
{
"section": "Autolinks",
"markdown": "**[email protected]**",
"html": "<p><strong><a href=\"mailto:[email protected]\">[email protected]</a></strong></p>",
"example": 1327
}
]
]