You are here

public function BlockParser::parse in Gutenberg 8.2

Parses a document and returns a list of block structures.

When encountering an invalid parse will return a best-effort parse. In contrast to the specification parser this does not return an error on invalid inputs.

@since 3.8.0

Parameters

string $document: Input document being parsed.

callable|null $filter_callable: A callback function to filter blocks with. It should return FALSE if the block should be skipped.

Return value

array The list of Gutenberg blocks.

File

src/Parser/BlockParser.php, line 89

Class

BlockParser
Class BlockParser.

Namespace

Drupal\gutenberg\Parser

Code

public function parse($document, callable $filter_callable = NULL) {
  $this->document = $document;
  $this->filterCallable = $filter_callable;
  $this->offset = 0;
  $this->output = [];
  $this->stack = [];
  $this->emptyAttrs = json_decode('{}', TRUE);
  do {

    // Twiddle our thumbs.
  } while ($this
    ->proceed());
  return $this->output;
}