You are here

function _geshifilter_process in GeSHi Filter for syntax highlighting 7

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

geshifilter_filter callback for processing input text.

1 call to _geshifilter_process()
geshifilter_process_callback in ./geshifilter.module
Process callback for the GeSHi filter.

File

./geshifilter.pages.inc, line 234

Code

function _geshifilter_process($format, $text) {

  // load GeSHi library (if not already)
  $geshi_library = libraries_load('geshi');
  if (!$geshi_library['loaded']) {
    drupal_set_message($geshi_library['error 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, function ($match) use ($format) {
    return _geshifilter_replace_callback($match, $format);
  }, $text);
  return $text;
}