Parsoid
A bidirectional parser between wikitext and HTML5
|
Table of Contents data, including an array of section metadata. More...
Public Member Functions | |
__construct (... $sections) | |
Create a new TOCData object with the given sections and no extension data. | |
getCurrentTOCLevel () | |
Return current TOC level while headings are being processed and section metadata is being constructed. | |
addSection (SectionMetadata $s) | |
Add a new section to this TOCData. | |
getSections () | |
Get the list of sections in the TOCData. | |
setExtensionData (string $key, $value) | |
Attaches arbitrary data to this TOCData object. | |
appendExtensionData (string $key, $value) | |
Appends arbitrary data to this TOCData. | |
getExtensionData ( $key) | |
Gets extension data previously attached to this TOCData. | |
toLegacy () | |
Return as associative array, in the legacy format returned by the action API. | |
processHeading (int $oldLevel, int $level, SectionMetadata $metadata) | |
jsonSerialize () | |
Serialize all data in the TOCData as JSON. | |
toJsonArray () | |
prettyPrint () | |
For use in parser tests and wherever else humans might appreciate some formatting in the JSON encoded output. | |
__clone () | |
Static Public Member Functions | |
static | fromLegacy (array $data) |
Create a new TOCData object from the legacy associative array format. | |
static | newFromJsonArray (array $json) |
static | jsonClassHintFor (string $keyName) |
Table of Contents data, including an array of section metadata.
This is simply an array of SectionMetadata objects for now along with extension data, but may include additional ToC properties in the future.
Wikimedia\Parsoid\Core\TOCData::__construct | ( | $sections | ) |
Create a new TOCData object with the given sections and no extension data.
SectionMetadata | ...$sections |
Wikimedia\Parsoid\Core\TOCData::addSection | ( | SectionMetadata | $s | ) |
Add a new section to this TOCData.
SectionMetadata | $s |
Wikimedia\Parsoid\Core\TOCData::appendExtensionData | ( | string | $key, |
$value ) |
Appends arbitrary data to this TOCData.
This can be used to store some information about the table of contents in the ParserOutput object for later use during page output.
See ::setExtensionData() for more details on rationale and use.
string | $key | The key for accessing the data. Extensions should take care to avoid conflicts in naming keys. It is suggested to use the extension's name as a prefix. |
int | string | $value | The value to append to the list. |
|
static |
Create a new TOCData object from the legacy associative array format.
This is used for backward compatibility, but the associative array format does not include any properties of the TOCData other than the section list.
array | $data | Associative array with ToC data in legacy format |
Wikimedia\Parsoid\Core\TOCData::getCurrentTOCLevel | ( | ) |
Return current TOC level while headings are being processed and section metadata is being constructed.
Wikimedia\Parsoid\Core\TOCData::getExtensionData | ( | $key | ) |
Gets extension data previously attached to this TOCData.
string | $key | The key to look up |
Wikimedia\Parsoid\Core\TOCData::getSections | ( | ) |
Get the list of sections in the TOCData.
Wikimedia\Parsoid\Core\TOCData::jsonSerialize | ( | ) |
Serialize all data in the TOCData as JSON.
Unlike the :toLegacy()
method, this method will include all of the properties in the TOCData so that the serialization is reversible.
Wikimedia\Parsoid\Core\TOCData::prettyPrint | ( | ) |
For use in parser tests and wherever else humans might appreciate some formatting in the JSON encoded output.
Wikimedia\Parsoid\Core\TOCData::processHeading | ( | int | $oldLevel, |
int | $level, | ||
SectionMetadata | $metadata ) |
int | $oldLevel | level of the heading (H1/H2, etc.) |
int | $level | level of the heading (H1/H2, etc.) |
SectionMetadata | $metadata | This metadata will be updated This logic is copied from Parser.php::finalizeHeadings |
Wikimedia\Parsoid\Core\TOCData::setExtensionData | ( | string | $key, |
$value ) |
Attaches arbitrary data to this TOCData object.
This can be used to store some information about the table of contents in the ParserOutput object for later use during page output. The data will be cached along with the ParserOutput object.
See ParserOutput::setExtensionData() in core for further information about typical usage in hooks, and SectionMetadata::setExtensionData() for a similar method appropriate for information about a specific section of the ToC.
Setting conflicting values for the same key is not allowed. If you call ::setExtensionData() multiple times with the same key on a TOCData, is is expected that the value will be identical each time. If you want to collect multiple pieces of data under a single key, use ::appendExtensionData().
string | $key | The key for accessing the data. Extensions should take care to avoid conflicts in naming keys. It is suggested to use the extension's name as a prefix. Using the prefix mw: is reserved for core. |
mixed | $value | The value to set. Setting a value to null is equivalent to removing the value. |
Wikimedia\Parsoid\Core\TOCData::toLegacy | ( | ) |
Return as associative array, in the legacy format returned by the action API.
This is helpful as b/c support while we transition to objects, but it drops some properties from this class and shouldn't be used in new code.