Skip to content

Commit

Permalink
allow link titles to be wrapped in parenthesis
Browse files Browse the repository at this point in the history
  • Loading branch information
Feder1co5oave committed Mar 5, 2018
1 parent 277d093 commit 3afc360
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ var inline = {
+ '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
+ '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
+ '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>', // CDATA section
link: /^!?\[(inside)\]\(href\)/,
link: /^!?\[(inside)\]\(href(?:\s+(title))?\s*\)/,
reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
nolink: /^!?\[((?:\[[^\]]*\]|\\[\[\]]|[^\[\]])*)\]/,
strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
Expand All @@ -508,7 +508,6 @@ var inline = {
text: /^[\s\S]+?(?=[\\<!\[`*]|\b_| {2,}\n|$)/
};


inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;

inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
Expand All @@ -526,11 +525,13 @@ inline.tag = edit(inline.tag)
.getRegex();

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

inline.link = edit(inline.link)
.replace('inside', inline._inside)
.replace('href', inline._href)
.replace('title', inline._title)
.getRegex();

inline.reflink = edit(inline.reflink)
Expand All @@ -550,7 +551,7 @@ inline.normal = merge({}, inline);
inline.pedantic = merge({}, inline.normal, {
strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,
link: edit(/^!?\[(inside)\]\(\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*\)/)
link: edit(/^!?\[(inside)\]\(\s*<?([\s\S]*?)>?(?:\s+(['"][\s\S]*?['"]))?\s*\)/)
.replace('inside', inline._inside)
.getRegex()
});
Expand Down Expand Up @@ -631,6 +632,7 @@ InlineLexer.prototype.output = function(src) {
link,
text,
href,
title,
cap;

while (src) {
Expand Down Expand Up @@ -696,9 +698,10 @@ InlineLexer.prototype.output = function(src) {
this.inLink = true;
href = cap[2];
href = href[0] === '<' ? href.substring(1, href.length - 1) : href;
title = cap[3] ? cap[3].substring(1, cap[3].length - 1) : cap[3];
out += this.outputLink(cap, {
href: InlineLexer.escapes(href),
title: InlineLexer.escapes(cap[3])
title: InlineLexer.escapes(title)
});
this.inLink = false;
continue;
Expand Down

0 comments on commit 3afc360

Please sign in to comment.