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 f5dd0fa..e516f6b 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -683,7 +683,7 @@ class Parsedown 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 @@ class Parsedown $Block = array( 'name' => $matches[1], - 'depth' => 0, 'markup' => $Line['text'], ); @@ -730,35 +729,11 @@ class Parsedown 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 9e89627..6e0213f 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 323dace..bef612b 100644 --- a/test/ParsedownTest.php +++ b/test/ParsedownTest.php @@ -10,7 +10,8 @@ class ParsedownTest extends PHPUnit_Framework_TestCase 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 0000000..a0b1fca --- /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 0000000..7a00770 --- /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 0000000..2a301aa --- /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 0000000..d40609a --- /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 0000000..eb5136b --- /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 0000000..4189580 --- /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 0000000..efcebcd --- /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 0000000..bd663ac --- /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 0000000..cfa1463 --- /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 0000000..66318e9 --- /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 0000000..1633678 --- /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 0000000..8173380 --- /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 a0b1fca..d4c5005 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 7a00770..18b4dcb 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 2a301aa..a89b4fd 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 d40609a..daf945a 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 eb5136b..ccc01f1 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 4189580..7f8df0c 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 efcebcd..f7e71c7 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 bd663ac..83f3af7 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 cfa1463..ffa4728 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 66318e9..dc70bb7 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 1633678..707d6be 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 8173380..af5b781 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 e516f6b..f6daad2 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -515,10 +515,10 @@ class Parsedown ), ); - if($name === 'ol') + if($name === 'ol') { $listStart = stristr($matches[0], '.', true); - + if($listStart !== '1') { $Block['element']['attributes'] = array('start' => $listStart); @@ -697,32 +697,6 @@ class Parsedown '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 acb2032..61d16a3 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