Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
davisjam committed Apr 16, 2018
1 parent fbf93a8 commit ba2fc13
Showing 1 changed file with 43 additions and 22 deletions.
65 changes: 43 additions & 22 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,36 +564,57 @@ inline.pedantic = merge({}, inline.normal, {
.replace('label', inline._label)
.getRegex();

function unwrapAngleBrackets (str) {
if (str.match(/^<.*>$/)) {
str = str.slice(1, -1);
// destination: DESTINATION from generalLinkRe
// returns [destination, title]: no angle-brackets on destination, no quotes on title
function splitIntoDestinationAndTitle (destination) {
function unwrapAngleBrackets (str) {
if (str.match(/^<.*>$/)) {
str = str.slice(1, -1);
}
return str;
}

// Valid DESTINATIONs, in decreasing specificity.
var destinationAndTitleRe = /^([^'"(]*[^\s])\s+(['"(].*['")])/;
var destinationRe = /^(<?[\s\S]*>?)/;
var parsingRegexes = [destinationAndTitleRe, destinationRe];

var match = false;
var dest = undefined;
var title = undefined;
for (var i = 0; i < parsingRegexes.length; i++) {
match = parsingRegexes[i].exec(destination);
if (match) {
dest = match[1];
title = match[2];
break;
}
}

if (match) {
// title is optional.
if (typeof title === 'undefined') {
title = '';
}

// Format dest.
dest = dest.trim();
dest = unwrapAngleBrackets(dest);

return [dest, title];
}
return str;
return null;
}

var fullMatch = generalLinkRe.exec(s);
if (fullMatch) {
var text = fullMatch[1];
var destination = fullMatch[2];

var m;

var destinationAndTitleRe = /^([^'"(]*[^\s])\s+(['"(].*['")])/;
if (m = destinationAndTitleRe.exec(destination)) {
// <destination> -> destination
var dest1 = m[1].trim();
dest1 = unwrapAngleBrackets(dest1);
var title1 = m[2];
return [fullMatch[0], text, dest1, title1];
}

var destinationRe = /^(<?[\s\S]*>?)/;
if (m = destinationRe.exec(destination)) {
// <destination> -> destination
var dest2 = m[1].trim();
dest2 = unwrapAngleBrackets(dest2);
var title2 = '';
return [fullMatch[0], text, dest2, title2];
// Does 'destination' match spec?
var destinationAndTitle = splitIntoDestinationAndTitle(destination);
if (destinationAndTitle) {
return [fullMatch[0], text, destinationAndTitle[0], destinationAndTitle[1]];
}
}
return null;
Expand Down

0 comments on commit ba2fc13

Please sign in to comment.