Tags final class
Minn\Html\Tags · public/minn/src/Minn/Html/Tags.php · 589 lines
A streaming HTML tokenizer with in-place edits: every token in document order, attributes decoded, edits applied to the source without reserialising the rest, bookmarks to seek back to (probe html-tag-processor).
Constants and properties
| const | TAG = '#tag' | |
| const | TEXT = '#text' | |
| const | COMMENT = '#comment' | |
| const | DOCTYPE = '#doctype' | |
| const | PI = '#processing-instruction' | |
| const | FUNKY = '#funky-comment' | |
| const | CDATA = '#cdata-section' | |
| const | PRESUMPTUOUS = '#presumptuous-tag' | |
| const | COMMENT_HTML = 'COMMENT_AS_HTML_COMMENT' | |
| const | COMMENT_ABRUPT = 'COMMENT_AS_ABRUPTLY_CLOSED_COMMENT' | |
| const | COMMENT_INVALID = 'COMMENT_AS_INVALID_HTML' | |
| const | COMMENT_CDATA = 'COMMENT_AS_CDATA_LOOKALIKE' | |
| const | COMMENT_PI = 'COMMENT_AS_PI_NODE_LOOKALIKE' | |
| const | RAW_TEXT = array ( 0 => 'script', 1 => 'style', 2 => 'textarea', 3 => 'title', 4 => 'xmp', 5 => 'iframe', 6 => 'noembed', 7 => 'noframes', ) | Elements whose body is raw text up to the closer. |
| private | RAW_DECODED = array ( 0 => 'textarea', 1 => 'title', ) | |
| private | MAX_BOOKMARKS = 10 | |
| private | string $html | |
| private | int $cursor | |
| private | bool $ended | |
| private | bool $paused | |
| private | ?string $type | |
| private | ?string $name | |
| private | int $start | |
| private | int $end | |
| private | int $nameEnd | |
| private | bool $closer | |
| private | bool $selfClosing | |
| private | array $attributes | |
| private | int $textStart | |
| private | int $textLength | |
| private | ?string $commentType | |
| private | ?string $commentTarget | |
| private | string $namespace | |
| private | string $tagBodies | |
| private | int $maxBookmarks | |
| private | bool $afterPre | Whether a text token here drops one leading line break (it follows a PRE or LISTING opener). |
| private | bool $textAfterPre | |
| private | int $fullTextStart | |
| private | int $fullTextLength | |
| private | Minn\Html\Edits $edits | |
| private | array $bookmarks |
Public
| new | __construct(string $html)# | ||||
| method | nextToken(): bool# | Advances to the next token; false at the end or at an incomplete one. | |||
| method | nextTag(array $query): bool# | Advances to the next tag matching the query; false when none. @param array{tag_name?: ?string, class_name?: ?string, match_offset?: int, tag_closers?: string} $query
| |||
| method | pausedAtIncompleteToken(): bool# | Whether the scan stopped inside an unfinished token. | |||
| method | tokenType(): ?string# | The current token's kind. | |||
| method | tokenName(): ?string# | The current token's name. | |||
| method | tag(): ?string# | The current tag name, upper-cased; a processing instruction's target, or a PI lookalike's, as written. | |||
| method | isCloser(): bool# | Whether the current tag is a closer. | |||
| method | selfClosing(): bool# | Whether the current tag has the self-closing flag. | |||
| method | commentType(): ?string# | The current comment's kind. | |||
| method | fullCommentText(): ?string# | The current comment's whole text (a funky comment's is its text). | |||
| method | modifiableText(): string# | The current token's text as a reader sees it. | |||
| method | doctype(): ?array# | Doctype pieces, or null when the token is not a doctype. @return array{name: ?string, public: ?string, system: ?string}|null @return array{name: ?string, public: ?string, system: ?string}|null | |||
| method | attribute(string $name): string|true|null# | The decoded value, true for a bare attribute, null when absent; a pending edit answers first. | |||
| method | attributeNames(string $prefix): ?array# | The current tag's attribute names with a prefix, lower-cased, in source order; null off a tag. @return list<string>|null @return list<string>|null | |||
| method | classes(): array# | The current tag's classes. @return list<string> distinct class names after pending edits @return list<string> distinct class names after pending edits | |||
| method | hasClass(string $class): bool# | Whether the current tag has a class. | |||
| method | setAttribute(string $name, Minn\Html\Escaped|string|int|float|bool|null $value): bool# | Sets an attribute on the current tag. | |||
| method | removeAttribute(string $name): bool# | Removes an attribute from the current tag. | |||
| method | addClass(string $class): bool# | Adds a class to the current tag. | |||
| method | removeClass(string $class): bool# | Removes a class from the current tag. | |||
| method | setModifiableText(string $text): bool# | Replaces the current token's text, when its kind allows it. | |||
| method | setBookmark(string $name): bool# | Names the current token's position. | |||
| method | releaseBookmark(string $name): bool# | Forgets a bookmark. | |||
| method | hasBookmark(string $name): bool# | Whether a bookmark exists. | |||
| method | seek(string $name): bool# | Moves to a bookmark. | |||
| method | parseAs(string $namespace, string $tagBodies = 'html'): void# | What follows as a namespace's content: outside HTML "<![CDATA[" opens a section; tag bodies read as HTML ("html", raw text elements whole) unless foreign ("foreign"). | |||
| method | allowBookmarks(int $max): void# | Raises how many bookmarks may be held at once. | |||
| method | rewind(): void# | Back to the start of the document, with every update written in and the bookmarks kept. | |||
| method | splitText(int $length): void# | The current text token cut to its first bytes; the rest is read next. | |||
| method | tokenSpan(): array# | Where the current token sits in the document: [start, end]. | |||
| method | textSpan(): array# | Where the current text token's text sits: [start, length]. | |||
| method | source(int $start, int $length): string# | The source between two offsets, updates written in. | |||
| method | bookmarkSpan(string $name): ?array# | Where a bookmark sits: [start, end], or null when there is none of that name. | |||
| method | replaceAfter(int $start, int $end, string $text): void# | Replaces a span at or after the current token's end, updates written in first: the new text is read next, and bookmarks past the span move with it. | |||
| method | html(): string# | The document with every update written in. |
Internals 10
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | setToken(string $type, string $name, int $start, int $end, int $textStart, int $textLength): void# | ||||
| private | resetToken(): void# | ||||
| private | takeTag(int $at, bool $closer): bool# | A tag the scanner read at $at becomes the current token; a raw-text element carries its body to its closer. | |||
| private | take(?array $found): bool# | A comment, doctype, or processing instruction the scanner read becomes the current token; null pauses. | |||
| private | baseClassList(): array# | @return list<string> | |||
| private | baseClassValue(): ?string# | ||||
| private | flush(): void# | Writes every pending update into the source, keeping bookmarks and the current token aligned. | |||
| private | applyReplacements(array $replacements): void# |
| |||
| private | rescanCurrent(): void# | Re-reads the current token so attribute offsets match the new source. | |||
| private | rescan(): void# |
Nothing matches.