function _geshifilter_prepare_callback in GeSHi Filter for syntax highlighting 7
Same name and namespace in other branches
- 5.2 geshifilter.pages.inc \_geshifilter_prepare_callback()
- 6 geshifilter.pages.inc \_geshifilter_prepare_callback()
_geshifilter_prepare callback for preparing input text. Replaces the code tags brackets with geshifilter specific ones to prevent possible messing up by other filters, e.g. '[python]foo[/python]' to '[geshifilter-python]foo[/geshifilter-python]'. Replaces newlines with " " to prevent issues with the line break filter Escapes the tricky characters like angle brackets with check_plain() to prevent messing up by other filters like the HTML filter.
1 call to _geshifilter_prepare_callback()
- _geshifilter_prepare in ./
geshifilter.pages.inc - geshifilter_filter callback for preparing input text.
File
- ./
geshifilter.pages.inc, line 168
Code
function _geshifilter_prepare_callback($match, $format) {
// $match[0]: complete matched string
// $match[1]: opening bracket ('<' or '[')
// $match[2]: tag
// $match[3] and $match[4]: attributes
// $match[5]: closing bracket
// $match[6]: source code
// $match[7]: closing tag
$tag_name = $match[2];
$tag_attributes = $match[3];
$content = $match[6];
// Decode HTML entities if option has been set
if (geshifilter_decode_entities($format)) {
$content = html_entity_decode($content, ENT_QUOTES);
}
// get the default highlighting mode
$lang = variable_get('geshifilter_default_highlighting', GESHIFILTER_DEFAULT_PLAINTEXT);
if ($lang == GESHIFILTER_DEFAULT_DONOTHING) {
// If the default highlighting mode is GESHIFILTER_DEFAULT_DONOTHING
// and there is no language set (with language tag or language attribute),
// we should not do any escaping in this prepare phase,
// so that other filters can do their thing.
$enabled_languages = _geshifilter_get_enabled_languages();
// Usage of language tag?
list($generic_code_tags, $language_tags, $tag_to_lang) = _geshifilter_get_tags($format);
if (isset($tag_to_lang[$tag_name]) && isset($enabled_languages[$tag_to_lang[$tag_name]])) {
$lang = $tag_to_lang[$tag_name];
}
else {
// Get additional settings from the tag attributes.
$settings = _geshifilter_parse_attributes($tag_attributes, $format);
if ($settings['language'] && isset($enabled_languages[$settings['language']])) {
$lang = $settings['language'];
}
}
// If no language was set: prevent escaping and return original string
if ($lang == GESHIFILTER_DEFAULT_DONOTHING) {
return $match[0];
}
}
// return escaped code block
return '[geshifilter-' . $tag_name . $tag_attributes . ']' . str_replace(array(
"\r",
"\n",
), array(
'',
' ',
), check_plain($content)) . '[/geshifilter-' . $tag_name . ']';
}