\HTMLPurifier_Lexer

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.

Summary

Methods
Properties
Constants
create()
__construct()
parseText()
parseAttr()
parseData()
tokenizeHTML()
normalize()
extractBody()
$tracksLineNumbers
No constants found
escapeCDATA()
escapeCommentedCDATA()
removeIEConditional()
CDATACallback()
$_special_entity2str
N/A
No private methods found
No private properties found
N/A

Properties

$tracksLineNumbers

$tracksLineNumbers

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

If it does, set to true.

$_special_entity2str

$_special_entity2str

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

Methods

create()

create(\HTMLPurifier_Config  $config) : \HTMLPurifier_Lexer

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.

Parameters

\HTMLPurifier_Config $config

Throws

\HTMLPurifier_Exception

Returns

\HTMLPurifier_Lexer —

__construct()

__construct() : mixed

Returns

mixed —

parseText()

parseText(mixed  $string, mixed  $config) : mixed

Parameters

mixed $string
mixed $config

Returns

mixed —

parseAttr()

parseAttr(mixed  $string, mixed  $config) : mixed

Parameters

mixed $string
mixed $config

Returns

mixed —

parseData()

parseData(string  $string, mixed  $is_attr, mixed  $config) : string

Parses special entities into the proper characters.

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

Parameters

string $string

String character data to be parsed.

mixed $is_attr
mixed $config

Returns

string —

Parsed character data.

tokenizeHTML()

tokenizeHTML( $string, \HTMLPurifier_Config  $config, \HTMLPurifier_Context  $context) : \HTMLPurifier_Token[]

Lexes an HTML string into tokens.

Parameters

$string

String HTML.

\HTMLPurifier_Config $config
\HTMLPurifier_Context $context

Returns

\HTMLPurifier_Token[] —

array representation of HTML.

normalize()

normalize(string  $html, \HTMLPurifier_Config  $config, \HTMLPurifier_Context  $context) : string

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

Parameters

string $html

HTML.

\HTMLPurifier_Config $config
\HTMLPurifier_Context $context

Returns

string —

extractBody()

extractBody(mixed  $html) : mixed

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

Parameters

mixed $html

Returns

mixed —

escapeCDATA()

escapeCDATA(string  $string) : string

Translates CDATA sections into regular sections (through escaping).

Parameters

string $string

HTML string to process.

Returns

string —

HTML with CDATA sections escaped.

escapeCommentedCDATA()

escapeCommentedCDATA(string  $string) : string

Special CDATA case that is especially convoluted for <script>

Parameters

string $string

HTML string to process.

Returns

string —

HTML with CDATA sections escaped.

removeIEConditional()

removeIEConditional(string  $string) : string

Special Internet Explorer conditional comments should be removed.

Parameters

string $string

HTML string to process.

Returns

string —

HTML with conditional comments removed.

CDATACallback()

CDATACallback(array  $matches) : string

Callback function for escapeCDATA() that does the work.

Parameters

array $matches

PCRE matches array, with index 0 the entire match and 1 the inside of the CDATA section.

Returns

string —

Escaped internals of the CDATA section.