From 7ab3c60a77646aa20c5356907ecb0b37cceeb59d Mon Sep 17 00:00:00 2001 From: Emanuil Rusev Date: Tue, 2 Dec 2014 22:23:43 +0200 Subject: [PATCH] improve CommonMark compliance --- Parsedown.php | 21 ++++++++++++++++----- test/data/image_reference.html | 2 +- test/data/image_title.html | 2 +- test/data/inline_link.html | 4 ++-- test/data/special_characters.html | 2 +- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index 0258075..b622d15 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -972,6 +972,7 @@ class Parsedown '*' => array('Emphasis'), '/' => array('Url'), '<' => array('UrlTag', 'EmailTag', 'Tag', 'LessThan'), + '>' => array('GreaterThan'), '[' => array('Link'), '_' => array('Emphasis'), '`' => array('InlineCode'), @@ -981,7 +982,7 @@ class Parsedown # ~ - protected $spanMarkerList = '*_!&[/`~\\'; # # ~ @@ -1132,6 +1133,14 @@ class Parsedown ); } + protected function identifyGreaterThan() + { + return array( + 'markup' => '>', + 'extent' => 1, + ); + } + protected function identifyUrlTag($Excerpt) { if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(https?:[\/]{2}[^\s]+?)>/i', $Excerpt['text'], $matches)) @@ -1175,7 +1184,7 @@ class Parsedown return; } - if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<\/?\w.*?>/', $Excerpt['text'], $matches)) + if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<\/?\w.*?>/s', $Excerpt['text'], $matches)) { return array( 'markup' => $matches[0], @@ -1188,10 +1197,11 @@ class Parsedown { $marker = $Excerpt['text'][0]; - if (preg_match('/^('.$marker.'+)[ ]*(.+?)[ ]*(? strlen($matches[0]), @@ -1267,8 +1277,8 @@ class Parsedown $Element = array( 'name' => 'img', 'attributes' => array( - 'alt' => $Link['text'], 'src' => $url, + 'alt' => $Link['text'], ), ); } @@ -1332,9 +1342,10 @@ class Parsedown protected function readPlainText($text) { - $breakMarker = $this->breaksEnabled ? "\n" : " \n"; + $breakMarker = $this->breaksEnabled ? "\n" : array(" \n", "\\\n"); $text = str_replace($breakMarker, "
\n", $text); + $text = str_replace(" \n", "\n", $text); return $text; } diff --git a/test/data/image_reference.html b/test/data/image_reference.html index b3249cb..6e45cba 100644 --- a/test/data/image_reference.html +++ b/test/data/image_reference.html @@ -1 +1 @@ -

Markdown Logo

\ No newline at end of file +

Markdown Logo

\ No newline at end of file diff --git a/test/data/image_title.html b/test/data/image_title.html index 82c155f..4fc59f6 100644 --- a/test/data/image_title.html +++ b/test/data/image_title.html @@ -1 +1 @@ -

alt

\ No newline at end of file +

alt

\ No newline at end of file diff --git a/test/data/inline_link.html b/test/data/inline_link.html index 2b9e649..226fa53 100644 --- a/test/data/inline_link.html +++ b/test/data/inline_link.html @@ -1,4 +1,4 @@

link and another link

link

-

MD Logo

-

MD Logo and text

\ No newline at end of file +

MD Logo

+

MD Logo and text

\ No newline at end of file diff --git a/test/data/special_characters.html b/test/data/special_characters.html index 8199abc..3b652c3 100644 --- a/test/data/special_characters.html +++ b/test/data/special_characters.html @@ -1,6 +1,6 @@

AT&T has an ampersand in their name

this & that

-

4 < 5 and 6 > 5

+

4 < 5 and 6 > 5

http://example.com/autolink?a=1&b=2

inline link

reference link

\ No newline at end of file