From d13dec251006af745c277d2ada47d85badfdbe0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20P=2E=20Gon=C3=A7alves?= Date: Fri, 17 May 2019 23:10:00 -0300 Subject: [PATCH] Added a hook to change blocks on-the-fly --- Parsedown.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Parsedown.php b/Parsedown.php index ae0cbde..0198f30 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -13,12 +13,15 @@ # # -class Parsedown +class Parsedown { # ~ const version = '1.8.0-beta-7'; + # ~ + protected $texthook = NULL; + # ~ function text($text) @@ -1720,6 +1723,11 @@ class Parsedown $permitRawHtml = false; + // Add a hook for change blocks on the fly + if(is_callable($this->texthook)) { + $Element = call_user_func($this->texthook, $Element); + } + if (isset($Element['text'])) { $text = $Element['text']; @@ -1750,6 +1758,8 @@ class Parsedown } else { + + if (!$permitRawHtml) { $markup .= self::escape($text, true); @@ -1770,6 +1780,13 @@ class Parsedown return $markup; } + /** + * Set callback hool + */ + public function setTextHook($callback) { + $this->texthook = $callback; + } + protected function elements(array $Elements) { $markup = '';