From 5aad1d42d22d7a3ae0df1b45524e4ea617230c4f Mon Sep 17 00:00:00 2001
From: Emanuil <4thmail@gmail.com>
Date: Thu, 25 Jul 2013 01:33:40 +0300
Subject: [PATCH] inline links should work with images
---
Parsedown.php | 8 ++++----
tests/data/inline_link.html | 2 ++
tests/data/inline_link.md | 3 +++
3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/Parsedown.php b/Parsedown.php
index 5ea2e74..9369c91 100755
--- a/Parsedown.php
+++ b/Parsedown.php
@@ -558,19 +558,19 @@ class Parsedown
# Inline Link / Image
- if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)\[(.*?)\]\((.*?)\)/', $text, $matches, PREG_SET_ORDER)) # inline
+ if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)(\[((?:[^][]+|(?2))*)\])\((.*?)\)/', $text, $matches, PREG_SET_ORDER)) # inline
{
foreach ($matches as $matches)
{
if ($matches[1]) # image
{
- $element = '';
+ $element = '
';
}
else
{
- $element_text = $this->parse_inline_elements($matches[2]);
+ $element_text = $this->parse_inline_elements($matches[3]);
- $element = ''.$element_text.'';
+ $element = ''.$element_text.'';
}
$element_text = $this->parse_inline_elements($matches[1]);
diff --git a/tests/data/inline_link.html b/tests/data/inline_link.html
index e69de29..4ad6eb7 100644
--- a/tests/data/inline_link.html
+++ b/tests/data/inline_link.html
@@ -0,0 +1,2 @@
+
Here's a link.
+ \ No newline at end of file diff --git a/tests/data/inline_link.md b/tests/data/inline_link.md index e69de29..52979f4 100644 --- a/tests/data/inline_link.md +++ b/tests/data/inline_link.md @@ -0,0 +1,3 @@ +Here's a [link](http://parsedown.org). + +Here's an image link: [![MD Logo](http://parsedown.org/md.png)](http://daringfireball.net/projects/markdown/). \ No newline at end of file