Skip to content

Commit

Permalink
Merge pull request #1385 from anis-ladram/master
Browse files Browse the repository at this point in the history
Fix bold around autolink email address
  • Loading branch information
styfle authored Dec 6, 2018
2 parents ed64407 + 485248e commit 20d3b8c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 37 deletions.
74 changes: 37 additions & 37 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,43 +694,6 @@ InlineLexer.prototype.output = function(src) {
continue;
}

// autolink
if (cap = this.rules.autolink.exec(src)) {
src = src.substring(cap[0].length);
if (cap[2] === '@') {
text = escape(this.mangle(cap[1]));
href = 'mailto:' + text;
} else {
text = escape(cap[1]);
href = text;
}
out += this.renderer.link(href, null, text);
continue;
}

// url (gfm)
if (!this.inLink && (cap = this.rules.url.exec(src))) {
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;
}

// tag
if (cap = this.rules.tag.exec(src)) {
if (!this.inLink && /^<a /i.test(cap[0])) {
Expand Down Expand Up @@ -831,6 +794,43 @@ InlineLexer.prototype.output = function(src) {
continue;
}

// autolink
if (cap = this.rules.autolink.exec(src)) {
src = src.substring(cap[0].length);
if (cap[2] === '@') {
text = escape(this.mangle(cap[1]));
href = 'mailto:' + text;
} else {
text = escape(cap[1]);
href = text;
}
out += this.renderer.link(href, null, text);
continue;
}

// url (gfm)
if (!this.inLink && (cap = this.rules.url.exec(src))) {
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;
}

// text
if (cap = this.rules.text.exec(src)) {
src = src.substring(cap[0].length);
Expand Down
6 changes: 6 additions & 0 deletions test/specs/marked/marked.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@
"html": "<p><strong><a href=\"mailto:me@example.com\">me@example.com</a></strong></p>",
"example": 1327
},
{
"section": "Autolinks",
"markdown": "__test@test.com__",
"html": "<p><strong><a href=\"mailto:test@test.com\">test@test.com</a></strong></p>",
"example": 1347
},
{
"section": "Emphasis extra tests",
"markdown": "_test_. _test_: _test_! _test_? _test_-",
Expand Down

0 comments on commit 20d3b8c

Please sign in to comment.