protected function handleTag_code()
{
if ($this->hasParent('pre')) {
// ignore code blocks inside <pre>
return;
}
if ($this->parser->isStartTag) {
$this->buffer();
} else {
$buffer = $this->unbuffer();
// use as many backticks as needed
preg_match_all('#`+#', $buffer, $matches);
if (!empty($matches[0])) {
rsort($matches[0]);
$ticks = '`';
while (true) {
if (!in_array($ticks, $matches[0])) {
break;
}
$ticks .= '`';
}
} else {
$ticks = '`';
}
if ($buffer[0] == '`' || substr($buffer, -1) == '`') {
$buffer = ' ' . $buffer . ' ';
}
$this->out($ticks . $buffer . $ticks, true);
}
}