API / Minn\Html / Scanner

Scanner final class

Minn\Html\Scanner · public/minn/src/Minn/Html/Scanner.php · 291 lines

Reads one token's shape out of raw HTML at an offset: a tag with its name and attributes, a comment of one of the reference's kinds, a doctype, or a processing instruction. Pure and stateless; null means the input ends before the token does, which is where a streaming reader pauses.

Public

statictag(string $html, int $at, int $nameStart): ?array#

A tag starting at $at, its name from $nameStart (one byte in for an opener, two for a closer): the name, where it ends, the end offset, the attributes with their source offsets, and the self-closing flag.

@return array{name: string, nameEnd: int, end: int, attributes: list<array{name: string, lower: string, start: int, end: int, value: ?string, quoted: bool}>, selfClosing: bool}|null
staticrawText(string $html, string $name, int $from): ?array#

A raw-text element's body (script, style, textarea, ...): from $from to its closing tag, or null when the closer never comes.

@return array{textStart: int, textLength: int, end: int}|null
staticmarkupDeclaration(string $html, int $at): ?array#

What "<!" opens at $at: an HTML comment (abruptly closed or not), a doctype, a CDATA lookalike, or a bogus comment.

@return array{kind: string, start: int, end: int, textStart: int, textLength: int, commentType?: string, fullStart?: int, fullLength?: int}|null
staticquestion(string $html, int $at): ?array#

What "<?" opens at $at: a processing instruction when an ASCII alphanumeric target (not "xml") is followed by space, "?" or ">" (its text after the space, up to "?>" or ">"); a PI lookalike comment for another XML name closed by "?>"; otherwise an invalid comment.

@return array{kind: string, start: int, end: int, textStart: int, textLength: int, target?: string, commentType?: string, fullStart?: int, fullLength?: int}|null
staticattributeValue(array $attributes, string $lower): string|true|null#

A source attribute's decoded value (true when it has none), or null when the tag lacks it.

$attributeslist<array{lower: string, value: ?string}>
staticopensMarkup(string $html, int $at): bool#

Whether the "<" at $at opens markup: a tag, a closer, "<!" or "<?".

statictextEnd(string $html, int $at): int#

Where text starting at $at ends: at the next "<" that opens markup, before a "<" ending the input, or at the end.

staticcdata(string $html, int $at): ?array#

A CDATA section in foreign content, "<![CDATA[" to "]]>"; null when it does not close.

@return array{kind: string, start: int, end: int, textStart: int, textLength: int}|null
staticdoctype(string $body): array#

A doctype's body split into its name and public and system identifiers.

@return array{name: ?string, public: ?string, system: ?string}
staticisSpace(string $c): bool#

Whether a byte is HTML whitespace.

Internals 2

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privateattribute(string $html, int $i): ?array#

One attribute from $i: its name (a leading "=" is part of it), then an optional quoted or bare value. Null when the input ends first.

@return array{int, string, int, int, ?string, bool}|null offset after, name, start, end, value, quoted
privatecomment(int $start, int $end, int $textStart, int $textLength, string $type, int $fullStart, int $fullLength): array#
@return array{kind: string, start: int, end: int, textStart: int, textLength: int, commentType: string, fullStart: int, fullLength: int}