You are here

function codefilter_escape in Code Filter 7

Same name and namespace in other branches
  1. 5 codefilter.module \codefilter_escape()
  2. 6 codefilter.module \codefilter_escape()

Escape code blocks during input filter 'prepare'.

Parameters

string $text: The string to escape.

string $type: The type of code block, either 'code' or 'php'.

string|null $attributes: (optional) The HTML attributes of the code block.

Return value

string The escaped string.

2 calls to codefilter_escape()
_codefilter_escape_code_tag_callback in ./codefilter.module
Callback to escape content of <code> elements.
_codefilter_escape_php_tag_callback in ./codefilter.module
Callback to escape content of <?php ?>, [?php ?], <% %>, and [% %] elements.

File

./codefilter.module, line 112
Text filter for highlighting PHP source code.

Code

function codefilter_escape($text, $type = 'code', $attributes = NULL) {

  // Note, pay attention to odd preg_replace-with-/e behaviour on slashes.
  $text = check_plain(str_replace('\\"', '"', $text));

  // Protect newlines from line break converter.
  $text = str_replace(array(
    "\r",
    "\n",
  ), array(
    '',
    '&#10;',
  ), $text);

  // Prepare the class HTML attribute for the codefilter tag.
  if (isset($attributes)) {
    $attributes = ' ' . $attributes;
  }

  // Add codefilter escape tags.
  $text = "[codefilter_{$type}{$attributes}]{$text}[/codefilter_{$type}]";
  return $text;
}