function _syntaxhighlighter_do_filter_prepare in Syntax Highlighter 6
Same name and namespace in other branches
- 6.2 syntaxhighlighter.module \_syntaxhighlighter_do_filter_prepare()
- 7.2 syntaxhighlighter.module \_syntaxhighlighter_do_filter_prepare()
- 7 syntaxhighlighter.module \_syntaxhighlighter_do_filter_prepare()
Replace any '<' and '>' with < and > inside so that any HTML filter will not mess with the code.
Parameters
string $text: the content text to be filtered
Return value
the escape content text
1 call to _syntaxhighlighter_do_filter_prepare()
- syntaxhighlighter_filter in ./
syntaxhighlighter.module - Implements hook_filter()
File
- ./
syntaxhighlighter.module, line 262 - 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(
'<' => '<',
'>' => '>',
));
$at = $close_tag[1] + strlen($close_tag[0]);
}
$output .= substr($text, $at);
return $output;
}