Skip to content
Permalink
Browse files

new gfm autolink rule: http/www URLs and email addresses

  • Loading branch information...
Feder1co5oave committed Jan 23, 2018
1 parent ed6d145 commit 00f1f7a23916ef27186d0904635aa3509af63d47
Showing with 15 additions and 4 deletions.
  1. +15 −4 lib/marked.js
@@ -515,11 +515,13 @@ inline.pedantic = merge({}, inline.normal, {

inline.gfm = merge({}, inline.normal, {
escape: replace(inline.escape)('])', '~|])')(),
url: /^(https?:\/\/[^\s<]+[^<.,:;"'!)\]\s])/,
url: replace(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/)
('email', inline._email)
(),
del: /^~~(?=\S)([\s\S]*?\S)~~/,
text: replace(inline.text)
(']|', '~]|')
('|', '|https?://|')
('|', '|https?://|ftp://|www\\.|[a-zA-Z0-9.!#$%&\'*+/=?^_`{\\|}~-]+@|')
()
});

@@ -610,8 +612,17 @@ InlineLexer.prototype.output = function(src) {
// url (gfm)
if (!this.inLink && (cap = this.rules.url.exec(src))) {
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;
}

0 comments on commit 00f1f7a

Please sign in to comment.
You can’t perform that action at this time.