IndexEntryCollector
in package
Walks every document for `.. index::` entries and expands each one into term/subterm rows, following Sphinx's `pair`/`triple`/`module` conventions.
2
Table of Contents
Properties
- $logger : LoggerInterface
Methods
- __construct() : mixed
- collectAll() : GenIndexTermMap
- findRootSection() : SectionNode|null
- placements() : array<int, array{0: IndexNode, 1: SectionNode|null, 2: string|null, 3: string}>
- Every `.. index::` block in a document, with the section its entries are filed under and the anchor and title that section is linked by.
- addEntry() : void
- checkPartCount() : void
- `.. index::` entry types only ever use a fixed number of parts (e.g. a `pair:` entry uses exactly 2). Too many silently drops the extras; too few is worse -- the whole entry is silently skipped, since none of the `count($parts) >= N` checks above are satisfied at all. Both are silent data loss unless we say something.
- collectFromDocument() : array<int, array{0: IndexEntryNode, 1: string|null, 2: string}>
- A single-pass parser attaches a `.. index::` block to whichever section is still open when it's parsed, which is usually the *previous* section, since the block conventionally sits right before the heading it documents. So anchor resolution can't rely on tree ancestry — it needs the node's true document-order position: flatten the whole document first, then for each index entry look forward for the next heading. An index block with no heading anywhere after it (e.g. the trailing `.. index::` line TYPO3 Core Changelog files end with) isn't "attached" to whatever subsection happened to be last -- it applies to the page as a whole, so it falls back to the document's own uppermost section instead.
- expandEntry() : void
- Expands one parsed `.. index::` line into one or more term/subterm insertions, following Sphinx's `pair`/`triple`/`module` conventions.
- findNextSection() : SectionNode|null
- flatten() : void
- normalize() : string
- resolveAnchor() : array{0: string|null, 1: string}
Properties
$logger read-only
private
LoggerInterface
$logger
Methods
__construct()
public
__construct(LoggerInterface $logger) : mixed
Parameters
- $logger : LoggerInterface
collectAll()
public
collectAll(DocumentNode[] $documents) : GenIndexTermMap
Parameters
- $documents : DocumentNode[]
Return values
GenIndexTermMapfindRootSection()
public
findRootSection(DocumentNode $document) : SectionNode|null
Parameters
- $document : DocumentNode
Return values
SectionNode|nullplacements()
Every `.. index::` block in a document, with the section its entries are filed under and the anchor and title that section is linked by.
public
placements(DocumentNode $document) : array<int, array{0: IndexNode, 1: SectionNode|null, 2: string|null, 3: string}>
The one answer to "where does this index block point", shared by the
index itself and by anything else that has to agree with it -- a
:name: target, for one, must land where the index entries do.
Parameters
- $document : DocumentNode
Return values
array<int, array{0: IndexNode, 1: SectionNode|null, 2: string|null, 3: string}>addEntry()
private
addEntry(GenIndexTermMap $termMap, string $term, string|null $subterm, GenIndexRowData $row) : void
Parameters
- $termMap : GenIndexTermMap
- $term : string
- $subterm : string|null
- $row : GenIndexRowData
checkPartCount()
`.. index::` entry types only ever use a fixed number of parts (e.g. a `pair:` entry uses exactly 2). Too many silently drops the extras; too few is worse -- the whole entry is silently skipped, since none of the `count($parts) >= N` checks above are satisfied at all. Both are silent data loss unless we say something.
private
checkPartCount(IndexEntryNode $entry, int $minParts, int $maxParts, DocumentNode $document) : void
Parameters
- $entry : IndexEntryNode
- $minParts : int
- $maxParts : int
- $document : DocumentNode
collectFromDocument()
A single-pass parser attaches a `.. index::` block to whichever section is still open when it's parsed, which is usually the *previous* section, since the block conventionally sits right before the heading it documents. So anchor resolution can't rely on tree ancestry — it needs the node's true document-order position: flatten the whole document first, then for each index entry look forward for the next heading. An index block with no heading anywhere after it (e.g. the trailing `.. index::` line TYPO3 Core Changelog files end with) isn't "attached" to whatever subsection happened to be last -- it applies to the page as a whole, so it falls back to the document's own uppermost section instead.
private
collectFromDocument(DocumentNode $document) : array<int, array{0: IndexEntryNode, 1: string|null, 2: string}>
Parameters
- $document : DocumentNode
Return values
array<int, array{0: IndexEntryNode, 1: string|null, 2: string}>expandEntry()
Expands one parsed `.. index::` line into one or more term/subterm insertions, following Sphinx's `pair`/`triple`/`module` conventions.
private
expandEntry(IndexEntryNode $entry, string|null $anchor, string $title, GenIndexTermMap $termMap, DocumentNode $document) : void
Parameters
- $entry : IndexEntryNode
- $anchor : string|null
- $title : string
- $termMap : GenIndexTermMap
- $document : DocumentNode
findNextSection()
private
findNextSection(array<int, array{0: string, 1: Node}> $flat, int $afterIndex) : SectionNode|null
Parameters
- $flat : array<int, array{0: string, 1: Node}>
- $afterIndex : int
Return values
SectionNode|nullflatten()
private
flatten(Node $node, array<int, array{0: string, 1: Node}> &$flat) : void
Parameters
- $node : Node
- $flat : array<int, array{0: string, 1: Node}>
normalize()
private
normalize(string $term) : string
Parameters
- $term : string
Return values
stringresolveAnchor()
private
resolveAnchor(SectionNode|null $section, DocumentNode $document) : array{0: string|null, 1: string}
Parameters
- $section : SectionNode|null
- $document : DocumentNode