mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
resolve #17
This commit is contained in:
parent
4a6bb88239
commit
8ac52a2f30
@ -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,14 +526,20 @@ 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
|
||||
{
|
||||
$element = '<img alt="'.$matches[2].'" src="'.$url.'">';
|
||||
|
@ -1,8 +1,13 @@
|
||||
<p>Here's a <a href="http://parsedown.org">reference link</a>.</p>
|
||||
<p>Here's <a href="http://parsedown.org">one</a> with an alternative syntax.</p>
|
||||
<p>Here's <a href="http://parsedown.org">one</a> on the next line.</p>
|
||||
<p>Here's <a href="http://parsedown.org">one</a> on 2 lines.</p>
|
||||
<p>Here's <a href="http://parsedown.org/tests/">one</a> with a different URL.</p>
|
||||
<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 a <a href="http://parsedown.org">reference link</a>.</p>
|
||||
<p>Here's <a href="http://parsedown.org">one</a> with an alternative syntax.</p>
|
||||
<p>Here's <a href="http://parsedown.org">one</a> on the next line.</p>
|
||||
<p>Here's <a href="http://parsedown.org">one</a> on 2 lines.</p>
|
||||
<p>Here's <a href="http://parsedown.org/tests/">one</a> with a different URL.</p>
|
||||
<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>
|
@ -1,29 +1,40 @@
|
||||
Here's a [reference link][1].
|
||||
|
||||
[1]: http://parsedown.org
|
||||
|
||||
Here's [one] [2] with an alternative syntax.
|
||||
|
||||
[2] :http://parsedown.org
|
||||
|
||||
Here's [one][3] on the next line.
|
||||
[3]: http://parsedown.org
|
||||
|
||||
Here's [one][4] on 2 lines.
|
||||
|
||||
[4]:
|
||||
http://parsedown.org
|
||||
|
||||
Here's [one][5] with a different URL.
|
||||
|
||||
[5]: http://parsedown.org/tests/
|
||||
|
||||
Here's [one][the website] with a semantic name.
|
||||
|
||||
[the 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 a [reference link][1].
|
||||
|
||||
[1]: http://parsedown.org
|
||||
|
||||
Here's [one] [2] with an alternative syntax.
|
||||
|
||||
[2] :http://parsedown.org
|
||||
|
||||
Here's [one][3] on the next line.
|
||||
[3]: http://parsedown.org
|
||||
|
||||
Here's [one][4] on 2 lines.
|
||||
|
||||
[4]:
|
||||
http://parsedown.org
|
||||
|
||||
Here's [one][5] with a different URL.
|
||||
|
||||
[5]: http://parsedown.org/tests/
|
||||
|
||||
Here's [one][website] with a semantic name.
|
||||
|
||||
[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.
|
Loading…
Reference in New Issue
Block a user