list($attr, $content) = preg_split('/>/u', $match, 2);
if ($this->syntax == 'sxh') {
$attr = trim($attr);
if ($attr == null) {
// No brush and no options, use "text" with default options.
$attr = 'text';
} elseif (substr($attr, 0, 1) == ";") {
// Options but no brush, add "text" brush.
$attr = 'text' . $attr;
}
} else {
$attr = null;
}
return array($this->syntax, $attr, $content);
}
return false;
}
public function render($mode, &$renderer, $data)
{
if ($mode != 'xhtml') {
return false;
}
if (count($data) == 3) {
list($syntax, $attr, $content) = $data;
if ($syntax == 'sxh') {
$title = '';
$highlight = '';
// Check if there's a title in the $attr string. Block title can't be passed along as a normal parameter to SyntaxHighlighter.
if (preg_match("/title:/i", $attr)) {
// Extract title(s) from $attr string.
$attr_array = explode(";", $attr);
$title_array = preg_grep("/title:/i", $attr_array);
// Extract everything BUT title(s) from $attr string.
$not_title_array = preg_grep("/title:/i", $attr_array, PREG_GREP_INVERT);
$attr = implode(";", $not_title_array);
// If there are multiple titles, use the last one.
$title = array_pop($title_array);
$title = ' title="' . preg_replace("/.*title:\s{0,}(.*)/i", "$1", $title) . '"';
}
// Check highlight attr for lines ranges
if (preg_match("/highlight:/i", $attr, $matches)) {
// Extract highlight from $attr string.
$attr_array = explode(";", $attr);
$highlight_array = preg_grep("/highlight:/i", $attr_array);
// Extract everything BUT highlight from $attr string.
$not_highlight_array = preg_grep("/highlight:/i", $attr_array, PREG_GREP_INVERT);
$attr = implode(";", $not_highlight_array);
// If there are multiple hightlights, use the last one.
$highlight_str = array_pop($highlight_array);
$highlight_str = preg_replace("/.*highlight:\s{0,}(.*)/i", "$1", $highlight_str);
// Remove [ ]
$highlight_str = str_replace(array('[', ']'), '', $highlight_str);
// Process ranges if exists
$highlight_exp = explode(',', $highlight_str);
foreach ($highlight_exp as $highlight_elt) {
if (!empty($highlight)) {
$highlight .= ',';
}
$highlight_elt = trim($highlight_elt);
$highlight_elt_exp = explode('-', $highlight_elt);
if (count($highlight_elt_exp) == 2) {
foreach (range($highlight_elt_exp[0], $highlight_elt_exp[1]) as $key => $lineNumber) {
if ($key > 0) {
$highlight .= ',';
}
$highlight .= $lineNumber;
}
} else {
$highlight .= $highlight_elt;
}
}
$highlight = ' highlight: [' . $highlight . ']';
}
$renderer->doc .= '' . $renderer->_xmlEntities($content) . '
';
} else {
$renderer->file($content);
}
}
return true;
}
}
// vim:ts=4:sw=4:et: