You are here

public static function GeshiFilterProcess::highlightStringProcess in GeSHi Filter for syntax highlighting 8

Same name and namespace in other branches
  1. 8.2 src/GeshiFilterProcess.php \Drupal\geshifilter\GeshiFilterProcess::highlightStringProcess()

Geshifilter wrapper for highlight_string() processing of PHP.

Parameters

string $source_code: The source code.

bool $inline_mode: When to use inline styles(TRUE) or a css.

Return value

string The source code after being processed.

1 call to GeshiFilterProcess::highlightStringProcess()
GeshiFilterProcess::processSourceCode in src/GeshiFilterProcess.php
General geshifilter processing function for a chunk of source code.

File

src/GeshiFilterProcess.php, line 24

Class

GeshiFilterProcess
Helpers functions related to processing the source code with geshi.

Namespace

Drupal\geshifilter

Code

public static function highlightStringProcess($source_code, $inline_mode) {

  // Make sure that the source code starts with < ?php and ends with ? >.
  $text = trim($source_code);
  if (substr($text, 0, 5) != '<?php') {
    $source_code = '<?php' . $source_code;
  }
  if (substr($text, -2) != '?>') {
    $source_code = $source_code . '?>';
  }

  // Use the right container.
  $container = $inline_mode ? 'span' : 'div';

  // Process with highlight_string()
  $text = '<' . $container . ' class="codeblock geshifilter">' . highlight_string($source_code, TRUE) . '</' . $container . '>';

  // Remove newlines (added by highlight_string()) to avoid issues with the
  // linebreak filter.
  $text = str_replace("\n", '', $text);
  return $text;
}