You are here

function codefilter_escape in Code Filter 5

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

Escape code blocks during input filter 'prepare'.

Parameters

$text: The string to escape.

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

Return value

The escaped string.

File

./codefilter.module, line 98

Code

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

  // 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(
    '',
    '
',
  ), $text);

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