You are here

function geshifilter_geshi_process in GeSHi Filter for syntax highlighting 5.2

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

geshifilter wrapper for GeSHi processing.

2 calls to geshifilter_geshi_process()
GeshiFilterTest::assertGeshiFilterHighlighting in tests/geshifilter.test
Assert function for testing if GeSHi highlighting works
geshifilter_process in ./geshifilter.pages.inc
General geshifilter processing function

File

./geshifilter.pages.inc, line 297

Code

function geshifilter_geshi_process($source_code, $lang, $line_numbering = 0, $linenumbers_start = 1, $inline_mode = FALSE) {

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

  // remove leading/trailing newlines
  $source_code = trim($source_code, "\n\r");

  // create GeSHi object
  $geshi = _geshifilter_geshi_factory($source_code, $lang);

  // CSS mode
  $ccs_mode = variable_get('geshifilter_css_mode', GESHIFILTER_CSS_INLINE);
  if ($ccs_mode == GESHIFILTER_CSS_CLASSES_AUTOMATIC || $ccs_mode == GESHIFILTER_CSS_CLASSES_ONLY) {
    $geshi
      ->enable_classes(TRUE);
  }
  _geshifilter_override_geshi_defaults($geshi, $lang);

  // some more GeSHi settings and parsing
  if ($inline_mode) {

    // inline source code mode
    $geshi
      ->set_header_type(GESHI_HEADER_NONE);
    $source_code = '<span class="geshifilter"><code class="' . $geshi->overall_class . '">' . $geshi
      ->parse_code() . '</code></span>';
  }
  else {

    // block source code mode
    $geshi
      ->set_header_type((int) variable_get('geshifilter_code_container', GESHI_HEADER_PRE));
    if ($line_numbering == 1) {
      $geshi
        ->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
      $geshi
        ->start_line_numbers_at($linenumbers_start);
    }
    elseif ($line_numbering >= 2) {
      $geshi
        ->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, $line_numbering);
      $geshi
        ->start_line_numbers_at($linenumbers_start);
    }
    $source_code = '<div class="geshifilter">' . $geshi
      ->parse_code() . '</div>';
  }
  return $source_code;
}