HumHub Documentation (unofficial)

Markdown extends Parser
in package
uses CodeTrait, HeadlineTrait, HtmlTrait, ListTrait, QuoteTrait, RuleTrait, CodeTrait, EmphStrongTrait, LinkTrait

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

Tags
author

Carsten Brandt mail@cebe.cc

Table of Contents

Properties

$html5  : bool
$keepListStartNumber  : bool
$maximumNestingLevel  : int
$context  : array<string|int, mixed>
$escapeCharacters  : array<string|int, mixed>
$inlineHtmlElements  : array<string|int, mixed>
$references  : array<string|int, mixed>
$selfClosingHtmlElements  : array<string|int, mixed>
$_blockTypes  : mixed
$_depth  : mixed
$_inlineMarkers  : array<string|int, mixed>

Methods

parse()  : string
Parses the given text considering the full language.
parseParagraph()  : string
Parses a paragraph without block elements (block elements are ignored).
blockTypes()  : array<string|int, mixed>
cleanup()  : mixed
This method will be called after `parse()` and `parseParagraph()`.
consumeCode()  : mixed
Consume lines for a code block element
consumeHeadline()  : mixed
Consume lines for a headline
consumeHr()  : mixed
Consume a horizontal rule
consumeHtml()  : mixed
Consume lines for an HTML block
consumeOl()  : mixed
Consume lines for an ordered list
consumeParagraph()  : array<string|int, mixed>
Consume lines for a paragraph
consumeQuote()  : mixed
Consume lines for a blockquote element
consumeReference()  : mixed
Consume link references
consumeUl()  : mixed
Consume lines for an unordered list
detectLineType()  : mixed
identifyCode()  : mixed
identify a line as the beginning of a code block.
identifyHeadline()  : mixed
identify a line as a headline
identifyHr()  : mixed
identify a line as a horizontal rule.
identifyHtml()  : mixed
identify a line as the beginning of a HTML block.
identifyOl()  : mixed
identify a line as the beginning of an ordered list.
identifyQuote()  : mixed
identify a line as the beginning of a block quote.
identifyReference()  : mixed
identifyUl()  : mixed
identify a line as the beginning of an unordered list.
inlineMarkers()  : array<string|int, mixed>
Returns a map of inline markers to the corresponding parser methods.
lookupReference()  : mixed
parseBlock()  : array<string|int, mixed>
Parses the block at current line by identifying the block type and parsing the content
parseBlocks()  : mixed
parseEmphStrong()  : mixed
Parses emphasized and strong elements.
parseEntity()  : mixed
Parses an & or a html entity definition.
parseEscape()  : mixed
Parses escaped special characters.
parseGt()  : mixed
Escapes `>` characters.
parseImage()  : mixed
Parses an image indicated by `![`.
parseInline()  : mixed
parseInlineCode()  : mixed
Parses an inline code span `` ` ``.
parseInlineHtml()  : mixed
Parses inline HTML.
parseLink()  : mixed
Parses a link indicated by `[`.
parseLinkOrImage()  : mixed
parseLt()  : mixed
Parses inline HTML.
prepare()  : mixed
This method will be called before `parse()` and `parseParagraph()`.
prepareMarkers()  : mixed
Prepare markers that are used in the text to parse
renderAbsy()  : mixed
renderCode()  : mixed
Renders a code block
renderEmail()  : mixed
renderEmph()  : mixed
renderHeadline()  : mixed
Renders a headline
renderHr()  : mixed
Renders a horizontal rule
renderHtml()  : mixed
Renders an HTML block
renderImage()  : mixed
renderInlineCode()  : mixed
renderInlineHtml()  : mixed
renders a html entity.
renderLink()  : mixed
renderList()  : mixed
Renders a list
renderParagraph()  : string
Render a paragraph block
renderQuote()  : mixed
Renders a blockquote
renderStrong()  : mixed
renderText()  : mixed
This function renders plain text sections in the markdown text.
renderUrl()  : mixed
replaceEscape()  : string
Remove backslash from escaped characters
consumeList()  : mixed
generateHtmlAttributes()  : string
Return html attributes string from [attrName => attrValue] list

Properties

$html5

public bool $html5 = false

whether to format markup according to HTML5 spec. Defaults to false which means that markup is formatted as HTML4.

$keepListStartNumber

public bool $keepListStartNumber = false

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.

$maximumNestingLevel

public int $maximumNestingLevel = 32

the maximum nesting level for language elements.

$context

protected array<string|int, mixed> $context = []

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

$escapeCharacters

protected array<string|int, mixed> $escapeCharacters = [ '\\', // backslash '`', // backtick '*', // asterisk '_', // underscore '{', '}', // curly braces '[', ']', // square brackets '(', ')', // parentheses '#', // hash mark '+', // plus sign '-', // minus sign (hyphen) '.', // dot '!', // exclamation mark '<', '>', ]

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.

$inlineHtmlElements

protected array<string|int, mixed> $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']

HTML elements considered as inline elements.

Tags
see
http://www.w3.org/wiki/HTML/Elements#Text-level_semantics

$references

protected array<string|int, mixed> $references = []

a list of defined references in this document.

$selfClosingHtmlElements

protected array<string|int, mixed> $selfClosingHtmlElements = ['br', 'hr', 'img', 'input', 'nobr']

HTML elements known to be self-closing.

$_blockTypes

private mixed $_blockTypes

$_depth

private mixed $_depth = 0

$_inlineMarkers

private array<string|int, mixed> $_inlineMarkers = []

the set of inline markers to use in different contexts.

Methods

parse()

Parses the given text considering the full language.

public parse(string $text) : string

This includes parsing block elements as well as inline elements.

Parameters
$text : string

the text to parse

Return values
string

parsed markup

parseParagraph()

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

public parseParagraph(string $text) : string
Parameters
$text : string

the text to parse

Return values
string

parsed markup

blockTypes()

protected blockTypes() : array<string|int, mixed>
Return values
array<string|int, mixed>

a list of block element types available.

cleanup()

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

protected cleanup() : mixed

You can override it to do cleanup.

consumeCode()

Consume lines for a code block element

protected consumeCode(mixed $lines, mixed $current) : mixed
Parameters
$lines : mixed
$current : mixed

consumeHeadline()

Consume lines for a headline

protected consumeHeadline(mixed $lines, mixed $current) : mixed
Parameters
$lines : mixed
$current : mixed

consumeHr()

Consume a horizontal rule

protected consumeHr(mixed $lines, mixed $current) : mixed
Parameters
$lines : mixed
$current : mixed

consumeHtml()

Consume lines for an HTML block

protected consumeHtml(mixed $lines, mixed $current) : mixed
Parameters
$lines : mixed
$current : mixed

consumeOl()

Consume lines for an ordered list

protected consumeOl(mixed $lines, mixed $current) : mixed
Parameters
$lines : mixed
$current : mixed

consumeParagraph()

Consume lines for a paragraph

protected consumeParagraph(mixed $lines, mixed $current) : array<string|int, mixed>

Allow headlines and code to break paragraphs

Parameters
$lines : mixed
$current : mixed
Return values
array<string|int, mixed>

consumeQuote()

Consume lines for a blockquote element

protected consumeQuote(mixed $lines, mixed $current) : mixed
Parameters
$lines : mixed
$current : mixed

consumeReference()

Consume link references

protected consumeReference(mixed $lines, mixed $current) : mixed
Parameters
$lines : mixed
$current : mixed

consumeUl()

Consume lines for an unordered list

protected consumeUl(mixed $lines, mixed $current) : mixed
Parameters
$lines : mixed
$current : mixed

detectLineType()

protected abstract detectLineType(mixed $lines, mixed $current) : mixed
Parameters
$lines : mixed
$current : mixed

identifyCode()

identify a line as the beginning of a code block.

protected identifyCode(mixed $line) : mixed
Parameters
$line : mixed

identifyHeadline()

identify a line as a headline

protected identifyHeadline(mixed $line, mixed $lines, mixed $current) : mixed
Parameters
$line : mixed
$lines : mixed
$current : mixed

identifyHr()

identify a line as a horizontal rule.

protected identifyHr(mixed $line) : mixed
Parameters
$line : mixed

identifyHtml()

identify a line as the beginning of a HTML block.

protected identifyHtml(mixed $line, mixed $lines, mixed $current) : mixed
Parameters
$line : mixed
$lines : mixed
$current : mixed

identifyOl()

identify a line as the beginning of an ordered list.

protected identifyOl(mixed $line) : mixed
Parameters
$line : mixed

identifyQuote()

identify a line as the beginning of a block quote.

protected identifyQuote(mixed $line) : mixed
Parameters
$line : mixed

identifyReference()

protected identifyReference(mixed $line) : mixed
Parameters
$line : mixed

identifyUl()

identify a line as the beginning of an unordered list.

protected identifyUl(mixed $line) : mixed
Parameters
$line : mixed

inlineMarkers()

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

protected inlineMarkers() : array<string|int, mixed>

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 values
array<string|int, mixed>

a map of markers to parser methods

lookupReference()

protected lookupReference(mixed $key) : mixed
Parameters
$key : mixed

parseBlock()

Parses the block at current line by identifying the block type and parsing the content

protected parseBlock(mixed $lines, mixed $current) : array<string|int, mixed>
Parameters
$lines : mixed
$current : mixed
Return values
array<string|int, mixed>

Array of two elements, the first element contains the block, the second contains the next line index to be parsed.

parseBlocks()

protected abstract parseBlocks(mixed $lines) : mixed
Parameters
$lines : mixed

parseEmphStrong()

Parses emphasized and strong elements.

protected parseEmphStrong(mixed $text) : mixed
Parameters
$text : mixed
Tags
marker

_

marker

parseEntity()

Parses an & or a html entity definition.

protected parseEntity(mixed $text) : mixed
Parameters
$text : mixed
Tags
marker

&

parseEscape()

Parses escaped special characters.

protected parseEscape(mixed $text) : mixed
Parameters
$text : mixed
Tags
marker

\

parseGt()

Escapes `>` characters.

protected parseGt(mixed $text) : mixed
Parameters
$text : mixed
Tags
marker

parseImage()

Parses an image indicated by `![`.

protected parseImage(mixed $markdown) : mixed
Parameters
$markdown : mixed
Tags
marker

![

parseInline()

protected abstract parseInline(mixed $text) : mixed
Parameters
$text : mixed

parseInlineCode()

Parses an inline code span `` ` ``.

protected parseInlineCode(mixed $text) : mixed
Parameters
$text : mixed
Tags
marker

`

parseInlineHtml()

Parses inline HTML.

protected parseInlineHtml(mixed $text) : mixed
Parameters
$text : mixed
Tags
marker

<

Parses a link indicated by `[`.

protected parseLink(mixed $markdown) : mixed
Parameters
$markdown : mixed
Tags
marker

[

parseLinkOrImage()

protected parseLinkOrImage(mixed $markdown) : mixed
Parameters
$markdown : mixed

parseLt()

Parses inline HTML.

protected parseLt(mixed $text) : mixed
Parameters
$text : mixed
Tags
marker

<

prepare()

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

protected prepare() : mixed
Tags
inheritDoc

prepareMarkers()

Prepare markers that are used in the text to parse

protected prepareMarkers(string $text) : mixed

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

Parameters
$text : string

renderAbsy()

protected abstract renderAbsy(mixed $absy) : mixed
Parameters
$absy : mixed

renderCode()

Renders a code block

protected renderCode(mixed $block) : mixed
Parameters
$block : mixed

renderEmail()

protected renderEmail(mixed $block) : mixed
Parameters
$block : mixed

renderEmph()

protected renderEmph(mixed $block) : mixed
Parameters
$block : mixed

renderHeadline()

Renders a headline

protected renderHeadline(mixed $block) : mixed
Parameters
$block : mixed

renderHr()

Renders a horizontal rule

protected renderHr(mixed $block) : mixed
Parameters
$block : mixed

renderHtml()

Renders an HTML block

protected renderHtml(mixed $block) : mixed
Parameters
$block : mixed

renderImage()

protected renderImage(mixed $block) : mixed
Parameters
$block : mixed

renderInlineCode()

protected renderInlineCode(mixed $block) : mixed
Parameters
$block : mixed

renderInlineHtml()

renders a html entity.

protected renderInlineHtml(mixed $block) : mixed
Parameters
$block : mixed
protected renderLink(mixed $block) : mixed
Parameters
$block : mixed

renderList()

Renders a list

protected renderList(mixed $block) : mixed
Parameters
$block : mixed

renderParagraph()

Render a paragraph block

protected renderParagraph(mixed $block) : string
Parameters
$block : mixed
Return values
string

renderQuote()

Renders a blockquote

protected renderQuote(mixed $block) : mixed
Parameters
$block : mixed

renderStrong()

protected renderStrong(mixed $block) : mixed
Parameters
$block : mixed

renderText()

This function renders plain text sections in the markdown text.

protected renderText(mixed $text) : mixed
Parameters
$text : mixed
Tags
inheritdocs

Parses a newline indicated by two spaces on the end of a markdown line.

renderUrl()

protected renderUrl(mixed $block) : mixed
Parameters
$block : mixed

replaceEscape()

Remove backslash from escaped characters

protected replaceEscape(mixed $text) : string
Parameters
$text : mixed
Return values
string

consumeList()

private consumeList(mixed $lines, mixed $current, mixed $block, mixed $type) : mixed
Parameters
$lines : mixed
$current : mixed
$block : mixed
$type : mixed

generateHtmlAttributes()

Return html attributes string from [attrName => attrValue] list

private generateHtmlAttributes(array<string|int, mixed> $attributes) : string
Parameters
$attributes : array<string|int, mixed>

the attribute name-value pairs.

Return values
string

        
On this page

Search results