Fixing fenced code blocks to allow classes to be added. Also the newline callback regex seemed to not be working, so I removed the ^ character from before \n.
This commit is contained in:
parent
5e0be6adb4
commit
4a48b4648c
1 changed files with 17 additions and 5 deletions
22
markdown.php
22
markdown.php
|
|
@ -2552,9 +2552,13 @@ class MarkdownExtra_Parser extends Markdown_Parser {
|
|||
(
|
||||
~{3,} # Marker: three tilde or more.
|
||||
)
|
||||
|
||||
# 2: CSS classes
|
||||
\s?(\.[^\n]+)?
|
||||
|
||||
[ ]* \n # Whitespace and newline following marker.
|
||||
|
||||
# 2: Content
|
||||
# 3: Content
|
||||
(
|
||||
(?>
|
||||
(?!\1 [ ]* \n) # Not a closing marker.
|
||||
|
|
@ -2563,18 +2567,26 @@ class MarkdownExtra_Parser extends Markdown_Parser {
|
|||
)
|
||||
|
||||
# Closing marker.
|
||||
\1 [ ]* \n
|
||||
\1
|
||||
|
||||
# 4: CSS classes
|
||||
\s?(\.[^\n]+)?
|
||||
|
||||
# End of line
|
||||
[ ]* \n
|
||||
}xm',
|
||||
array(&$this, '_doFencedCodeBlocks_callback'), $text);
|
||||
|
||||
return $text;
|
||||
}
|
||||
function _doFencedCodeBlocks_callback($matches) {
|
||||
$codeblock = $matches[2];
|
||||
$codeblock = $matches[3];
|
||||
$codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);
|
||||
$codeblock = preg_replace_callback('/^\n+/',
|
||||
$codeblock = preg_replace_callback('/\n+/',
|
||||
array(&$this, '_doFencedCodeBlocks_newlines'), $codeblock);
|
||||
$codeblock = "<pre><code>$codeblock</code></pre>";
|
||||
$class = ! empty($matches[2]) ? $matches[2] : ( ! empty($matches[4]) ? $matches[4] : '');
|
||||
$class = ! empty($class) ? ' class="'.trim($class, '.').'"' : '';
|
||||
$codeblock = "<pre$class><code>$codeblock</code></pre>";
|
||||
return "\n\n".$this->hashBlock($codeblock)."\n\n";
|
||||
}
|
||||
function _doFencedCodeBlocks_newlines($matches) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue