From 34f521d4aa88c76a9cdf1048c104f127e0e39141 Mon Sep 17 00:00:00 2001 From: Michel Fortin Date: Sat, 17 May 2008 07:15:20 -0400 Subject: [PATCH] Fixed problem with headers and horizontal rules within fenced code blocks. --- PHP Markdown Extra Readme.text | 6 ++++++ markdown.php | 13 ++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/PHP Markdown Extra Readme.text b/PHP Markdown Extra Readme.text index abd6f79..6e76c46 100644 --- a/PHP Markdown Extra Readme.text +++ b/PHP Markdown Extra Readme.text @@ -204,6 +204,12 @@ expected; (3) the output PHP Markdown actually produced. Version History --------------- +Current Extra: + +* Fixed a problem where Markdown headers and horizontal rules were + transformed into their HTML equivalent inside fenced code blocks. + + Extra 1.2: * Added fenced code block syntax which don't require indentation diff --git a/markdown.php b/markdown.php index 88f2e02..be20fff 100644 --- a/markdown.php +++ b/markdown.php @@ -1541,6 +1541,7 @@ class MarkdownExtra_Parser extends Markdown_Parser { "appendFootnotes" => 50, ); $this->block_gamut += array( + "doFencedCodeBlocks" => 5, "doTables" => 15, "doDefLists" => 45, ); @@ -2358,7 +2359,7 @@ class MarkdownExtra_Parser extends Markdown_Parser { } - function doCodeBlocks($text) { + function doFencedCodeBlocks($text) { # # Adding the fenced code block syntax to regular Markdown: # @@ -2387,21 +2388,19 @@ class MarkdownExtra_Parser extends Markdown_Parser { # Closing marker. \1 [ ]* \n }xm', - array(&$this, '_doCodeBlocks_fenced_callback'), $text); - - $text = parent::doCodeBlocks($text); + array(&$this, '_doFencedCodeBlocks_callback'), $text); return $text; } - function _doCodeBlocks_fenced_callback($matches) { + function _doFencedCodeBlocks_callback($matches) { $codeblock = $matches[2]; $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); $codeblock = preg_replace_callback('/^\n+/', - array(&$this, '_doCodeBlocks_fenced_newlines'), $codeblock); + array(&$this, '_doFencedCodeBlocks_newlines'), $codeblock); $codeblock = "
$codeblock
"; return "\n\n".$this->hashBlock($codeblock)."\n\n"; } - function _doCodeBlocks_fenced_newlines($matches) { + function _doFencedCodeBlocks_newlines($matches) { return str_repeat("empty_element_suffix", strlen($matches[0])); }