From 5ad15b87faa2ab10f7cda7593e2e92696fafadd2 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 17 Dec 2015 10:46:44 -0700 Subject: [PATCH] Break out method_exists checks into extendable methods to allow for better pluggability --- Parsedown.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index b0e7094..b04ee4a 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -175,7 +175,7 @@ class Parsedown } else { - if (method_exists($this, 'block'.$CurrentBlock['type'].'Complete')) + if ($this->isBlockCompleteable($CurrentBlock['type'])) { $CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock); } @@ -216,7 +216,7 @@ class Parsedown $Block['identified'] = true; } - if (method_exists($this, 'block'.$blockType.'Continue')) + if ($this->isBlockContinueable($blockType)) { $Block['continuable'] = true; } @@ -245,7 +245,7 @@ class Parsedown # ~ - if (isset($CurrentBlock['continuable']) and method_exists($this, 'block'.$CurrentBlock['type'].'Complete')) + if (isset($CurrentBlock['continuable']) and $this->isBlockCompleteable($CurrentBlock['type'])) { $CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock); } @@ -278,6 +278,19 @@ class Parsedown return $markup; } + # + # Allow for plugin extensibility + # + protected function isBlockContinueable($Type) + { + return method_exists($this, 'block'.$Type.'Continue'); + } + + protected function isBlockCompleteable($Type) + { + return method_exists($this, 'block'.$Type.'Complete'); + } + # # Code @@ -1521,8 +1534,8 @@ class Parsedown 'q', 'rt', 'ins', 'font', 'strong', 's', 'tt', 'sub', 'mark', 'u', 'xm', 'sup', 'nobr', - 'var', 'ruby', - 'wbr', 'span', - 'time', + 'var', 'ruby', + 'wbr', 'span', + 'time', ); }