From 64f82e1e2abffcb39041cb4891ced37c4791d857 Mon Sep 17 00:00:00 2001
From: Emanuil <4thmail@gmail.com>
Date: Fri, 20 Sep 2013 01:12:40 +0300
Subject: [PATCH] inline links should get parsed before reference links
---
Parsedown.php | 62 +++++++++++++++++++++++++--------------------------
1 file changed, 31 insertions(+), 31 deletions(-)
diff --git a/Parsedown.php b/Parsedown.php
index 447a7d0..134197b 100755
--- a/Parsedown.php
+++ b/Parsedown.php
@@ -417,6 +417,37 @@ class Parsedown
}
}
+ # Inline Link / Image
+
+ if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)(\[((?:[^][]+|(?2))*)\])\((.*?)\)/', $text, $matches, PREG_SET_ORDER)) # inline
+ {
+ foreach ($matches as $matches)
+ {
+ if ($matches[1]) # image
+ {
+ $element = '';
+ }
+ else
+ {
+ $element_text = $this->parse_inline_elements($matches[3]);
+
+ $element = ''.$element_text.'';
+ }
+
+ $element_text = $this->parse_inline_elements($matches[1]);
+
+ # ~
+
+ $code = "\x1A".'$'.$index;
+
+ $text = str_replace($matches[0], $code, $text);
+
+ $map[$code] = $element;
+
+ $index ++;
+ }
+ }
+
# Reference(d) Link / Image
if ($this->reference_map and strpos($text, '[') !== FALSE and preg_match_all('/(!?)\[(.+?)\](?:\n?[ ]?\[(.*?)\])?/ms', $text, $matches, PREG_SET_ORDER))
@@ -457,37 +488,6 @@ class Parsedown
}
}
- # Inline Link / Image
-
- if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)(\[((?:[^][]+|(?2))*)\])\((.*?)\)/', $text, $matches, PREG_SET_ORDER)) # inline
- {
- foreach ($matches as $matches)
- {
- if ($matches[1]) # image
- {
- $element = '';
- }
- else
- {
- $element_text = $this->parse_inline_elements($matches[3]);
-
- $element = ''.$element_text.'';
- }
-
- $element_text = $this->parse_inline_elements($matches[1]);
-
- # ~
-
- $code = "\x1A".'$'.$index;
-
- $text = str_replace($matches[0], $code, $text);
-
- $map[$code] = $element;
-
- $index ++;
- }
- }
-
if (strpos($text, '<') !== FALSE and preg_match_all('/<((https?|ftp|dict):[^\^\s]+?)>/i', $text, $matches, PREG_SET_ORDER))
{
foreach ($matches as $matches)