diff --git a/dist/showdown.js b/dist/showdown.js index 2b3e1ba..089ca1c 100644 Binary files a/dist/showdown.js and b/dist/showdown.js differ diff --git a/dist/showdown.js.map b/dist/showdown.js.map index bc0b44a..648dba4 100644 Binary files a/dist/showdown.js.map and b/dist/showdown.js.map differ diff --git a/dist/showdown.min.js b/dist/showdown.min.js index 37b0ca7..cf90cd8 100644 Binary files a/dist/showdown.min.js and b/dist/showdown.min.js differ diff --git a/dist/showdown.min.js.map b/dist/showdown.min.js.map index 4589b04..ab04d86 100644 Binary files a/dist/showdown.min.js.map and b/dist/showdown.min.js.map differ diff --git a/src/subParsers/anchors.js b/src/subParsers/anchors.js index b45b56d..5779368 100644 --- a/src/subParsers/anchors.js +++ b/src/subParsers/anchors.js @@ -6,17 +6,16 @@ showdown.subParser('anchors', function (text, options, globals) { text = globals.converter._dispatch('anchors.before', text, options, globals); - var writeAnchorTag = function (wholeMatch, m1, m2, m3, m4, m5, m6, m7) { - if (showdown.helper.isUndefined(m7)) { - m7 = ''; + var writeAnchorTag = function (wholeMatch, linkText, linkId, url, m5, m6, title) { + if (showdown.helper.isUndefined(title)) { + title = ''; } - wholeMatch = m1; - var linkText = m2, - linkId = m3.toLowerCase(), - url = m4, - title = m7; + linkId = linkId.toLowerCase(); - if (!url) { + // Special case for explicit empty url + if (wholeMatch.search(/\(? ?(['"].*['"])?\)$/m) > -1) { + url = ''; + } else if (!url) { if (!linkId) { // lower-case and turn embedded newlines into spaces linkId = linkText.toLowerCase().replace(/ ?\n/g, ' '); @@ -29,12 +28,7 @@ showdown.subParser('anchors', function (text, options, globals) { title = globals.gTitles[linkId]; } } else { - if (wholeMatch.search(/\(\s*\)$/m) > -1) { - // Special case for explicit empty url - url = ''; - } else { - return wholeMatch; - } + return wholeMatch; } } @@ -61,16 +55,21 @@ showdown.subParser('anchors', function (text, options, globals) { }; // First, handle reference-style links: [link text] [id] - text = text.replace(/(\[((?:\[[^\]]*]|[^\[\]])*)][ ]?(?:\n[ ]*)?\[(.*?)])()()()()/g, writeAnchorTag); + text = text.replace(/\[((?:\[[^\]]*]|[^\[\]])*)] ?(?:\n *)?\[(.*?)]()()()()/g, writeAnchorTag); // Next, inline-style links: [link text](url "optional title") - text = text.replace(/(\[((?:\[[^\]]*]|[^\[\]])*)]\([ \t]*()?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g, + // cases with crazy urls like ./image/cat1).png + text = text.replace(/\[((?:\[[^\]]*]|[^\[\]])*)]()[ \t]*\([ \t]?<([^>]*)>(?:[ \t]*((["'])([^"]*?)\5))?[ \t]?\)/g, + writeAnchorTag); + + // normal cases + text = text.replace(/\[((?:\[[^\]]*]|[^\[\]])*)]()[ \t]*\([ \t]??(?:[ \t]*((["'])([^"]*?)\5))?[ \t]?\)/g, writeAnchorTag); // handle reference-style shortcuts: [link text] // These must come last in case you've also got [link test][1] // or [link test](/foo) - text = text.replace(/(\[([^\[\]]+)])()()()()()/g, writeAnchorTag); + text = text.replace(/\[([^\[\]]+)]()()()()()/g, writeAnchorTag); // Lastly handle GithubMentions if option is enabled if (options.ghMentions) { diff --git a/src/subParsers/images.js b/src/subParsers/images.js index 201ad24..3dba06b 100644 --- a/src/subParsers/images.js +++ b/src/subParsers/images.js @@ -6,7 +6,8 @@ showdown.subParser('images', function (text, options, globals) { text = globals.converter._dispatch('images.before', text, options, globals); - var inlineRegExp = /!\[(.*?)]\s?\([ \t]*()?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(['"])(.*?)\6[ \t]*)?\)/g, + var inlineRegExp = /!\[([^\]]*?)][ \t]*()\([ \t]??(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(["'])([^"]*?)\6)?[ \t]?\)/g, + crazyRegExp = /!\[([^\]]*?)][ \t]*()\([ \t]?<([^>]*)>(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(?:(["'])([^"]*?)\6))?[ \t]?\)/g, referenceRegExp = /!\[([^\]]*?)] ?(?:\n *)?\[(.*?)]()()()()()/g, refShortcutRegExp = /!\[([^\[\]]+)]()()()()()/g; @@ -21,8 +22,11 @@ showdown.subParser('images', function (text, options, globals) { if (!title) { title = ''; } + // Special case for explicit empty url + if (wholeMatch.search(/\(? ?(['"].*['"])?\)$/m) > -1) { + url = ''; - if (url === '' || url === null) { + } else if (url === '' || url === null) { if (linkId === '' || linkId === null) { // lower-case and turn embedded newlines into spaces linkId = altText.toLowerCase().replace(/ ?\n/g, ' '); @@ -76,6 +80,10 @@ showdown.subParser('images', function (text, options, globals) { text = text.replace(referenceRegExp, writeImageTag); // Next, handle inline images: ![alt text](url =x "optional title") + // cases with crazy urls like ./image/cat1).png + text = text.replace(crazyRegExp, writeImageTag); + + // normal cases text = text.replace(inlineRegExp, writeImageTag); // handle reference-style shortcuts: |[img text] diff --git a/test/cases/anchors-followed-by-brakets.html b/test/cases/anchors-followed-by-brakets.html new file mode 100644 index 0000000..1b1abac --- /dev/null +++ b/test/cases/anchors-followed-by-brakets.html @@ -0,0 +1,4 @@ +

This is a link (some other text)

+

This is a link (some other text)

+

This is a link (some other text)

+

This is a link (some other text)

\ No newline at end of file diff --git a/test/cases/anchors-followed-by-brakets.md b/test/cases/anchors-followed-by-brakets.md new file mode 100644 index 0000000..974fdd3 --- /dev/null +++ b/test/cases/anchors-followed-by-brakets.md @@ -0,0 +1,7 @@ +This is a [link](https://en.wikipedia.org/wiki/Textile) (some other text) + +This is a [link](https://en.wikipedia.org/wiki/Textile_(markup) (some other text) + +This is a [link](https://en.wikipedia.org/wiki/Textile_(markup_language)) (some other text) + +This is a [link](https://en.wikipedia.org/wiki/Textile_(markup_language)/foo) (some other text) \ No newline at end of file diff --git a/test/cases/images-followed-by-brackets.html b/test/cases/images-followed-by-brackets.html new file mode 100644 index 0000000..20e2292 --- /dev/null +++ b/test/cases/images-followed-by-brackets.html @@ -0,0 +1,2 @@ +

image link(some text between brackets)

+

image link(some text between brackets)

\ No newline at end of file diff --git a/test/cases/images-followed-by-brackets.md b/test/cases/images-followed-by-brackets.md new file mode 100644 index 0000000..1481067 --- /dev/null +++ b/test/cases/images-followed-by-brackets.md @@ -0,0 +1,3 @@ +![image link](<./image/cat1.png>)(some text between brackets) + +![image link](<./image/cat(1).png>)(some text between brackets) diff --git a/test/issues/#390.brackets-in-URL-break-images.html b/test/issues/#390.brackets-in-URL-break-images.html new file mode 100644 index 0000000..d5290b4 --- /dev/null +++ b/test/issues/#390.brackets-in-URL-break-images.html @@ -0,0 +1,4 @@ +

This is an image

+

This is another image

+

image link

+

image link

diff --git a/test/issues/#390.brackets-in-URL-break-images.md b/test/issues/#390.brackets-in-URL-break-images.md new file mode 100644 index 0000000..6340f75 --- /dev/null +++ b/test/issues/#390.brackets-in-URL-break-images.md @@ -0,0 +1,9 @@ +This is an ![image][] + +[image]: ./image/cat(1).png + +This is another ![image](./image/cat(1).png) + +[![image link](./image/cat(1).png)](http://example.com) + +[![image link](<./image/cat1).png>)](http://example.com) diff --git a/test/issues/#390.brackets-in-URL-break-links.html b/test/issues/#390.brackets-in-URL-break-links.html index 46379c8..acff8f9 100644 --- a/test/issues/#390.brackets-in-URL-break-links.html +++ b/test/issues/#390.brackets-in-URL-break-links.html @@ -1,2 +1,3 @@

This is a link.

This is another link.

+

link

diff --git a/test/issues/#390.brackets-in-URL-break-links.md b/test/issues/#390.brackets-in-URL-break-links.md index 4a3e2c1..338fcdd 100644 --- a/test/issues/#390.brackets-in-URL-break-links.md +++ b/test/issues/#390.brackets-in-URL-break-links.md @@ -3,3 +3,5 @@ This is a [link][]. [link]: https://en.wikipedia.org/wiki/Textile_(markup_language) "Textile" This is another [link](https://en.wikipedia.org/wiki/Textile_(markup_language) "Textile"). + +[link](<./image/cat1).png> "title") diff --git a/test/issues/URLs-with-multiple-parenthesis.html b/test/issues/URLs-with-multiple-parenthesis.html new file mode 100644 index 0000000..166a9d3 --- /dev/null +++ b/test/issues/URLs-with-multiple-parenthesis.html @@ -0,0 +1,5 @@ +

link

+

link

+

image

+

image

+

image

diff --git a/test/issues/URLs-with-multiple-parenthesis.md b/test/issues/URLs-with-multiple-parenthesis.md new file mode 100644 index 0000000..5d32457 --- /dev/null +++ b/test/issues/URLs-with-multiple-parenthesis.md @@ -0,0 +1,9 @@ +[link](<./images(1)/cat(1).png>) + +[link](<./images(1)/cat(1).png> "title") + +![image](<./images(1)/cat(1).png>) + +![image](<./images(1)/cat(1).png> "title") + +![image](<./images(1)/cat(1).png> =800x600 "title") diff --git a/test/issues/crazy-urls.html b/test/issues/crazy-urls.html new file mode 100644 index 0000000..d5a1f3a --- /dev/null +++ b/test/issues/crazy-urls.html @@ -0,0 +1,14 @@ +

my cat

+

my cat

+

foo

+

foo

+

foo

+

foo

+

empty

+

empty

+

empty

+

empty

+

empty

+

empty

+

empty

+

empty

diff --git a/test/issues/crazy-urls.md b/test/issues/crazy-urls.md new file mode 100644 index 0000000..3299d5b --- /dev/null +++ b/test/issues/crazy-urls.md @@ -0,0 +1,27 @@ +![my cat]() + +[my cat]() + +![foo]() + +![foo]( "title") + +[foo]() + +[foo]( "title") + +![empty](<>) + +[empty](<>) + +![empty](<> "title") + +[empty](<> "title") + +![empty](< >) + +[empty](< >) + +![empty](< > "title") + +[empty](< > "title")