From 408cb5c21fb77fbd059bd75de594f619cc314898 Mon Sep 17 00:00:00 2001 From: Emanuil Rusev Date: Thu, 16 Jan 2014 23:43:12 +0200 Subject: [PATCH] code block doesn't have to use regex --- Parsedown.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index 1263574..ff55e5b 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -272,8 +272,10 @@ class Parsedown # code block - if (preg_match('/^[ ]{4}(.*)/', $line, $matches)) + if (isset($line[3]) and $line[3] === ' ' and $line[2] === ' ' and $line[1] === ' ') { + $code_line = substr($line, 4); + if ($element['type'] === 'code block') { if (isset($element['interrupted'])) @@ -283,7 +285,7 @@ class Parsedown unset ($element['interrupted']); } - $element['text'] .= "\n".$matches[1]; + $element['text'] .= "\n".$code_line; } else { @@ -291,7 +293,7 @@ class Parsedown $element = array( 'type' => 'code block', - 'text' => $matches[1], + 'text' => $code_line, ); }