You are here

function _geshifilter_process in GeSHi Filter for syntax highlighting 6

Same name and namespace in other branches
  1. 5.2 geshifilter.pages.inc \_geshifilter_process()
  2. 7 geshifilter.pages.inc \_geshifilter_process()

geshifilter_filter callback for processing input text.

1 call to _geshifilter_process()
geshifilter_filter in ./geshifilter.module
Implementation of hook_filter().

File

./geshifilter.pages.inc, line 212

Code

function _geshifilter_process($format, $text) {

  // load GeSHi library (if not already)
  $geshi_library = _geshifilter_check_geshi_library();
  if (!$geshi_library['success']) {
    drupal_set_message($geshi_library['message'], 'error');
    return $text;
  }

  // get the available tags
  list($generic_code_tags, $language_tags, $tag_to_lang) = _geshifilter_get_tags($format);
  if (in_array(GESHIFILTER_BRACKETS_PHPBLOCK, array_filter(_geshifilter_tag_styles($format)))) {
    $language_tags[] = 'questionmarkphp';
    $tag_to_lang['questionmarkphp'] = 'php';
  }
  $tags = array_merge($generic_code_tags, $language_tags);

  // escape special (regular expression) characters in tags (for tags like 'c++' and 'c#')
  $tags = preg_replace('#(\\+|\\#)#', '\\\\$1', $tags);
  $tags_string = implode('|', $tags);

  // Pattern for matching the prepared "<code>...</code>" stuff
  $pattern = '#\\[geshifilter-(' . $tags_string . ')([^\\]]*)\\](.*?)(\\[/geshifilter-\\1\\])#s';
  $text = preg_replace_callback($pattern, create_function('$match', "return _geshifilter_replace_callback(\$match, {$format});"), $text);
  return $text;
}