Abstract Class cebe\markdown\Parser
Inheritance | cebe\markdown\Parser |
---|---|
Subclasses | cebe\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
Property | Type | Description | Defined By |
---|---|---|---|
$maximumNestingLevel | integer | The maximum nesting level for language elements. | cebe\markdown\Parser |
Protected Properties
Property | Type | Description | Defined By |
---|---|---|---|
$context | string | The current context the parser is in. | cebe\markdown\Parser |
$escapeCharacters | array | These are "escapeable" characters. | cebe\markdown\Parser |
Public Methods
Method | Description | Defined 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
Method | Description | Defined 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
The current context the parser is in. TODO remove in favor of absy
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.
The maximum nesting level for language elements.
Method Details
protected array blockTypes ( ) | ||
return | array | A list of block element types available. |
---|
This method will be called after parse()
and parseParagraph()
.
You can override it to do cleanup.
protected void cleanup ( ) |
Consume lines for a paragraph
protected array consumeParagraph ( $lines, $current ) | ||
$lines | ||
$current |
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 |
---|
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 |
---|
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 |
---|
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 |
Parses escaped special characters.
protected void parseEscape ( $text ) | ||
$text |
Parses inline elements of the language.
protected array parseInline ( $text ) | ||
$text | string | The inline text to parse. |
Parses a paragraph without block elements (block elements are ignored).
public string parseParagraph ( $text ) | ||
$text | string | The text to parse |
return | string | Parsed markup |
---|
This method will be called before parse()
and parseParagraph()
.
You can override it to do some initialization work.
protected void prepare ( ) |
protected void renderAbsy ( $blocks ) | ||
$blocks |
Render a paragraph block
protected string renderParagraph ( $block ) | ||
$block |
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 |