HumHub Documentation (unofficial)

HTMLPurifier_Lexer
in package

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.

Tags
note

The unit tests will instantiate this class for testing purposes, as many of the utility functions require a class to be instantiated. This means that, even though this class is not runnable, it will not be declared abstract.

note

We use tokens rather than create a DOM representation because DOM would:

par
par

-# Require more processing and memory to create, -# Is not streamable, and -# Has the entire document structure (html and body not needed).

par

However, DOM is helpful in that it makes it easy to move around nodes without a lot of lookaheads to see when a tag is closed. This is a limitation of the token system and some workarounds would be nice.

Table of Contents

Properties

$tracksLineNumbers  : mixed
Whether or not this lexer implements line-number/column-number tracking.
$_special_entity2str  : mixed
Most common entity to raw value conversion table for special entities.
$_entity_parser  : mixed

Methods

__construct()  : mixed
create()  : HTMLPurifier_Lexer
Retrieves or sets the default Lexer as a Prototype Factory.
extractBody()  : mixed
Takes a string of HTML (fragment or document) and returns the content
normalize()  : string
Takes a piece of HTML and normalizes it by converting entities, fixing encoding, extracting bits, and other good stuff.
parseAttr()  : mixed
parseData()  : string
Parses special entities into the proper characters.
parseText()  : mixed
tokenizeHTML()  : array<string|int, HTMLPurifier_Token>
Lexes an HTML string into tokens.
CDATACallback()  : string
Callback function for escapeCDATA() that does the work.
escapeCDATA()  : string
Translates CDATA sections into regular sections (through escaping).
escapeCommentedCDATA()  : string
Special CDATA case that is especially convoluted for <script>
removeIEConditional()  : string
Special Internet Explorer conditional comments should be removed.

Properties

$tracksLineNumbers

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

public mixed $tracksLineNumbers = \false

If it does, set to true.

$_special_entity2str

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

protected mixed $_special_entity2str = array('&quot;' => '"', '&amp;' => '&', '&lt;' => '<', '&gt;' => '>', '&#39;' => "'", '&#039;' => "'", '&#x27;' => "'")
Tags
type

array

$_entity_parser

private mixed $_entity_parser
Tags
type

HTMLPurifier_EntityParser

Methods

__construct()

public __construct() : mixed

create()

Retrieves or sets the default Lexer as a Prototype Factory.

public static create(HTMLPurifier_Config $config) : HTMLPurifier_Lexer

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

Parameters
$config : HTMLPurifier_Config
Tags
note

The behavior of this class has changed, rather than accepting a prototype object, it now accepts a configuration object. To specify your own prototype, set %Core.LexerImpl to it. This change in behavior de-singletonizes the lexer object.

throws
HTMLPurifier_Exception
Return values
HTMLPurifier_Lexer

extractBody()

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

public extractBody(mixed $html) : mixed
Parameters
$html : mixed
Tags
todo

Consider making protected

parseAttr()

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

parseData()

Parses special entities into the proper characters.

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

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

Parameters
$string : string

String character data to be parsed.

$is_attr : mixed
$config : mixed
Return values
string

Parsed character data.

parseText()

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

CDATACallback()

Callback function for escapeCDATA() that does the work.

protected static CDATACallback(array<string|int, mixed> $matches) : string
Parameters
$matches : array<string|int, mixed>

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

Tags
warning

Though this is public in order to let the callback happen, calling it directly is not recommended.

Return values
string

Escaped internals of the CDATA section.

escapeCDATA()

Translates CDATA sections into regular sections (through escaping).

protected static escapeCDATA(string $string) : string
Parameters
$string : string

HTML string to process.

Return values
string

HTML with CDATA sections escaped.

escapeCommentedCDATA()

Special CDATA case that is especially convoluted for <script>

protected static escapeCommentedCDATA(string $string) : string
Parameters
$string : string

HTML string to process.

Return values
string

HTML with CDATA sections escaped.

removeIEConditional()

Special Internet Explorer conditional comments should be removed.

protected static removeIEConditional(string $string) : string
Parameters
$string : string

HTML string to process.

Return values
string

HTML with conditional comments removed.


        
On this page

Search results