BB code parser and renderer.

package XenForo_BbCode

 Methods

Constructor.

__construct(\XenForo_BbCode_Formatter_Base $formatter) 

Parameters

$formatter

\XenForo_BbCode_Formatter_Base

Formatting rules.

Parse the specified text for BB codes and return the syntax tree.

parse(string $text) : array

Parameters

$text

string

Returns

array

Renders the given text containing BB codes to the required output format (dependent on the given tags).

render(string | array $text, array $extraStates) : string

Parameters

$text

stringarray

If array, is assumed to be an already parsed version

$extraStates

array

A list of extra states to pass into the formatter

Returns

string

Finds the named tag in the currently open tags stack.

_findInStack(string $tagName) : array | false

If an array is returned, the last entry is the correct stack entry. Any other entries are tags that were opened before this but not closed (inner most first). These tags should be re-opened after closing this to force valid nesting.

Parameters

$tagName

string

Name of the tag to find

Returns

arrayfalse

Gets information about the specified tag.

_getTagRule(string $tagName) : array | false

Parameters

$tagName

string

Returns

arrayfalse

Merges the trailing text into the current context.

_mergeTrailingText() 

Looks for the next tag in the text.

_parseTag() : boolean

Returns

booleanFalse if no more valid tags can possibly found; true otherwise

Parses a closing tag.

_parseTagClose(integer $tagStartPosition, integer $tagEndPosition, integer $tagContentEndPosition) : boolean

The "[" has already been matched.

Parameters

$tagStartPosition

integer

Position of the "["

$tagEndPosition

integer

Position after the "]". May be modified if necessary.

$tagContentEndPosition

integer

Position of the "]"

Returns

booleanFalse if no more valid tags can possibly found; true otherwise

Parses an opening tag.

_parseTagOpen(integer $tagStartPosition, integer $tagEndPosition, integer $tagContentEndPosition) : boolean

The "[" has already been matched.

Parameters

$tagStartPosition

integer

Position of the "["

$tagEndPosition

integer

Position after the "]". May be modified if necessary.

$tagContentEndPosition

integer

Position of the "]"

Returns

booleanFalse if no more valid tags can possibly found; true otherwise

Pushes a tag closing onto the tree.

_pushTagClose(string $tagName, string $originalText) 

Parameters

$tagName

string

Name of the tag that was found

$originalText

string

Original, plain text version of the matched tag (including [ and ])

Pushes a new tag opening onto the tree.

_pushTagOpen(string $tagName, string | null $tagOption, string $originalText) 

Parameters

$tagName

string

Name of the tag that was found

$tagOption

stringnull

Value for the tag's option

$originalText

string

Original, plain text version of the matched tag (including [ and ])

Pushes a new plain text node onto the tree.

_pushText(string $text) 

Parameters

$text

string

_resetParser()

_resetParser() 

 Properties

 

Reference to the current tree context.

$_context : array

 

Contains information about how the tags, smilies, strings, etc should be formatted.

$_formatter : \XenForo_BbCode_Formatter_Base

 

The current states the parser is in.

$_parserStates : array

Can include things like "plainText", etc.

 

The current position in the text.

$_position : integer

Parsing will only occur from this point on.

 

List of valid tags from the tag handler.

$_tagList : array

 

Stack of currently open tags, with references to the parent's position in the tree.

$_tagStack : array

 

The text that is to be parsed/rendered.

$_text : string

 

Trailing text in the current tree context.

$_trailingText : string

Used to fold multiple text entries together.

 

The parse tree.

$_tree : array

This will only be populated while parsing. Format: strings are literal text; arrays are tag openings, with keys: * tag - tag name (lower case) * option - value for the tag's option * children - array of more children (same format as the whole tree)