Abstract Class cebe\markdown\Parser

Inheritancecebe\markdown\Parser
Subclassescebe\markdown\GithubMarkdown, cebe\markdown\Markdown, cebe\markdown\MarkdownExtra, cebe\markdown\latex\GithubMarkdown, cebe\markdown\latex\Markdown

A generic parser for markdown-like languages.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$maximumNestingLevel integer The maximum nesting level for language elements. cebe\markdown\Parser

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$context string The current context the parser is in. cebe\markdown\Parser
$escapeCharacters array These are "escapeable" characters. cebe\markdown\Parser

Public Methods

Hide inherited methods

MethodDescriptionDefined By
parse() Parses the given text considering the full language. cebe\markdown\Parser
parseParagraph() Parses a paragraph without block elements (block elements are ignored). cebe\markdown\Parser

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
blockTypes() cebe\markdown\Parser
cleanup() This method will be called after parse() and parseParagraph(). cebe\markdown\Parser
consumeParagraph() Consume lines for a paragraph cebe\markdown\Parser
detectLineType() Given a set of lines and an index of a current line it uses the registed block types to detect the type of this line. cebe\markdown\Parser
inlineMarkers() Returns a map of inline markers to the corresponding parser methods. cebe\markdown\Parser
parseBlocks() Parse block elements by calling identifyLine() to identify them and call consume function afterwards. cebe\markdown\Parser
parseEscape() Parses escaped special characters. cebe\markdown\Parser
parseInline() Parses inline elements of the language. cebe\markdown\Parser
prepare() This method will be called before parse() and parseParagraph(). cebe\markdown\Parser
renderAbsy() cebe\markdown\Parser
renderParagraph() Render a paragraph block cebe\markdown\Parser
renderText() This function renders plain text sections in the markdown text. cebe\markdown\Parser

Property Details

$context protected property

The current context the parser is in. TODO remove in favor of absy

protected string $context = []
$escapeCharacters protected property

These are "escapeable" characters. When using one of these prefixed with a backslash, the character will be outputted without the backslash and is not interpreted as markdown.

protected array $escapeCharacters = ['\\']
$maximumNestingLevel public property

The maximum nesting level for language elements.

Method Details

blockTypes() protected method

protected array blockTypes ( )
return array

A list of block element types available.

cleanup() protected method

This method will be called after parse() and parseParagraph().

You can override it to do cleanup.

protected void cleanup ( )
consumeParagraph() protected method

Consume lines for a paragraph

protected array consumeParagraph ( $lines, $current )
$lines
$current
detectLineType() protected method

Given a set of lines and an index of a current line it uses the registed block types to detect the type of this line.

protected string detectLineType ( $lines, $current )
$lines array
$current integer
return string

Name of the block type in lower case

inlineMarkers() protected method

Returns a map of inline markers to the corresponding parser methods.

This array defines handler methods for inline markdown markers. When a marker is found in the text, the handler method is called with the text starting at the position of the marker.

Note that markers starting with whitespace may slow down the parser, you may want to use renderText() to deal with them.

You may override this method to define a set of markers and parsing methods. The default implementation looks for protected methods starting with parse that also have an @marker annotation in PHPDoc.

protected array inlineMarkers ( )
return array

A map of markers to parser methods

parse() public method

Parses the given text considering the full language.

This includes parsing block elements as well as inline elements.

public string parse ( $text )
$text string

The text to parse

return string

Parsed markup

parseBlocks() protected method

Parse block elements by calling identifyLine() to identify them and call consume function afterwards.

The blocks are then rendered by the corresponding rendering methods.

protected void parseBlocks ( $lines )
$lines
parseEscape() protected method

Parses escaped special characters.

protected void parseEscape ( $text )
$text
parseInline() protected method

Parses inline elements of the language.

protected array parseInline ( $text )
$text string

The inline text to parse.

parseParagraph() public method

Parses a paragraph without block elements (block elements are ignored).

public string parseParagraph ( $text )
$text string

The text to parse

return string

Parsed markup

prepare() protected method

This method will be called before parse() and parseParagraph().

You can override it to do some initialization work.

protected void prepare ( )
renderAbsy() protected method

protected void renderAbsy ( $blocks )
$blocks
renderParagraph() protected method

Render a paragraph block

protected string renderParagraph ( $block )
$block
renderText() protected method

This function renders plain text sections in the markdown text.

It can be used to work on normal text sections for example to highlight keywords or do special escaping.

protected void renderText ( $block )
$block