From 9fa8f87f20faa7ac92de2601566976d66221e2bd Mon Sep 17 00:00:00 2001 From: Floris Date: Thu, 4 Feb 2016 11:42:43 +0100 Subject: [PATCH] Allow custom content function for code span Just like the option `$code_block_content_func`, but now for code-span. Can be used to prevent the default `htmlspecialchars` or do some kind of other logic to convert the code to html. --- Michelf/Markdown.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index 68bb558..20fe11a 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -67,6 +67,9 @@ class Markdown implements MarkdownInterface { # Optional function for converting code block content to HTML public $code_block_content_func = null; + + # Optional function for converting code span content to HTML. + public $code_span_content_func = null; # Class attribute to toggle "enhanced ordered list" behaviour # setting this to true will allow ordered lists to start from the index @@ -1045,7 +1048,11 @@ class Markdown implements MarkdownInterface { # # Create a code span markup for $code. Called from handleSpanToken. # - $code = htmlspecialchars(trim($code), ENT_NOQUOTES); + if ($this->code_span_content_func) { + $code = call_user_func($this->code_span_content_func, $code); + } else { + $code = htmlspecialchars(trim($code), ENT_NOQUOTES); + } return $this->hashPart("$code"); }