diff --git a/Parsedown.php b/Parsedown.php index ce368e5..f4e0ead 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -399,11 +399,16 @@ class Parsedown # reference - if (preg_match('/^\[(.+?)\]:[ ]*([^ ]+)/', $deindented_line, $matches)) + if (preg_match('/^\[(.+?)\]:\s*([^\s]+)(?:\s+["\'\(](.+)["\'\)])?/', $deindented_line, $matches)) { $label = strtolower($matches[1]); - $this->reference_map[$label] = trim($matches[2], '<>');; + $this->reference_map[$label] = trim($matches[2], '<>'); + + if (isset($matches[3])) + { + $this->reference_map[$label.":title"] = $matches[3]; + } continue 2; } @@ -631,7 +636,7 @@ class Parsedown # inline link / inline image (recursive) - if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)(\[((?:[^\[\]]|(?2))*)\])\((.*?)\)/', $text, $matches, PREG_SET_ORDER)) + if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)(\[((?:[^\[\]]|(?2))*)\])\((.*?)(?:\s+["\'\(](.*?)["\'\)])?\)/', $text, $matches, PREG_SET_ORDER)) { foreach ($matches as $matches) { @@ -647,7 +652,14 @@ class Parsedown { $element_text = $this->parse_span_elements($matches[3]); - $element = ''.$element_text.''; + if (isset($matches[5])) + { + $element = ''.$element_text.''; + } + else + { + $element = ''.$element_text.''; + } } # ~ @@ -688,7 +700,14 @@ class Parsedown { $element_text = $this->parse_span_elements($matches[2]); - $element = ''.$element_text.''; + if (isset($this->reference_map[$link_definition.":title"])) + { + $element = ''.$element_text.''; + } + else + { + $element = ''.$element_text.''; + } } # ~ diff --git a/tests/data/implicit_reference.html b/tests/data/implicit_reference.html index 4565680..209b85e 100644 --- a/tests/data/implicit_reference.html +++ b/tests/data/implicit_reference.html @@ -1,2 +1,3 @@

an implicit reference link

-

an implicit reference link with an empty link definition

\ No newline at end of file +

an implicit reference link with an empty link definition

+

an explicit reference link with a title

\ No newline at end of file diff --git a/tests/data/implicit_reference.md b/tests/data/implicit_reference.md index 96e5ff4..d128826 100644 --- a/tests/data/implicit_reference.md +++ b/tests/data/implicit_reference.md @@ -2,4 +2,8 @@ an [implicit] reference link [implicit]: http://example.com -an [implicit][] reference link with an empty link definition \ No newline at end of file +an [implicit][] reference link with an empty link definition + +an [explicit][example] reference link with a title + +[example]: http://example.com "Example" \ No newline at end of file diff --git a/tests/data/inline_link.html b/tests/data/inline_link.html index 1ff9f1b..020ac75 100644 --- a/tests/data/inline_link.html +++ b/tests/data/inline_link.html @@ -1,3 +1,4 @@

link

link

+

link with title

MD Logo

\ No newline at end of file diff --git a/tests/data/inline_link.md b/tests/data/inline_link.md index 554de0e..041cd11 100644 --- a/tests/data/inline_link.md +++ b/tests/data/inline_link.md @@ -2,4 +2,6 @@ [`link`](http://example.com) +[link with title](http://example.com "Example") + [![MD Logo](http://parsedown.org/md.png)](http://example.com) \ No newline at end of file