ToctreeSortingTransformer
in package
implements
NodeTransformer
Table of Contents
Interfaces
Methods
- enterNode() : T
- getPriority() : int
- The higher the priority the earlier the NodeTransformer is executed.
- leaveNode() : T|null
- supports() : bool
- collectTocNodes() : array<string|int, TocNode>
- Collects the toctrees of a document in document order.
- menuEntryKey() : string
- sortMenuEntriesByToctrees() : array<string|int, DocumentEntryNode|ExternalEntryNode>|null
- Reorders the menu entries of a document so they follow the order authored in its toctrees.
Methods
enterNode()
public
enterNode(Node $node, CompilerContext $compilerContext) : T
Parameters
- $node : Node
- $compilerContext : CompilerContext
Return values
TgetPriority()
The higher the priority the earlier the NodeTransformer is executed.
public
getPriority() : int
Return values
intleaveNode()
public
leaveNode(Node $node, CompilerContext $compilerContext) : T|null
Parameters
- $node : Node
- $compilerContext : CompilerContext
Return values
T|nullsupports()
public
supports(Node $node) : bool
Parameters
- $node : Node
Return values
boolcollectTocNodes()
Collects the toctrees of a document in document order.
private
static collectTocNodes(Node $node) : array<string|int, TocNode>
DocumentNode::getTocNodes() is filled by TocNodeTransformer at priority 1000, which runs after
this pass, and getNodes() only looks at direct children while a toctree usually sits inside a
section. So the tree is walked here.
Parameters
- $node : Node
Return values
array<string|int, TocNode>menuEntryKey()
private
static menuEntryKey(DocumentEntryNode|ExternalEntryNode $entry) : string
Parameters
- $entry : DocumentEntryNode|ExternalEntryNode
Return values
stringsortMenuEntriesByToctrees()
Reorders the menu entries of a document so they follow the order authored in its toctrees.
private
sortMenuEntriesByToctrees(DocumentNode $documentNode, array<string|int, DocumentEntryNode|ExternalEntryNode> $menuEntries) : array<string|int, DocumentEntryNode|ExternalEntryNode>|null
The order is taken from all toctrees of the document at once, in document order, rather than
from the toctree currently visited: the menu entries the sorting starts from are grouped by
type, so a single toctree cannot tell where its own block belongs relative to the others.
Running this for every toctree of the document is idempotent, and the last run sees every
:reversed: toctree already reversed.
Nothing is reordered when a menu entry is attached that no toctree of the document accounts for: reordering only part of the list would be worse than not reordering it. Null is returned in that case.
Parameters
- $documentNode : DocumentNode
- $menuEntries : array<string|int, DocumentEntryNode|ExternalEntryNode>