Class HTMLPurifier_Lexer
Inheritance | HTMLPurifier_Lexer |
---|---|
Subclasses | HTMLPurifier_Lexer_DOMLex, HTMLPurifier_Lexer_DirectLex, HTMLPurifier_Lexer_PH5P |
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.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$tracksLineNumbers | Whether or not this lexer implements line-number/column-number tracking. | HTMLPurifier_Lexer |
Protected Properties
Property | Type | Description | Defined By |
---|---|---|---|
$_special_entity2str | Most common entity to raw value conversion table for special entities. | HTMLPurifier_Lexer |
Public Methods
Method | Description | Defined By |
---|---|---|
__construct() | HTMLPurifier_Lexer | |
create() | Retrieves or sets the default Lexer as a Prototype Factory. | HTMLPurifier_Lexer |
extractBody() | Takes a string of HTML (fragment or document) and returns the content | HTMLPurifier_Lexer |
normalize() | Takes a piece of HTML and normalizes it by converting entities, fixing encoding, extracting bits, and other good stuff. | HTMLPurifier_Lexer |
parseData() | Parses special entities into the proper characters. | HTMLPurifier_Lexer |
tokenizeHTML() | Lexes an HTML string into tokens. | HTMLPurifier_Lexer |
Protected Methods
Method | Description | Defined By |
---|---|---|
CDATACallback() | Callback function for escapeCDATA() that does the work. | HTMLPurifier_Lexer |
escapeCDATA() | Translates CDATA sections into regular sections (through escaping). | HTMLPurifier_Lexer |
escapeCommentedCDATA() | Special CDATA case that is especially convoluted for | HTMLPurifier_Lexer |
removeIEConditional() | Special Internet Explorer conditional comments should be removed. | HTMLPurifier_Lexer |
Property Details
If it does, set to true.
Method Details
Callback function for escapeCDATA() that does the work.
protected static string CDATACallback ( $matches ) | ||
$matches | array | PCRE matches array, with index 0 the entire match
|
return | string | Escaped internals of the CDATA section. |
---|
public void __construct ( ) |
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.
public static HTMLPurifier_Lexer create ( $config ) | ||
$config | HTMLPurifier_Config | |
throws | HTMLPurifier_Exception |
---|
Translates CDATA sections into regular sections (through escaping).
protected static string escapeCDATA ( $string ) | ||
$string | string | HTML string to process. |
return | string | HTML with CDATA sections escaped. |
---|
Special CDATA case that is especially convoluted for
protected static string escapeCommentedCDATA ( $string ) | ||
$string | string | HTML string to process. |
return | string | HTML with CDATA sections escaped. |
---|
Takes a string of HTML (fragment or document) and returns the content
public void extractBody ( $html ) | ||
$html |
Takes a piece of HTML and normalizes it by converting entities, fixing encoding, extracting bits, and other good stuff.
public string normalize ( $html, $config, $context ) | ||
$html | string | HTML. |
$config | HTMLPurifier_Config | |
$context | HTMLPurifier_Context |
Parses special entities into the proper characters.
This string will translate escaped versions of the special characters into the correct ones.
public string parseData ( $string ) | ||
$string | string | String character data to be parsed. |
return | string | Parsed character data. |
---|
Special Internet Explorer conditional comments should be removed.
protected static string removeIEConditional ( $string ) | ||
$string | string | HTML string to process. |
return | string | HTML with conditional comments removed. |
---|
Lexes an HTML string into tokens.
public HTMLPurifier_Token[] tokenizeHTML ( $string, $config, $context ) | ||
$string | String HTML. |
|
$config | HTMLPurifier_Config | |
$context | HTMLPurifier_Context | |
return | HTMLPurifier_Token[] | Array representation of HTML. |
---|