You are here

function codefilter_prism_escape in Code Filter 7

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 $attributes: (optional) The HTML attributes of the code block.

Return value

string The escaped string.

2 calls to codefilter_prism_escape()
_codefilter_prism_escape_code_tag_callback in modules/codefilter_prism/codefilter_prism.module
Callback to escape content of <code> elements.
_codefilter_prism_escape_php_tag_callback in modules/codefilter_prism/codefilter_prism.module
Callback to escape content of <?php ?>, [?php ?], <% %>, and [% %] elements.

File

modules/codefilter_prism/codefilter_prism.module, line 190
Text filter for highlighting PHP source code.

Code

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

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

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

  // Prepare the class HTML attribute for the prism_code_filter tag.
  if (!empty($attributes)) {
    $attributes = ' ' . $attributes;
  }

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