From d7956e3adec12e6067badf8b6c464791760d0296 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sat, 25 Mar 2017 14:28:43 +0000 Subject: [PATCH 1/4] blockmarkup ends on interrupt by newline (CommonMark compliance) --- Parsedown.php | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index f5dd0fa15..e516f6b21 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -683,7 +683,7 @@ protected function blockMarkup($Line) return; } - if (preg_match('/^<(\w*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches)) + if (preg_match('/^<[\/]?+(\w*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches)) { $element = strtolower($matches[1]); @@ -694,7 +694,6 @@ protected function blockMarkup($Line) $Block = array( 'name' => $matches[1], - 'depth' => 0, 'markup' => $Line['text'], ); @@ -730,35 +729,11 @@ protected function blockMarkup($Line) protected function blockMarkupContinue($Line, array $Block) { - if (isset($Block['closed'])) + if (isset($Block['closed']) or isset($Block['interrupted'])) { return; } - if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) # open - { - $Block['depth'] ++; - } - - if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) # close - { - if ($Block['depth'] > 0) - { - $Block['depth'] --; - } - else - { - $Block['closed'] = true; - } - } - - if (isset($Block['interrupted'])) - { - $Block['markup'] .= "\n"; - - unset($Block['interrupted']); - } - $Block['markup'] .= "\n".$Line['body']; return $Block; From 1d0af35f10ed6b7e2a5841d032ac6a1de5b6f939 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sat, 25 Mar 2017 14:47:36 +0000 Subject: [PATCH 2/4] update test to result generated by CommonMark reference parser --- test/data/sparse_html.html | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/data/sparse_html.html b/test/data/sparse_html.html index 9e896274c..6e0213fab 100644 --- a/test/data/sparse_html.html +++ b/test/data/sparse_html.html @@ -1,8 +1,6 @@
line 1 - -line 2 -line 3 - -line 4 +

line 2 +line 3

+

line 4

\ No newline at end of file From 6a4afac0d02218b134b922428e5c659ed9360d36 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Thu, 22 Jun 2017 00:02:03 +0100 Subject: [PATCH 3/4] remove ability for htmlblock to allow paragraph after if it closes on the same line --- Parsedown.php | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index e516f6b21..f6daad2e3 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -515,10 +515,10 @@ protected function blockList($Line) ), ); - if($name === 'ol') + if($name === 'ol') { $listStart = stristr($matches[0], '.', true); - + if($listStart !== '1') { $Block['element']['attributes'] = array('start' => $listStart); @@ -697,32 +697,6 @@ protected function blockMarkup($Line) 'markup' => $Line['text'], ); - $length = strlen($matches[0]); - - $remainder = substr($Line['text'], $length); - - if (trim($remainder) === '') - { - if (isset($matches[2]) or in_array($matches[1], $this->voidElements)) - { - $Block['closed'] = true; - - $Block['void'] = true; - } - } - else - { - if (isset($matches[2]) or in_array($matches[1], $this->voidElements)) - { - return; - } - - if (preg_match('/<\/'.$matches[1].'>[ ]*$/i', $remainder)) - { - $Block['closed'] = true; - } - } - return $Block; } } From c05bff047ad6703b1b4abd58bca9de78f32fa05a Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Thu, 22 Jun 2017 00:03:12 +0100 Subject: [PATCH 4/4] correct test to match CommonMark specified input for output --- test/data/self-closing_html.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/data/self-closing_html.md b/test/data/self-closing_html.md index acb20327d..61d16a39b 100644 --- a/test/data/self-closing_html.md +++ b/test/data/self-closing_html.md @@ -1,12 +1,18 @@
+ paragraph
+ paragraph
+ paragraph
+ paragraph
+ paragraph
+ paragraph \ No newline at end of file