From 1df2655b8b2bb826748f0e20598af96655ae0f2e Mon Sep 17 00:00:00 2001 From: Mario Konrad Date: Thu, 16 Apr 2015 21:56:41 +0200 Subject: [PATCH] Optional code block content function added. --- Michelf/MarkdownExtra.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Michelf/MarkdownExtra.php b/Michelf/MarkdownExtra.php index 3107a79..7fd8038 100644 --- a/Michelf/MarkdownExtra.php +++ b/Michelf/MarkdownExtra.php @@ -43,6 +43,9 @@ class MarkdownExtra extends \Michelf\Markdown { # setting this to true will put attributes on the `pre` tag instead. public $code_attr_on_pre = false; + # Optional content function for code blocks + public $code_block_content_func = null; + # Predefined abbreviations. public $predef_abbr = array(); @@ -1318,6 +1321,12 @@ class MarkdownExtra extends \Michelf\Markdown { $classname =& $matches[2]; $attrs =& $matches[3]; $codeblock = $matches[4]; + + if ($this->code_block_content_func) { + $codeblock = call_user_func($this->code_block_content_func, $codeblock, $classname); + return "\n\n".$this->hashBlock($codeblock)."\n\n"; + } + $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); $codeblock = preg_replace_callback('/^\n+/', array($this, '_doFencedCodeBlocks_newlines'), $codeblock);