You are here

function _syntaxhighlighter_do_filter_prepare in Syntax Highlighter 7

Same name and namespace in other branches
  1. 6.2 syntaxhighlighter.module \_syntaxhighlighter_do_filter_prepare()
  2. 6 syntaxhighlighter.module \_syntaxhighlighter_do_filter_prepare()
  3. 7.2 syntaxhighlighter.module \_syntaxhighlighter_do_filter_prepare()

Escape the content text in preparation for filtering by replacing all '<' and '>' with &lt; and &gt; inside.

Parameters

string $text: the content text to be filtered

Return value

the escape content text

1 string reference to '_syntaxhighlighter_do_filter_prepare'
syntaxhighlighter_filter_info in ./syntaxhighlighter.module
Implements hook_filter_info()

File

./syntaxhighlighter.module, line 199
Syntax highlight code using the Syntaxhighlighter javascript library. See http://alexgorbatchev.com/wiki/SyntaxHighlighter

Code

function _syntaxhighlighter_do_filter_prepare($text) {
  preg_match_all('/\\{ *syntaxhighlighter *[^}]+\\}|\\{\\/ *syntaxhighlighter *\\}/', $text, $matches, PREG_OFFSET_CAPTURE);
  $output = '';
  $at = 0;
  for ($it = new ArrayIterator($matches[0]); $it
    ->valid(); $it
    ->next()) {
    $open_tag = $it
      ->current();
    $it
      ->next();
    $close_tag = $it
      ->current();
    $output .= substr($text, $at, $open_tag[1] - $at);
    $end = $close_tag[1] + strlen($close_tag[0]);
    $output .= strtr(substr($text, $open_tag[1], $end - $open_tag[1]), array(
      '<' => '&lt;',
      '>' => '&gt;',
    ));
    $at = $close_tag[1] + strlen($close_tag[0]);
  }
  $output .= substr($text, $at);
  return $output;
}