From d7956e3adec12e6067badf8b6c464791760d0296 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sat, 25 Mar 2017 14:28:43 +0000 Subject: [PATCH 1/6] 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/6] 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 be963a6531001b7d87083fb3f77b0df525ebc8db Mon Sep 17 00:00:00 2001 From: Daniel Berthereau Date: Mon, 19 Jun 2017 00:00:00 +0200 Subject: [PATCH 3/6] Added tests for consistency when a markdown follows a markup without blank line. --- test/ParsedownTest.php | 3 ++- test/data/markup_consecutive_one.html | 3 +++ test/data/markup_consecutive_one.md | 4 ++++ test/data/markup_consecutive_one_line.html | 4 ++++ test/data/markup_consecutive_one_line.md | 5 +++++ test/data/markup_consecutive_one_stripped.html | 3 +++ test/data/markup_consecutive_one_stripped.md | 4 ++++ test/data/markup_consecutive_two.html | 3 +++ test/data/markup_consecutive_two.md | 4 ++++ test/data/markup_consecutive_two_lines.html | 4 ++++ test/data/markup_consecutive_two_lines.md | 5 +++++ test/data/markup_consecutive_two_stripped.html | 4 ++++ test/data/markup_consecutive_two_stripped.md | 5 +++++ 13 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 test/data/markup_consecutive_one.html create mode 100644 test/data/markup_consecutive_one.md create mode 100644 test/data/markup_consecutive_one_line.html create mode 100644 test/data/markup_consecutive_one_line.md create mode 100644 test/data/markup_consecutive_one_stripped.html create mode 100644 test/data/markup_consecutive_one_stripped.md create mode 100644 test/data/markup_consecutive_two.html create mode 100644 test/data/markup_consecutive_two.md create mode 100644 test/data/markup_consecutive_two_lines.html create mode 100644 test/data/markup_consecutive_two_lines.md create mode 100644 test/data/markup_consecutive_two_stripped.html create mode 100644 test/data/markup_consecutive_two_stripped.md diff --git a/test/ParsedownTest.php b/test/ParsedownTest.php index 323dace86..bef612b7f 100644 --- a/test/ParsedownTest.php +++ b/test/ParsedownTest.php @@ -10,7 +10,8 @@ final function __construct($name = null, array $data = array(), $dataName = '') parent::__construct($name, $data, $dataName); } - private $dirs, $Parsedown; + private $dirs; + protected $Parsedown; /** * @return array diff --git a/test/data/markup_consecutive_one.html b/test/data/markup_consecutive_one.html new file mode 100644 index 000000000..a0b1fcacd --- /dev/null +++ b/test/data/markup_consecutive_one.html @@ -0,0 +1,3 @@ +
Markup
+

No markdown without blank line if strict compliance, but main processors convert it.

+

Markdown

\ No newline at end of file diff --git a/test/data/markup_consecutive_one.md b/test/data/markup_consecutive_one.md new file mode 100644 index 000000000..7a0077081 --- /dev/null +++ b/test/data/markup_consecutive_one.md @@ -0,0 +1,4 @@ +
Markup
+_No markdown_ without blank line if strict compliance, but **main** processors convert it. + +**Markdown** \ No newline at end of file diff --git a/test/data/markup_consecutive_one_line.html b/test/data/markup_consecutive_one_line.html new file mode 100644 index 000000000..2a301aa86 --- /dev/null +++ b/test/data/markup_consecutive_one_line.html @@ -0,0 +1,4 @@ +
One markup on +two lines
+

Markdown

+

Markdown

\ No newline at end of file diff --git a/test/data/markup_consecutive_one_line.md b/test/data/markup_consecutive_one_line.md new file mode 100644 index 000000000..d40609ac5 --- /dev/null +++ b/test/data/markup_consecutive_one_line.md @@ -0,0 +1,5 @@ +
One markup on +two lines
+_Markdown_ + +**Markdown** \ No newline at end of file diff --git a/test/data/markup_consecutive_one_stripped.html b/test/data/markup_consecutive_one_stripped.html new file mode 100644 index 000000000..eb5136b90 --- /dev/null +++ b/test/data/markup_consecutive_one_stripped.html @@ -0,0 +1,3 @@ +

Stripped markup

+

Markdown

+

Markdown

\ No newline at end of file diff --git a/test/data/markup_consecutive_one_stripped.md b/test/data/markup_consecutive_one_stripped.md new file mode 100644 index 000000000..4189580a7 --- /dev/null +++ b/test/data/markup_consecutive_one_stripped.md @@ -0,0 +1,4 @@ +

Stripped markup

+_Markdown_ + +**Markdown** \ No newline at end of file diff --git a/test/data/markup_consecutive_two.html b/test/data/markup_consecutive_two.html new file mode 100644 index 000000000..efcebcd40 --- /dev/null +++ b/test/data/markup_consecutive_two.html @@ -0,0 +1,3 @@ +
First markup

and second markup on the same line.

+

Markdown

+

Markdown

\ No newline at end of file diff --git a/test/data/markup_consecutive_two.md b/test/data/markup_consecutive_two.md new file mode 100644 index 000000000..bd663ac08 --- /dev/null +++ b/test/data/markup_consecutive_two.md @@ -0,0 +1,4 @@ +
First markup

and second markup on the same line.

+_Markdown_ + +**Markdown** \ No newline at end of file diff --git a/test/data/markup_consecutive_two_lines.html b/test/data/markup_consecutive_two_lines.html new file mode 100644 index 000000000..cfa1463a7 --- /dev/null +++ b/test/data/markup_consecutive_two_lines.html @@ -0,0 +1,4 @@ +
First markup

and partial markup +on two lines.

+

Markdown

+

Markdown

\ No newline at end of file diff --git a/test/data/markup_consecutive_two_lines.md b/test/data/markup_consecutive_two_lines.md new file mode 100644 index 000000000..66318e9bd --- /dev/null +++ b/test/data/markup_consecutive_two_lines.md @@ -0,0 +1,5 @@ +
First markup

and partial markup +on two lines.

+_Markdown_ + +**Markdown** \ No newline at end of file diff --git a/test/data/markup_consecutive_two_stripped.html b/test/data/markup_consecutive_two_stripped.html new file mode 100644 index 000000000..1633678ea --- /dev/null +++ b/test/data/markup_consecutive_two_stripped.html @@ -0,0 +1,4 @@ +

Stripped markup +on two lines

+

Markdown

+

Markdown

\ No newline at end of file diff --git a/test/data/markup_consecutive_two_stripped.md b/test/data/markup_consecutive_two_stripped.md new file mode 100644 index 000000000..8173380e1 --- /dev/null +++ b/test/data/markup_consecutive_two_stripped.md @@ -0,0 +1,5 @@ +

Stripped markup +on two lines

+_Markdown_ + +**Markdown** \ No newline at end of file From 129f807e32104a31134882c9ca32b279350f3db3 Mon Sep 17 00:00:00 2001 From: Daniel Berthereau Date: Thu, 22 Jun 2017 00:00:00 +0200 Subject: [PATCH 4/6] Inverted checks of consistency for markdown following markups. --- test/data/markup_consecutive_one.html | 2 +- test/data/markup_consecutive_one.md | 2 +- test/data/markup_consecutive_one_line.html | 2 +- test/data/markup_consecutive_one_line.md | 2 +- test/data/markup_consecutive_one_stripped.html | 2 +- test/data/markup_consecutive_one_stripped.md | 2 +- test/data/markup_consecutive_two.html | 2 +- test/data/markup_consecutive_two.md | 2 +- test/data/markup_consecutive_two_lines.html | 2 +- test/data/markup_consecutive_two_lines.md | 2 +- test/data/markup_consecutive_two_stripped.html | 2 +- test/data/markup_consecutive_two_stripped.md | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/test/data/markup_consecutive_one.html b/test/data/markup_consecutive_one.html index a0b1fcacd..d4c500541 100644 --- a/test/data/markup_consecutive_one.html +++ b/test/data/markup_consecutive_one.html @@ -1,3 +1,3 @@
Markup
-

No markdown without blank line if strict compliance, but main processors convert it.

+_No markdown_ without blank line for **strict** compliance with CommonMark.

Markdown

\ No newline at end of file diff --git a/test/data/markup_consecutive_one.md b/test/data/markup_consecutive_one.md index 7a0077081..18b4dcb8a 100644 --- a/test/data/markup_consecutive_one.md +++ b/test/data/markup_consecutive_one.md @@ -1,4 +1,4 @@
Markup
-_No markdown_ without blank line if strict compliance, but **main** processors convert it. +_No markdown_ without blank line for **strict** compliance with CommonMark. **Markdown** \ No newline at end of file diff --git a/test/data/markup_consecutive_one_line.html b/test/data/markup_consecutive_one_line.html index 2a301aa86..a89b4fd32 100644 --- a/test/data/markup_consecutive_one_line.html +++ b/test/data/markup_consecutive_one_line.html @@ -1,4 +1,4 @@
One markup on two lines
-

Markdown

+_No markdown_

Markdown

\ No newline at end of file diff --git a/test/data/markup_consecutive_one_line.md b/test/data/markup_consecutive_one_line.md index d40609ac5..daf945a1e 100644 --- a/test/data/markup_consecutive_one_line.md +++ b/test/data/markup_consecutive_one_line.md @@ -1,5 +1,5 @@
One markup on two lines
-_Markdown_ +_No markdown_ **Markdown** \ No newline at end of file diff --git a/test/data/markup_consecutive_one_stripped.html b/test/data/markup_consecutive_one_stripped.html index eb5136b90..ccc01f185 100644 --- a/test/data/markup_consecutive_one_stripped.html +++ b/test/data/markup_consecutive_one_stripped.html @@ -1,3 +1,3 @@

Stripped markup

-

Markdown

+_No markdown_

Markdown

\ No newline at end of file diff --git a/test/data/markup_consecutive_one_stripped.md b/test/data/markup_consecutive_one_stripped.md index 4189580a7..7f8df0c1b 100644 --- a/test/data/markup_consecutive_one_stripped.md +++ b/test/data/markup_consecutive_one_stripped.md @@ -1,4 +1,4 @@

Stripped markup

-_Markdown_ +_No markdown_ **Markdown** \ No newline at end of file diff --git a/test/data/markup_consecutive_two.html b/test/data/markup_consecutive_two.html index efcebcd40..f7e71c7c1 100644 --- a/test/data/markup_consecutive_two.html +++ b/test/data/markup_consecutive_two.html @@ -1,3 +1,3 @@
First markup

and second markup on the same line.

-

Markdown

+_No markdown_

Markdown

\ No newline at end of file diff --git a/test/data/markup_consecutive_two.md b/test/data/markup_consecutive_two.md index bd663ac08..83f3af771 100644 --- a/test/data/markup_consecutive_two.md +++ b/test/data/markup_consecutive_two.md @@ -1,4 +1,4 @@
First markup

and second markup on the same line.

-_Markdown_ +_No markdown_ **Markdown** \ No newline at end of file diff --git a/test/data/markup_consecutive_two_lines.html b/test/data/markup_consecutive_two_lines.html index cfa1463a7..ffa4728c9 100644 --- a/test/data/markup_consecutive_two_lines.html +++ b/test/data/markup_consecutive_two_lines.html @@ -1,4 +1,4 @@
First markup

and partial markup on two lines.

-

Markdown

+_No markdown_

Markdown

\ No newline at end of file diff --git a/test/data/markup_consecutive_two_lines.md b/test/data/markup_consecutive_two_lines.md index 66318e9bd..dc70bb760 100644 --- a/test/data/markup_consecutive_two_lines.md +++ b/test/data/markup_consecutive_two_lines.md @@ -1,5 +1,5 @@
First markup

and partial markup on two lines.

-_Markdown_ +_No markdown_ **Markdown** \ No newline at end of file diff --git a/test/data/markup_consecutive_two_stripped.html b/test/data/markup_consecutive_two_stripped.html index 1633678ea..707d6be93 100644 --- a/test/data/markup_consecutive_two_stripped.html +++ b/test/data/markup_consecutive_two_stripped.html @@ -1,4 +1,4 @@

Stripped markup on two lines

-

Markdown

+_No markdown_

Markdown

\ No newline at end of file diff --git a/test/data/markup_consecutive_two_stripped.md b/test/data/markup_consecutive_two_stripped.md index 8173380e1..af5b7812a 100644 --- a/test/data/markup_consecutive_two_stripped.md +++ b/test/data/markup_consecutive_two_stripped.md @@ -1,5 +1,5 @@

Stripped markup on two lines

-_Markdown_ +_No markdown_ **Markdown** \ 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 5/6] 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 6/6] 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