Skip to content

Commit

Permalink
Add support for indent-sensitive Markdown blocks, eg code blocks (#17)
Browse files Browse the repository at this point in the history
Co-authored-by: Nathan Parsons <[email protected]>
  • Loading branch information
Nathan Parsons and N-Parsons authored Jul 27, 2020
1 parent 7f3f749 commit 0a2f4a8
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions markdown-notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) . ' ';

Expand All @@ -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;
}
Expand Down

0 comments on commit 0a2f4a8

Please sign in to comment.