Skip to content

Commit

Permalink
Merge branch '1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
kzykhys committed Jan 23, 2014
2 parents 86053df + 766b431 commit 52d43ec
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/Ciconia/Extension/Gfm/UrlAutoLinkExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,22 @@ public function register(Markdown $markdown)
*/
public function processStandardUrl(Text $text)
{
$text->replace('{(?<!]\(|"|<|>|\[)((?:https?|ftp)://[^\'">\s]+)(?!>|<|\"|\])}', '<\1>');
$hashes = array();

// escape <code>
$text->replace('{<code>.*?</code>}m', function (Text $w) use (&$hashes) {
$md5 = md5($w);
$hashes[$md5] = $w;

return "{gfm-extraction-$md5}";
});

$text->replace('{(?<!]\(|"|<|\[)((?:https?|ftp)://[^\'">\s]+)(?!>|\"|\])}', '<\1>');

/** @noinspection PhpUnusedParameterInspection */
$text->replace('/\{gfm-extraction-([0-9a-f]{32})\}/m', function (Text $w, Text $md5) use (&$hashes) {
return $hashes[(string)$md5];
});
}

/**
Expand Down
4 changes: 3 additions & 1 deletion test/Ciconia/Resources/gfm/link-in-code-span.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Look at: `http://someurl.com` and text.
Look at: `http://someurl.com` and text.

Look at: `url: http://someurl.com` and text.
4 changes: 3 additions & 1 deletion test/Ciconia/Resources/gfm/link-in-code-span.out
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<p>Look at: <code>http://someurl.com</code> and text.</p>
<p>Look at: <code>http://someurl.com</code> and text.</p>

<p>Look at: <code>url: http://someurl.com</code> and text.</p>
3 changes: 3 additions & 0 deletions test/Ciconia/Resources/gfm/link-in-codeblock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
``` php
$validator->validate('http://www.example.com/');
```
2 changes: 2 additions & 0 deletions test/Ciconia/Resources/gfm/link-in-codeblock.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<pre class="prettyprint lang-php"><code>$validator-&gt;validate('http://www.example.com/');
</code></pre>

0 comments on commit 52d43ec

Please sign in to comment.