API / Minn\Blocks / Parser

Parser final class

Minn\Blocks\Parser · public/minn/src/Minn/Blocks/Parser.php · 114 lines

Parses block markup into a tree. The grammar is the delimiter comment: an opener with optional JSON attributes, a closer, or a self-closing void block; a name without a namespace is core/. Anything outside a block is a freeform block that renders as-is.

Uses 2

Constants and properties

privateTOKEN = '/<!--\\s+(?P<closer>\\/)?wp:(?P<namespace>[a-z][a-z0-9_-]*\\/)?(?P<name>[a-z][a-z0-9_-]*)\\s+(?P<attrs>\\{(?:(?!\\}\\s+\\/?-->).)*+\\}\\s+)?(?P<void>\\/)?-->/s'

Public

staticparse(string $markup): array#

Block markup as a tree of blocks.

@return list<Block>
statictoken(string $markup, int $offset): ?array#

The first block delimiter at or after an offset: where it starts, its length, its name (core/ when it names no namespace), its attributes as written (null when it has none), and whether it closes a block or is a void one. Null when no delimiter follows.

@return array{start: int, length: int, name: string, attrs: ?string, closer: bool, void: bool}|null
staticcontains(string $content, string $name): bool#

Whether serialized content carries a block by name; a bare name means core/, and core blocks are also found by their short delimiter.