From 44042011755697dd1b8972b6a79c2b87c759660e Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sun, 20 Aug 2017 10:28:46 +0100 Subject: [PATCH] Properly support fenced code block infostring Reference: http://spec.commonmark.org/0.28/#info-string --- Parsedown.php | 6 +++--- test/data/fenced_code_block.html | 3 ++- test/data/fenced_code_block.md | 4 ++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index f5dd0fa15..00f61f36b 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -396,7 +396,7 @@ protected function blockCommentContinue($Line, array $Block) protected function blockFencedCode($Line) { - if (preg_match('/^['.$Line['text'][0].']{3,}[ ]*([\w-]+)?[ ]*$/', $Line['text'], $matches)) + if (preg_match('/^['.$Line['text'][0].']{3,}[ ]*([^`]+)?[ ]*$/', $Line['text'], $matches)) { $Element = array( 'name' => 'code', @@ -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); diff --git a/test/data/fenced_code_block.html b/test/data/fenced_code_block.html index 8bdabba96..ce8dfd0dc 100644 --- a/test/data/fenced_code_block.html +++ b/test/data/fenced_code_block.html @@ -3,4 +3,5 @@ $message = 'fenced code block'; echo $message;
tilde
-
echo 'language identifier';
\ No newline at end of file +
echo 'language identifier';
+
echo 'language identifier with non words';
\ No newline at end of file diff --git a/test/data/fenced_code_block.md b/test/data/fenced_code_block.md index cbed8ebb5..9176ef47a 100644 --- a/test/data/fenced_code_block.md +++ b/test/data/fenced_code_block.md @@ -11,4 +11,8 @@ tilde ```php echo 'language identifier'; +``` + +```c# +echo 'language identifier with non words'; ``` \ No newline at end of file