\HTMLPurifier_Injector_AutoParagraph

Injector that auto paragraphs text in the root node based on double-spacing.

This enables "formatter-like" functionality such as auto-paragraphing, smiley-ification and linkification to take place.

A note on how handlers create changes; this is done by assigning a new value to the $token reference. These values can take a variety of forms and are best described HTMLPurifier_Strategy_MakeWellFormed->processToken() documentation.

Summary

Methods
Properties
Constants
rewindOffset()
getRewindOffset()
prepare()
checkNeeded()
allowsElement()
handleText()
handleElement()
handleEnd()
notifyEnd()
$name
$needed
No constants found
forward()
forwardUntilEndToken()
backward()
$htmlDefinition
$currentNesting
$currentToken
$inputZipper
$rewindOffset
N/A
_pStart()
_splitText()
_isInline()
_pLookAhead()
_checkNeedsP()
No private properties found
N/A

Properties

$name

$name : 

Advisory name of injector, this is for friendly error messages.

Type

$needed

$needed : 

Array of elements and attributes this injector creates and therefore need to be allowed by the definition. Takes form of array('element' => array('attr', 'attr2'), 'element2')

Type

$htmlDefinition

$htmlDefinition : 

Type

$currentNesting

$currentNesting : 

Reference to CurrentNesting variable in Context. This is an array list of tokens that we are currently "inside"

Type

$currentToken

$currentToken : 

Reference to current token.

Type

$inputZipper

$inputZipper : 

Reference to InputZipper variable in Context.

Type

$rewindOffset

$rewindOffset : 

Number of elements to rewind backwards (relative).

Type

Methods

rewindOffset()

rewindOffset(boolean|integer  $offset) 

Rewind to a spot to re-perform processing. This is useful if you deleted a node, and now need to see if this change affected any earlier nodes. Rewinding does not affect other injectors, and can result in infinite loops if not used carefully.

Parameters

boolean|integer $offset

getRewindOffset()

getRewindOffset() : boolean|integer

Retrieves rewind offset, and then unsets it.

Returns

boolean|integer

prepare()

prepare(\HTMLPurifier_Config  $config, \HTMLPurifier_Context  $context) : boolean|string

Prepares the injector by giving it the config and context objects: this allows references to important variables to be made within the injector. This function also checks if the HTML environment will work with the Injector (see checkNeeded()).

Parameters

\HTMLPurifier_Config $config
\HTMLPurifier_Context $context

Returns

boolean|string —

Boolean false if success, string of missing needed element/attribute if failure

checkNeeded()

checkNeeded(\HTMLPurifier_Config  $config) : boolean|string

This function checks if the HTML environment will work with the Injector: if p tags are not allowed, the Auto-Paragraphing injector should not be enabled.

Parameters

\HTMLPurifier_Config $config

Returns

boolean|string —

Boolean false if success, string of missing needed element/attribute if failure

allowsElement()

allowsElement(string  $name) : boolean

Tests if the context node allows a certain element

Parameters

string $name

Name of element to test for

Returns

boolean —

True if element is allowed, false if it is not

handleText()

handleText(\HTMLPurifier_Token_Text  $token) 

Handler that is called when a text token is processed

Parameters

\HTMLPurifier_Token_Text $token

handleElement()

handleElement(\HTMLPurifier_Token  $token) 

Handler that is called when a start or empty token is processed

Parameters

\HTMLPurifier_Token $token

handleEnd()

handleEnd(  $token) 

Handler that is called when an end token is processed

Parameters

$token

notifyEnd()

notifyEnd(\HTMLPurifier_Token  $token) 

Notifier that is called when an end token is processed

Parameters

\HTMLPurifier_Token $token

Current token variable.

forward()

forward(integer  $i, \HTMLPurifier_Token  $current) : boolean

Iterator function, which starts with the next token and continues until you reach the end of the input tokens.

Parameters

integer $i

Current integer index variable for inputTokens

\HTMLPurifier_Token $current

Current token variable. Do NOT use $token, as that variable is also a reference

Returns

boolean

forwardUntilEndToken()

forwardUntilEndToken(integer  $i, \HTMLPurifier_Token  $current, integer  $nesting) : boolean

Similar to _forward, but accepts a third parameter $nesting (which should be initialized at 0) and stops when we hit the end tag for the node $this->inputIndex starts in.

Parameters

integer $i

Current integer index variable for inputTokens

\HTMLPurifier_Token $current

Current token variable. Do NOT use $token, as that variable is also a reference

integer $nesting

Returns

boolean

backward()

backward(integer  $i, \HTMLPurifier_Token  $current) : boolean

Iterator function, starts with the previous token and continues until you reach the beginning of input tokens.

Parameters

integer $i

Current integer index variable for inputTokens

\HTMLPurifier_Token $current

Current token variable. Do NOT use $token, as that variable is also a reference

Returns

boolean

_splitText()

_splitText(string  $data, array<mixed,\HTMLPurifier_Token>  $result) 

Splits up a text in paragraph tokens and appends them to the result stream that will replace the original

Parameters

string $data

String text data that will be processed into paragraphs

array<mixed,\HTMLPurifier_Token> $result

Reference to array of tokens that the tags will be appended onto

_isInline()

_isInline(\HTMLPurifier_Token  $token) : boolean

Returns true if passed token is inline (and, ergo, allowed in paragraph tags)

Parameters

\HTMLPurifier_Token $token

Returns

boolean

_pLookAhead()

_pLookAhead() : boolean

Looks ahead in the token list and determines whether or not we need to insert a <p> tag.

Returns

boolean

_checkNeedsP()

_checkNeedsP(\HTMLPurifier_Token  $current) : boolean

Determines if a particular token requires an earlier inline token to get a paragraph. This should be used with _forwardUntilEndToken

Parameters

\HTMLPurifier_Token $current

Returns

boolean