diff --git a/src/Ciconia/Extension/Gfm/UrlAutoLinkExtension.php b/src/Ciconia/Extension/Gfm/UrlAutoLinkExtension.php index 35bc58e..0cbe546 100644 --- a/src/Ciconia/Extension/Gfm/UrlAutoLinkExtension.php +++ b/src/Ciconia/Extension/Gfm/UrlAutoLinkExtension.php @@ -29,7 +29,22 @@ public function register(Markdown $markdown) */ public function processStandardUrl(Text $text) { - $text->replace('{(?|\[)((?:https?|ftp)://[^\'">\s]+)(?!>|<|\"|\])}', '<\1>'); + $hashes = array(); + + // escape + $text->replace('{.*?}m', function (Text $w) use (&$hashes) { + $md5 = md5($w); + $hashes[$md5] = $w; + + return "{gfm-extraction-$md5}"; + }); + + $text->replace('{(?\s]+)(?!>|\"|\])}', '<\1>'); + + /** @noinspection PhpUnusedParameterInspection */ + $text->replace('/\{gfm-extraction-([0-9a-f]{32})\}/m', function (Text $w, Text $md5) use (&$hashes) { + return $hashes[(string)$md5]; + }); } /** diff --git a/test/Ciconia/Resources/gfm/link-in-code-span.md b/test/Ciconia/Resources/gfm/link-in-code-span.md index 39f016b..25f772b 100644 --- a/test/Ciconia/Resources/gfm/link-in-code-span.md +++ b/test/Ciconia/Resources/gfm/link-in-code-span.md @@ -1 +1,3 @@ -Look at: `http://someurl.com` and text. \ No newline at end of file +Look at: `http://someurl.com` and text. + +Look at: `url: http://someurl.com` and text. \ No newline at end of file diff --git a/test/Ciconia/Resources/gfm/link-in-code-span.out b/test/Ciconia/Resources/gfm/link-in-code-span.out index b65a19f..091784e 100644 --- a/test/Ciconia/Resources/gfm/link-in-code-span.out +++ b/test/Ciconia/Resources/gfm/link-in-code-span.out @@ -1 +1,3 @@ -

Look at: http://someurl.com and text.

\ No newline at end of file +

Look at: http://someurl.com and text.

+ +

Look at: url: http://someurl.com and text.

\ No newline at end of file diff --git a/test/Ciconia/Resources/gfm/link-in-codeblock.md b/test/Ciconia/Resources/gfm/link-in-codeblock.md new file mode 100644 index 0000000..139e92d --- /dev/null +++ b/test/Ciconia/Resources/gfm/link-in-codeblock.md @@ -0,0 +1,3 @@ +``` php +$validator->validate('http://www.example.com/'); +``` \ No newline at end of file diff --git a/test/Ciconia/Resources/gfm/link-in-codeblock.out b/test/Ciconia/Resources/gfm/link-in-codeblock.out new file mode 100644 index 0000000..c784e37 --- /dev/null +++ b/test/Ciconia/Resources/gfm/link-in-codeblock.out @@ -0,0 +1,2 @@ +
$validator->validate('http://www.example.com/');
+
\ No newline at end of file