From 7b3c02cece02ba3206f36a42b46eb82e5f75cfdb Mon Sep 17 00:00:00 2001 From: maxlysenko Date: Thu, 24 Mar 2016 10:03:40 +0300 Subject: [PATCH] A way to override default Parsedown behavior As discussed in #736 It's possible to override default Parsedown processing if the new `tag` for existing `type` will be inserted into the array in higher position then the standard tag we want to override. --- .../Common/Markdown/ParsedownGravTrait.php | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index 6610e056b..c66629408 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -63,9 +63,13 @@ protected function init($page, $defaults) * @param $type * @param $tag */ - public function addBlockType($type, $tag, $continuable = false, $completable = false) + public function addBlockType($type, $tag, $continuable = false, $completable = false, $index = null) { - $this->BlockTypes[$type] [] = $tag; + if (!isset($index)) { + $this->BlockTypes[$type] [] = $tag; + } else { + array_splice($this->BlockTypes[$type], $index, 0, $tag); + } if ($continuable) { $this->continuable_blocks[] = $tag; @@ -82,10 +86,17 @@ public function addBlockType($type, $tag, $continuable = false, $completable = f * @param $type * @param $tag */ - public function addInlineType($type, $tag) + public function addInlineType($type, $tag, $index = null) { - $this->InlineTypes[$type] [] = $tag; - $this->inlineMarkerList .= $type; + if (!isset($index)) { + $this->InlineTypes[$type] [] = $tag; + } else { + array_splice($this->InlineTypes[$type], $index, 0, $tag); + } + + if (strpos($this->inlineMarkerList, $type) === false) { + $this->inlineMarkerList .= $type; + } } /**