function codefilter_process_code in Code Filter 7
Same name and namespace in other branches
- 5 codefilter.module \codefilter_process_code()
- 6 codefilter.module \codefilter_process_code()
Processes chunks of escaped code into HTML.
1 call to codefilter_process_code()
- _codefilter_process_code_callback in ./
codefilter.module - Callback to replace content of the <code> elements.
File
- ./
codefilter.module, line 48 - Text filter for highlighting PHP source code.
Code
function codefilter_process_code($text, $attributes = NULL) {
// Undo linebreak escaping.
$text = str_replace(' ', "\n", $text);
// Inline or block level piece?
$multiline = strpos($text, "\n") !== FALSE;
// Note, pay attention to odd preg_replace-with-/e behaviour on slashes.
$text = preg_replace("/^\n/", '', preg_replace('@</?(br|p)\\s*/?>@', '', str_replace('\\"', '"', $text)));
// Trim leading and trailing linebreaks.
$text = trim($text, "\n");
// Escape newlines.
$text = nl2br($text);
// PHP code in regular code.
$text = preg_replace_callback('/<\\?php.+?\\?>/s', 'codefilter_process_php_inline', $text);
$text = '<code' . $attributes . '>' . codefilter_fix_spaces(str_replace(' ', ' ', $text)) . '</code>';
$text = $multiline ? '<div class="codeblock">' . $text . '</div>' : $text;
// Remove newlines to avoid clashing with the linebreak filter.
return str_replace("\n", '', $text);
}