You are here

function Markdown_Parser::encodeAmpsAndAngles in Markdown 5

Same name and namespace in other branches
  1. 6 markdown.php \Markdown_Parser::encodeAmpsAndAngles()
1 call to Markdown_Parser::encodeAmpsAndAngles()
Markdown_Parser::encodeAttribute in ./markdown.php

File

./markdown.php, line 1393

Class

Markdown_Parser

Code

function encodeAmpsAndAngles($text) {

  #

  # Smart processing for ampersands and angle brackets that need to

  # be encoded. Valid character entities are left alone unless the

  # no-entities mode is set.

  #
  if ($this->no_entities) {
    $text = str_replace('&', '&', $text);
  }
  else {

    # Ampersand-encoding based entirely on Nat Irons's Amputator

    # MT plugin: <http://bumppo.net/projects/amputator/>
    $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\\w+);)/', '&amp;', $text);
  }

  # Encode remaining <'s
  $text = str_replace('<', '&lt;', $text);
  return $text;
}