You are here

function MarkdownExtra_Parser::_doFencedCodeBlocks_callback in Markdown 6

Same name and namespace in other branches
  1. 5 markdown.php \MarkdownExtra_Parser::_doFencedCodeBlocks_callback()

File

./markdown.php, line 2947

Class

MarkdownExtra_Parser

Code

function _doFencedCodeBlocks_callback($matches) {
  $classname =& $matches[2];
  $attrs =& $matches[3];
  $codeblock = $matches[4];
  $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);
  $codeblock = preg_replace_callback('/^\\n+/', array(
    &$this,
    '_doFencedCodeBlocks_newlines',
  ), $codeblock);
  if ($classname != "") {
    if ($classname[0] == '.') {
      $classname = substr($classname, 1);
    }
    $attr_str = ' class="' . $this->code_class_prefix . $classname . '"';
  }
  else {
    $attr_str = $this
      ->doExtraAttributes($this->code_attr_on_pre ? "pre" : "code", $attrs);
  }
  $pre_attr_str = $this->code_attr_on_pre ? $attr_str : '';
  $code_attr_str = $this->code_attr_on_pre ? '' : $attr_str;
  $codeblock = "<pre{$pre_attr_str}><code{$code_attr_str}>{$codeblock}</code></pre>";
  return "\n\n" . $this
    ->hashBlock($codeblock) . "\n\n";
}