Class HTMLPurifier_Lexer

Description

Forgivingly lexes HTML (SGML-style) markup into tokens.

A lexer parses a string of SGML-style markup and converts them into corresponding tokens. It doesn't check for well-formedness, although its internal mechanism may make this automatic (such as the case of HTMLPurifier_Lexer_DOMLex). There are several implementations to choose from.

A lexer is HTML-oriented: it might work with XML, but it's not recommended, as we adhere to a subset of the specification for optimization reasons. This might change in the future. Also, most tokenizers are not expected to handle DTDs or PIs.

This class should not be directly instantiated, but you may use create() to retrieve a default copy of the lexer. Being a supertype, this class does not actually define any implementation, but offers commonly used convenience functions for subclasses.

Located in /lib/core/Parsers/htmlpurifier/HTMLPurifier.standalone.php (line 5897)


	
			
Direct descendents
Class Description
HTMLPurifier_Lexer_PEARSax3 Proof-of-concept lexer that uses the PEAR package XML_HTMLSax3 to parse HTML.
HTMLPurifier_Lexer_DOMLex Parser that uses PHP 5's DOM extension (part of the core).
HTMLPurifier_Lexer_DirectLex Our in-house implementation of a parser.
Variable Summary
Method Summary
static Escaped CDATACallback ( $matches)
static Concrete create ($config $config)
static HTML escapeCDATA ($string $string)
static void escapeCommentedCDATA ( $string)
static void removeIEConditional ( $string)
HTMLPurifier_Lexer __construct ()
void extractBody ( $html)
void normalize ( $html,  $config,  $context)
Parsed parseData ($string $string)
HTMLPurifier_Token tokenizeHTML ($string $string,  $config,  $context)
Variables
mixed $tracksLineNumbers = false (line 5904)

Whether or not this lexer implements line-number/column-number tracking.

If it does, set to true.

  • access: public

Redefined in descendants as:
mixed $_special_entity2str = array(
'"' => '"',
'&' => '&',
'&lt;' => '<',
'&gt;' => '>',
'&#39;' => "'",
'&#039;' => "'",
'&#x27;' => "'"
)
(line 6004)

Most common entity to raw value conversion table for special entities.

  • access: protected
Methods
static method CDATACallback (line 6108)

Callback function for escapeCDATA() that does the work.

  • return: internals of the CDATA section.
  • access: protected
static Escaped CDATACallback ( $matches)
  • $matches
static method create (line 5923)

Retrieves or sets the default Lexer as a Prototype Factory.

By default HTMLPurifier_Lexer_DOMLex will be returned. There are a few exceptions involving special features that only DirectLex implements.

  • return: lexer.
  • access: public
static Concrete create ($config $config)
  • $config $config: Instance of HTMLPurifier_Config
static method escapeCDATA (line 6069)

Translates CDATA sections into regular sections (through escaping).

  • return: with CDATA sections escaped.
  • access: protected
static HTML escapeCDATA ($string $string)
  • $string $string: HTML string to process.
static method escapeCommentedCDATA (line 6080)

Special CDATA case that is especially convoluted for <script>

  • access: protected
static void escapeCommentedCDATA ( $string)
  • $string
static method removeIEConditional (line 6091)

Special Internet Explorer conditional comments should be removed.

  • access: protected
static void removeIEConditional ( $string)
  • $string
Constructor __construct (line 5997)
  • access: public
HTMLPurifier_Lexer __construct ()

Redefined in descendants as:
extractBody (line 6169)

Takes a string of HTML (fragment or document) and returns the content

  • todo: Consider making protected
  • access: public
void extractBody ( $html)
  • $html
normalize (line 6118)

Takes a piece of HTML and normalizes it by converting entities, fixing encoding, extracting bits, and other good stuff.

  • todo: Consider making protected
  • access: public
void normalize ( $html,  $config,  $context)
  • $html
  • $config
  • $context
parseData (line 6029)

Parses special entities into the proper characters.

This string will translate escaped versions of the special characters into the correct ones.

  • return: character data.
  • access: public
Parsed parseData ($string $string)
  • $string $string: String character data to be parsed.
tokenizeHTML (line 6059)

Lexes an HTML string into tokens.

  • return: array representation of HTML.
  • access: public
HTMLPurifier_Token tokenizeHTML ($string $string,  $config,  $context)
  • $string $string: String HTML.
  • $config
  • $context

Redefined in descendants as:

Documentation generated on Sun, 06 Mar 2011 00:24:10 -0500 by phpDocumentor 1.4.3