From 0a2f4a83d8cddb91a8f19ee4cf9428170e182328 Mon Sep 17 00:00:00 2001 From: Nathan Parsons Date: Mon, 27 Jul 2020 18:12:49 +0100 Subject: [PATCH] Add support for indent-sensitive Markdown blocks, eg code blocks (#17) Co-authored-by: Nathan Parsons --- markdown-notices.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/markdown-notices.php b/markdown-notices.php index d801f5e..3829e2a 100644 --- a/markdown-notices.php +++ b/markdown-notices.php @@ -45,16 +45,10 @@ public function onMarkdownInitialized(Event $event) $this->level_classes = $this->config->get('plugins.markdown-notices.level_classes'); $this->base_classes = $this->config->get('plugins.markdown-notices.base_classes'); - if (preg_match('/^(!{1,'.count($this->level_classes).'})[ ]+(.*)/', $Line['text'], $matches)) + if (preg_match('/^(!{1,'.count($this->level_classes).'}) (.*)/', $Line['text'], $matches)) { $level = strlen($matches[1]) - 1; - // if we have more levels than we support - if ($level > count($this->level_classes)-1) - { - return; - } - $text = $matches[2]; $base_classes = (empty($this->base_classes)) ? '' : str_replace(',', ' ', $this->base_classes) . ' '; @@ -79,9 +73,9 @@ public function onMarkdownInitialized(Event $event) return; } - if ($Line['text'][0] === '!' and preg_match('/^(!{1,'.count($this->level_classes).'})(.*)/', $Line['text'], $matches)) + if (preg_match('/^(!{1,'.count($this->level_classes).'}) ?(.*)/', $Line['text'], $matches)) { - $Block['element']['text'] []= ltrim($matches[2]); + $Block['element']['text'] []= $matches[2]; return $Block; }