diff --git a/src/subParsers/makehtml/stripLinkDefinitions.js b/src/subParsers/makehtml/stripLinkDefinitions.js index 350da9a..567fb57 100644 --- a/src/subParsers/makehtml/stripLinkDefinitions.js +++ b/src/subParsers/makehtml/stripLinkDefinitions.js @@ -6,14 +6,19 @@ showdown.subParser('makehtml.stripLinkDefinitions', function (text, options, globals) { 'use strict'; - var regex = /^ {0,3}\[(.+)]:[ \t]*\n?[ \t]*\s]+)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*\n?[ \t]*(?:(\n*)["|'(](.+?)["|')][ \t]*)?(?:\n+|(?=¨0))/gm, - base64Regex = /^ {0,3}\[(.+)]:[ \t]*\n?[ \t]*?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*\n?[ \t]*(?:(\n*)["|'(](.+?)["|')][ \t]*)?(?:\n\n|(?=¨0)|(?=\n\[))/gm; + var regex = /^ {0,3}\[([^\]]+)]:[ \t]*\n?[ \t]*\s]+)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*\n?[ \t]*(?:(\n*)["|'(](.+?)["|')][ \t]*)?(?:\n+|(?=¨0))/gm, + base64Regex = /^ {0,3}\[([^\]]+)]:[ \t]*\n?[ \t]*?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*\n?[ \t]*(?:(\n*)["|'(](.+?)["|')][ \t]*)?(?:\n\n|(?=¨0)|(?=\n\[))/gm; // attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug text += '¨0'; var replaceFunc = function (wholeMatch, linkId, url, width, height, blankLines, title) { + + // if there aren't two instances of linkId it must not be a reference link so back out linkId = linkId.toLowerCase(); + if (text.toLowerCase().split(linkId).length - 1 < 2) { + return wholeMatch; + } if (url.match(/^data:.+?\/.+?;base64,/)) { // remove newlines globals.gUrls[linkId] = url.replace(/\s/g, ''); diff --git a/test/functional/makehtml/cases/issues/reference-link-impostors.html b/test/functional/makehtml/cases/issues/reference-link-impostors.html new file mode 100644 index 0000000..706117a --- /dev/null +++ b/test/functional/makehtml/cases/issues/reference-link-impostors.html @@ -0,0 +1,3 @@ +

[We] are going to show [you]: sunshine!

+

[x]: take out the garbage
+[ ]: bring up the coal

diff --git a/test/functional/makehtml/cases/issues/reference-link-impostors.md b/test/functional/makehtml/cases/issues/reference-link-impostors.md new file mode 100644 index 0000000..f71ed03 --- /dev/null +++ b/test/functional/makehtml/cases/issues/reference-link-impostors.md @@ -0,0 +1,4 @@ +[We] are going to show [you]: sunshine! + +[x]: take out the garbage +[ ]: bring up the coal