HTMLPurifier_Injector_AutoParagraph
extends HTMLPurifier_Injector
in package
Injector that auto paragraphs text in the root node based on double-spacing.
Tags
Table of Contents
Properties
- $name : mixed
- Advisory name of injector, this is for friendly error messages.
- $needed : mixed
- 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')
- $currentNesting : mixed
- Reference to CurrentNesting variable in Context. This is an array list of tokens that we are currently "inside"
- $currentToken : mixed
- Reference to current token.
- $htmlDefinition : mixed
- $inputZipper : mixed
- Reference to InputZipper variable in Context.
- $rewindOffset : mixed
- Number of elements to rewind backwards (relative).
Methods
- allowsElement() : bool
- Tests if the context node allows a certain element
- checkNeeded() : bool|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.
- getRewindOffset() : bool|int
- Retrieves rewind offset, and then unsets it.
- handleElement() : mixed
- Handler that is called when a start or empty token is processed
- handleEnd() : mixed
- Handler that is called when an end token is processed
- handleText() : mixed
- Handler that is called when a text token is processed
- notifyEnd() : mixed
- Notifier that is called when an end token is processed
- prepare() : bool|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()).
- rewindOffset() : mixed
- 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.
- backward() : bool
- Iterator function, starts with the previous token and continues until you reach the beginning of input tokens.
- forward() : bool
- Iterator function, which starts with the next token and continues until you reach the end of the input tokens.
- forwardUntilEndToken() : bool
- 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.
- _checkNeedsP() : bool
- Determines if a particular token requires an earlier inline token to get a paragraph. This should be used with _forwardUntilEndToken
- _isInline() : bool
- Returns true if passed token is inline (and, ergo, allowed in paragraph tags)
- _pLookAhead() : bool
- Looks ahead in the token list and determines whether or not we need to insert a <p> tag.
- _pStart() : HTMLPurifier_Token_Start
- _splitText() : mixed
- Splits up a text in paragraph tokens and appends them to the result stream that will replace the original
Properties
$name
Advisory name of injector, this is for friendly error messages.
public
mixed
$name
= 'AutoParagraph'
Tags
$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')
public
mixed
$needed
= array('p')
Tags
$currentNesting
Reference to CurrentNesting variable in Context. This is an array list of tokens that we are currently "inside"
protected
mixed
$currentNesting
Tags
$currentToken
Reference to current token.
protected
mixed
$currentToken
Tags
$htmlDefinition
protected
mixed
$htmlDefinition
Tags
$inputZipper
Reference to InputZipper variable in Context.
protected
mixed
$inputZipper
Tags
$rewindOffset
Number of elements to rewind backwards (relative).
protected
mixed
$rewindOffset
= \false
Tags
Methods
allowsElement()
Tests if the context node allows a certain element
public
allowsElement(string $name) : bool
Parameters
- $name : string
-
Name of element to test for
Return values
bool —True if element is allowed, false if it is not
checkNeeded()
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.
public
checkNeeded(HTMLPurifier_Config $config) : bool|string
Parameters
- $config : HTMLPurifier_Config
Return values
bool|string —Boolean false if success, string of missing needed element/attribute if failure
getRewindOffset()
Retrieves rewind offset, and then unsets it.
public
getRewindOffset() : bool|int
Return values
bool|inthandleElement()
Handler that is called when a start or empty token is processed
public
handleElement(HTMLPurifier_Token &$token) : mixed
Parameters
- $token : HTMLPurifier_Token
handleEnd()
Handler that is called when an end token is processed
public
handleEnd(mixed &$token) : mixed
Parameters
- $token : mixed
handleText()
Handler that is called when a text token is processed
public
handleText(HTMLPurifier_Token_Text &$token) : mixed
Parameters
- $token : HTMLPurifier_Token_Text
notifyEnd()
Notifier that is called when an end token is processed
public
notifyEnd(HTMLPurifier_Token $token) : mixed
Parameters
- $token : HTMLPurifier_Token
-
Current token variable.
Tags
prepare()
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()).
public
prepare(HTMLPurifier_Config $config, HTMLPurifier_Context $context) : bool|string
Parameters
- $config : HTMLPurifier_Config
- $context : HTMLPurifier_Context
Return values
bool|string —Boolean false if success, string of missing needed element/attribute if failure
rewindOffset()
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.
public
rewindOffset(bool|int $offset) : mixed
Parameters
- $offset : bool|int
Tags
backward()
Iterator function, starts with the previous token and continues until you reach the beginning of input tokens.
protected
backward(int &$i, HTMLPurifier_Token &$current) : bool
Parameters
- $i : int
-
Current integer index variable for inputTokens
- $current : HTMLPurifier_Token
-
Current token variable. Do NOT use $token, as that variable is also a reference
Tags
Return values
boolforward()
Iterator function, which starts with the next token and continues until you reach the end of the input tokens.
protected
forward(int &$i, HTMLPurifier_Token &$current) : bool
Parameters
- $i : int
-
Current integer index variable for inputTokens
- $current : HTMLPurifier_Token
-
Current token variable. Do NOT use $token, as that variable is also a reference
Tags
Return values
boolforwardUntilEndToken()
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.
protected
forwardUntilEndToken(int &$i, HTMLPurifier_Token &$current, int &$nesting) : bool
Parameters
- $i : int
-
Current integer index variable for inputTokens
- $current : HTMLPurifier_Token
-
Current token variable. Do NOT use $token, as that variable is also a reference
- $nesting : int
Return values
bool_checkNeedsP()
Determines if a particular token requires an earlier inline token to get a paragraph. This should be used with _forwardUntilEndToken
private
_checkNeedsP(HTMLPurifier_Token $current) : bool
Parameters
- $current : HTMLPurifier_Token
Return values
bool_isInline()
Returns true if passed token is inline (and, ergo, allowed in paragraph tags)
private
_isInline(HTMLPurifier_Token $token) : bool
Parameters
- $token : HTMLPurifier_Token
Return values
bool_pLookAhead()
Looks ahead in the token list and determines whether or not we need to insert a <p> tag.
private
_pLookAhead() : bool
Return values
bool_pStart()
private
_pStart() : HTMLPurifier_Token_Start
Return values
HTMLPurifier_Token_Start_splitText()
Splits up a text in paragraph tokens and appends them to the result stream that will replace the original
private
_splitText(string $data, array<string|int, HTMLPurifier_Token> &$result) : mixed
Parameters
- $data : string
-
String text data that will be processed into paragraphs
- $result : array<string|int, HTMLPurifier_Token>
-
Reference to array of tokens that the tags will be appended onto