From 700b5ddbffa2ac6ce78f28b6646773a818d32f5b Mon Sep 17 00:00:00 2001 From: Won-Kyu Park Date: Thu, 27 Feb 2014 23:47:00 +0900 Subject: [PATCH] match balanced parens in URLs to resolve #126 * match balanced parens using recursive pattern * match quoted title correctly --- Parsedown.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index d2501a0..8cd6733 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -1020,13 +1020,13 @@ class Parsedown $remainingText = substr($text, $offset); - if ($remainingText[0] === '(' and preg_match('/\([ ]*(.*?)(?:[ ]+[\'"](.+?)[\'"])?[ ]*\)/', $remainingText, $matches)) + if ($remainingText[0] === '(' and preg_match('/^\([ ]*((?:[^()\s]+|(\((?:[^()\s]+|(?2))*\)))+)(?:[ ]+([\'"])(.+?)\\3)?[ ]*\)/', $remainingText, $matches)) { $element['link'] = $matches[1]; - if (isset($matches[2])) + if (isset($matches[4])) { - $element['title'] = $matches[2]; + $element['title'] = $matches[4]; } $offset += strlen($matches[0]);