Copied!

Markdown parser for github flavored markdown.

CloneableInstantiable
Properties
public $enableNewlines = false
 
  • var bool whether to interpret newlines as <br />-tags.
    This feature is useful for comments where newlines are often meant to be real new lines.
public cebe\markdown\Markdown::$html5 = false
 
  • var bool whether to format markup according to HTML5 spec.
    Defaults to false which means that markup is formatted as HTML4.
public cebe\markdown\Markdown::$keepListStartNumber = false
 
  • 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 = 32
 
  • 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.

  • param string $text the text to parse
  • return string parsed markup
public cebe\markdown\Parser::parseParagraph( $text)
 

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

  • param string $text the text to parse
  • 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 = ['\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '#', '+', '-', '.', '!', '<', '>', ':', '|']
 
  • inheritDoc
protected cebe\markdown\Markdown::$inlineHtmlElements = ['a', 'abbr', 'acronym', 'b', 'basefont', 'bdo', 'big', 'br', 'button', 'blink', 'cite', 'code', 'del', 'dfn', 'em', 'font', 'i', 'img', 'ins', 'input', 'iframe', 'kbd', 'label', 'listing', 'map', 'mark', 'nobr', 'object', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'script', 'select', 'small', 'spacer', 'span', 'strong', 'sub', 'sup', 'tt', 'var', 'u', 'wbr', 'time']
 
  • var array HTML elements considered as inline elements.
  • see http://www.w3.org/wiki/HTML/Elements#Text-level_semantics
protected cebe\markdown\Markdown::$references = []
 
  • var array a list of defined references in this document.
protected cebe\markdown\Markdown::$selfClosingHtmlElements = ['br', 'hr', 'img', 'input', 'nobr']
 
  • 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 composeTable( $head, $body)
 

This method composes a table from parsed body and head HTML.

You may override this method to customize the table rendering, for example by
adding a class to the table tag:

return "">\n\n$head\n\n$body\n
\n"
  • param string $head table head HTML.
  • param string $body table body HTML.
  • return string the complete table HTML.
  • since 1.2.0
protected cebe\markdown\Markdown::consumeAHr( $lines, $current)
 

Consume a horizontal rule

protected cebe\markdown\Markdown::consumeBUl( $lines, $current)
 

Consume lines for an unordered list

protected consumeCode( $lines, $current)
 

Consume lines for a code block element

protected consumeFencedCode( $lines, $current)
 

Consume lines for a fenced code block

protected cebe\markdown\Markdown::consumeHeadline( $lines, $current)
 

Consume lines for a headline

protected cebe\markdown\Markdown::consumeHr( $lines, $current)
 

Consume a horizontal rule

protected cebe\markdown\Markdown::consumeHtml( $lines, $current)
 

Consume lines for an HTML block

protected cebe\markdown\Markdown::consumeOl( $lines, $current)
 

Consume lines for an ordered list

protected consumeParagraph( $lines, $current)
 

Consume lines for a paragraph

Allow headlines, lists and code to break paragraphs

protected cebe\markdown\Markdown::consumeQuote( $lines, $current)
 

Consume lines for a blockquote element

protected cebe\markdown\Markdown::consumeReference( $lines, $current)
 

Consume link references

protected consumeTable( $lines, $current)
 

Consume lines for a table

protected cebe\markdown\Markdown::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.

  • param array $lines
  • param int $current
  • return string name of the block type in lower case
protected cebe\markdown\Markdown::identifyAHr( $line)
 

identify a line as a horizontal rule.

protected cebe\markdown\Markdown::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 identifyFencedCode( $line)
 

identify a line as the beginning of a fenced code block.

protected cebe\markdown\Markdown::identifyHeadline( $line, $lines, $current)
 

identify a line as a headline

protected cebe\markdown\Markdown::identifyHr( $line)
 

identify a line as a horizontal rule.

protected cebe\markdown\Markdown::identifyHtml( $line, $lines, $current)
 

identify a line as the beginning of a HTML block.

protected cebe\markdown\Markdown::identifyOl( $line)
 

identify a line as the beginning of an ordered list.

protected cebe\markdown\Markdown::identifyQuote( $line)
 

identify a line as the beginning of a block quote.

protected cebe\markdown\Markdown::identifyReference( $line)
protected identifyTable( $line, $lines, $current)
 

identify a line as the beginning of a table block.

protected cebe\markdown\Markdown::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 cebe\markdown\Markdown::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 cebe\markdown\Markdown::parseEmphStrong( $text)
 

Parses emphasized and strong elements.

  • marker _
  • marker *
protected cebe\markdown\Markdown::parseEntity( $text)
 

Parses an & or a html entity definition.

  • marker &
protected cebe\markdown\Parser::parseEscape( $text)
 

Parses escaped special characters.

  • marker \
protected cebe\markdown\Markdown::parseGt( $text)
 

Escapes > characters.

  • marker >
protected cebe\markdown\Markdown::parseImage( $markdown)
 

Parses an image indicated by ![.

  • marker ![
protected cebe\markdown\Parser::parseInline( $text)
 

Parses inline elements of the language.

  • param string $text the inline text to parse.
  • return array
protected cebe\markdown\Markdown::parseInlineCode( $text)
 

Parses an inline code span `.

  • marker `
protected cebe\markdown\Markdown::parseLink( $markdown)
 

Parses a link indicated by [.

  • marker [
protected cebe\markdown\Markdown::parseLinkOrImage( $markdown)
protected cebe\markdown\Markdown::parseLt( $text)
 

Parses inline HTML.

  • marker <
protected parseStrike( $markdown)
 

Parses the strikethrough feature.

  • marker ~~
protected parseTd( $markdown)
 
  • marker |
protected parseUrl( $markdown)
 

Parses urls and adds auto linking feature.

  • marker http
  • marker ftp
protected cebe\markdown\Markdown::prepare()
 

You can override it to do some initialization work.

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

  • param string $text
protected cebe\markdown\Parser::renderAbsy( $blocks)
protected renderAutoUrl( $block)
protected renderCode( $block)
 

Renders a code block

protected cebe\markdown\Markdown::renderEmail( $block)
protected cebe\markdown\Markdown::renderEmph( $block)
protected cebe\markdown\Markdown::renderHeadline( $block)
 

Renders a headline

protected cebe\markdown\Markdown::renderHr( $block)
 

Renders a horizontal rule

protected cebe\markdown\Markdown::renderHtml( $block)
 

Renders an HTML block

protected cebe\markdown\Markdown::renderImage( $block)
protected cebe\markdown\Markdown::renderInlineCode( $block)
protected cebe\markdown\Markdown::renderInlineHtml( $block)
 

renders a html entity.

protected cebe\markdown\Markdown::renderLink( $block)
protected cebe\markdown\Markdown::renderList( $block)
 

Renders a list

protected cebe\markdown\Parser::renderParagraph( $block)
 

Render a paragraph block

  • return string
protected cebe\markdown\Markdown::renderQuote( $block)
 

Renders a blockquote

protected renderStrike( $block)
protected cebe\markdown\Markdown::renderStrong( $block)
protected renderTable( $block)
 

render a table block

protected renderText( $text)
 

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

protected cebe\markdown\Markdown::renderUrl( $block)
protected cebe\markdown\Markdown::replaceEscape( $text)
 

Remove backslash from escaped characters

  • return string
© 2023 Bruce Wells
Search Namespaces \ Classes
Configuration