Block parsers should extend from
AbstractBlockParser and implement the following method:
When parsing a new line, the
DocParser iterates through all registered block parsers and calls their
parse() method. Each parser must determine whether it can handle the given line; if so, it should parse the given block and return true.
ContextInterface $context- Provides information about the current context of the DocParser. Includes access to things like the document, current block container, and more.
Cursor $cursor- Encapsulates the current state of the line being parsed and provides helpers for looking around the current position.
parse() should return
false if it’s unable to handle the current line for any reason. (The
Cursor state should be restored before returning false if modified). Other parsers will then have a chance to try parsing the line. If all registered parsers return false, the line will be parsed as text.
true tells the engine that you’ve successfully parsed the block at the given position. It is your responsibility to:
- Advance the cursor to the end of syntax indicating the block start
- Add the parsed block via
- For best performance,
return falseas soon as possible