Fixed problem with headers and horizontal rules within fenced code blocks.

This commit is contained in:
Michel Fortin 2008-05-17 07:15:20 -04:00
parent c10f487ec9
commit 34f521d4aa
2 changed files with 12 additions and 7 deletions

View file

@ -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

View file

@ -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 = "<pre><code>$codeblock</code></pre>";
return "\n\n".$this->hashBlock($codeblock)."\n\n";
}
function _doCodeBlocks_fenced_newlines($matches) {
function _doFencedCodeBlocks_newlines($matches) {
return str_repeat("<br$this->empty_element_suffix",
strlen($matches[0]));
}