function _geshifilter_replace_callback in GeSHi Filter for syntax highlighting 5.2
Same name and namespace in other branches
- 6 geshifilter.pages.inc \_geshifilter_replace_callback()
- 7 geshifilter.pages.inc \_geshifilter_replace_callback()
preg_replace_callback callback
File
- ./
geshifilter.pages.inc, line 214
Code
function _geshifilter_replace_callback($match, $format) {
// $match[0]: complete matched string
// $match[1]: tag name
// $match[2]: tag attributes
// $match[3]: tag content
$complete_match = $match[0];
$tag_name = $match[1];
$tag_attributes = $match[2];
$source_code = $match[3];
// Undo linebreak and escaping from preparation phase.
$source_code = decode_entities($source_code);
// Initialize to default settings.
$lang = variable_get('geshifilter_default_highlighting', GESHIFILTER_DEFAULT_PLAINTEXT);
$line_numbering = variable_get('geshifilter_default_line_numbering', GESHIFILTER_LINE_NUMBERS_DEFAULT_NONE);
$linenumbers_start = 1;
// Determine language based on tag name if possible.
list($generic_code_tags, $language_tags, $tag_to_lang) = _geshifilter_get_tags($format);
if (variable_get('geshifilter_enable_php_delimiters', FALSE)) {
$language_tags[] = 'questionmarkphp';
$tag_to_lang['questionmarkphp'] = 'php';
}
if (isset($tag_to_lang[$tag_name])) {
$lang = $tag_to_lang[$tag_name];
}
// Get additional settings from the tag attributes.
$settings = _geshifilter_parse_attributes($tag_attributes, $format);
if (isset($settings['language'])) {
$lang = $settings['language'];
}
if (isset($settings['line_numbering'])) {
$line_numbering = $settings['line_numbering'];
}
if (isset($settings['linenumbers_start'])) {
$linenumbers_start = $settings['linenumbers_start'];
}
if ($lang == GESHIFILTER_DEFAULT_DONOTHING) {
// Do nothing, and return the original.
return $complete_match;
}
if ($lang == GESHIFILTER_DEFAULT_PLAINTEXT) {
// Use plain text 'highlighting'
$lang = 'text';
}
$inline_mode = strpos($source_code, "\n") === FALSE;
// process and return
return geshifilter_process($source_code, $lang, $line_numbering, $linenumbers_start, $inline_mode);
}