1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00
This commit is contained in:
Emanuil 2013-08-31 19:55:07 +03:00
parent 4a6bb88239
commit 8ac52a2f30
3 changed files with 64 additions and 42 deletions

View File

@ -81,7 +81,7 @@ class Parsedown
{
foreach ($matches as $matches)
{
$this->reference_map[$matches[1]] = $matches[2];
$this->reference_map[strtolower($matches[1])] = $matches[2];
$text = str_replace($matches[0], '', $text);
}
@ -526,13 +526,19 @@ class Parsedown
# Reference(d) Link / Image
if ($this->reference_map and strpos($text, '[') !== FALSE and preg_match_all('/(!?)\[(.+?)\][ ]?\[(.+?)\]/', $text, $matches, PREG_SET_ORDER))
if ($this->reference_map and strpos($text, '[') !== FALSE and preg_match_all('/(!?)\[(.+?)\](?:[ ]?\[(.*?)\])?/ms', $text, $matches, PREG_SET_ORDER))
{
foreach ($matches as $matches)
{
if (array_key_exists($matches[3], $this->reference_map))
$link_difinition = isset($matches[3]) && $matches[3]
? $matches[3]
: $matches[2]; # implicit
$link_difinition = strtolower($link_difinition);
if (isset($this->reference_map[$link_difinition]))
{
$url = $this->reference_map[$matches[3]];
$url = $this->reference_map[$link_difinition];
if ($matches[1]) # image
{

View File

@ -6,3 +6,8 @@
<p>Here's <a href="http://parsedown.org">one</a> with a semantic name.</p>
<p>Here's [one][404] with no definition.</p>
<p>Here's an image: <img alt="Markdown Logo" src="https://raw.github.com/dcurtis/markdown-mark/master/png/32x20-solid.png"></p>
<p>Here's an <a href="http://google.com">implicit one</a>.</p>
<p>Here's an <a href="http://google.com">implicit one</a>.</p>
<p>Here's an <a href="http://google.com">implicit one</a> with an empty link definition.</p>
<p>Here's a <a href="http://parsedown.org">multiline
one</a> defined on 2 lines.</p>

View File

@ -18,12 +18,23 @@ Here's [one][5] with a different URL.
[5]: http://parsedown.org/tests/
Here's [one][the website] with a semantic name.
Here's [one][website] with a semantic name.
[the website]: http://parsedown.org
[website]: http://parsedown.org
Here's [one][404] with no definition.
Here's an image: ![Markdown Logo][image]
[image]: https://raw.github.com/dcurtis/markdown-mark/master/png/32x20-solid.png
Here's an [implicit one].
Here's an [implicit one].
[implicit one]: http://google.com
Here's an [implicit one][] with an empty link definition.
Here's a [multiline
one][website] defined on 2 lines.