Markdown parser for the [initial markdown spec](http://daringfireball.net/projects/markdown/syntax).

CloneableInstantiable
Extendscebe\markdown\Parser
Properties
public $html5
 


  • var bool whether to format markup according to HTML5 spec. Defaults to `false` which means that markup is formatted as HTML4.
public $keepListStartNumber
 


  • var bool enable support `start` attribute of ordered lists. This means that lists will start with the number you actually type in markdown and not the HTML generated one. Defaults to `false` which means that numeration of all ordered lists(
      ) starts with 1.
public cebe\markdown\Parser::$maximumNestingLevel
 


  • var int the maximum nesting level for language elements.
Methods
public cebe\markdown\Parser::parse( $text)
 
Parses the given text considering the full language.

This includes parsing block elements as well as inline elements.

  • return string parsed markup
public cebe\markdown\Parser::parseParagraph( $text)
 
Parses a paragraph without block elements (block elements are ignored).

  • return string parsed markup
Properties
protected cebe\markdown\Parser::$context
 


  • var array the current context the parser is in. TODO remove in favor of absy
protected $escapeCharacters
 


  • var array 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 $inlineHtmlElements
 


  • var array HTML elements considered as inline elements.
  • see http://www.w3.org/wiki/HTML/Elements#Text-level_semantics
protected $references
 


  • var array a list of defined references in this document.
protected $selfClosingHtmlElements
 


  • var array HTML elements known to be self-closing.
Methods
protected cebe\markdown\Parser::blockTypes()
 


  • return array a list of block element types available.
protected cebe\markdown\Parser::cleanup()
 
This method will be called after `parse()` and `parseParagraph()`.

You can override it to do cleanup.

protected consumeAHr( $lines, $current)
 
Consume a horizontal rule

protected consumeBUl( $lines, $current)
 
Consume lines for an unordered list

protected consumeCode( $lines, $current)
 
Consume lines for a code block element

protected consumeHeadline( $lines, $current)
 
Consume lines for a headline

protected consumeHr( $lines, $current)
 
Consume a horizontal rule

protected consumeHtml( $lines, $current)
 
Consume lines for an HTML block

protected consumeOl( $lines, $current)
 
Consume lines for an ordered list

protected consumeParagraph( $lines, $current)
 
Consume lines for a paragraph

Allow headlines and code to break paragraphs

protected consumeQuote( $lines, $current)
 
Consume lines for a blockquote element

protected consumeReference( $lines, $current)
 
Consume link references

protected consumeUl( $lines, $current)
 
Consume lines for an unordered list

protected cebe\markdown\Parser::detectLineType( $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.

  • return string name of the block type in lower case
protected identifyAHr( $line)
 
identify a line as a horizontal rule.

protected identifyBUl( $line)
 
identify a line as the beginning of an unordered list.

protected identifyCode( $line)
 
identify a line as the beginning of a code block.

protected identifyHeadline( $line, $lines, $current)
 
identify a line as a headline

protected identifyHr( $line)
 
identify a line as a horizontal rule.

protected identifyHtml( $line, $lines, $current)
 
identify a line as the beginning of a HTML block.

protected identifyOl( $line)
 
identify a line as the beginning of an ordered list.

protected identifyQuote( $line)
 
identify a line as the beginning of a block quote.

protected identifyReference( $line)
protected identifyUl( $line)
 
identify a line as the beginning of an unordered list.

protected cebe\markdown\Parser::inlineMarkers()
 
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.

  • return array a map of markers to parser methods
protected lookupReference( $key)
protected cebe\markdown\Parser::parseBlock( $lines, $current)
 
Parses the block at current line by identifying the block type and parsing the content

  • return array Array of two elements, the first element contains the block, the second contains the next line index to be parsed.
protected cebe\markdown\Parser::parseBlocks( $lines)
 
Parse block elements by calling `detectLineType()` to identify them and call consume function afterwards.

protected parseEmphStrong( $text)
 
Parses emphasized and strong elements.

  • marker _
  • marker *
protected parseEntity( $text)
 
Parses an & or a html entity definition.

  • marker &
protected cebe\markdown\Parser::parseEscape( $text)
 
Parses escaped special characters.

  • marker \
protected parseGt( $text)
 
Escapes `>` characters.

  • marker >
protected parseImage( $markdown)
 
Parses an image indicated by `![`.

  • marker ![
protected cebe\markdown\Parser::parseInline( $text)
 
Parses inline elements of the language.

  • return array
protected parseInlineCode( $text)
 
Parses an inline code span `` ` ``.

  • marker `
protected parseLink( $markdown)
protected parseLinkOrImage( $markdown)
protected parseLt( $text)
 
Parses inline HTML.

  • marker <
protected prepare()
 


  • inheritDoc
protected cebe\markdown\Parser::prepareMarkers( $text)
 
Prepare markers that are used in the text to parse

Add all markers that are present in markdown.
Check is done to avoid iterations in parseInline(), good for huge markdown files

    protected cebe\markdown\Parser::renderAbsy( $blocks)
    protected renderCode( $block)
     
    Renders a code block

    protected renderEmail( $block)
    protected renderEmph( $block)
    protected renderHeadline( $block)
     
    Renders a headline

    protected renderHr( $block)
     
    Renders a horizontal rule

    protected renderHtml( $block)
     
    Renders an HTML block

    protected renderImage( $block)
    protected renderInlineCode( $block)
    protected renderInlineHtml( $block)
     
    renders a html entity.

    protected renderLink( $block)
    protected renderList( $block)
     
    Renders a list

    protected cebe\markdown\Parser::renderParagraph( $block)
     
    Render a paragraph block

    • return string
    protected renderQuote( $block)
     
    Renders a blockquote

    protected renderStrong( $block)
    protected renderText( $text)
     


    • inheritdocs Parses a newline indicated by two spaces on the end of a markdown line.
    protected renderUrl( $block)
    protected replaceEscape( $text)
     
    Remove backslash from escaped characters

    • return string
    Methods
    private consumeList( $lines, $current, $block, $type)
    private generateHtmlAttributes( $attributes)
     
    Return html attributes string from [attrName => attrValue] list

    • return string
    private parseInlineHtml( $text)
     
    Parses inline HTML.

    • marker <
    © 2020 Bruce Wells
    Search Namespaces \ Classes
    ConfigurationNumbers (0-9.) only