HumHub Documentation (unofficial)

Markdown extends Parser
in package
uses FencedCodeTrait, CodeTrait, EmphStrongTrait, StrikeoutTrait

A Markdown parser that enhances markdown for reading in console environments.

Based on cebe/markdown.

Tags
author

Carsten Brandt mail@cebe.cc

since
2.0

Table of Contents

Properties

$maximumNestingLevel  : int
$context  : array<string|int, mixed>
$escapeCharacters  : 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()`.
consumeFencedCode()  : mixed
Consume lines for a fenced code block
consumeParagraph()  : array<string|int, mixed>
Consume lines for a paragraph
detectLineType()  : string
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.
identifyFencedCode()  : mixed
identify a line as the beginning of a fenced code block.
inlineMarkers()  : array<string|int, mixed>
Returns a map of inline markers to the corresponding parser methods.
parseBlock()  : array<string|int, mixed>
Parses the block at current line by identifying the block type and parsing the content
parseBlocks()  : mixed
Parse block elements by calling `detectLineType()` to identify them and call consume function afterwards.
parseEmphStrong()  : mixed
Parses emphasized and strong elements.
parseEscape()  : mixed
Parses escaped special characters.
parseInline()  : mixed
parseInlineCode()  : mixed
Parses an inline code span `` ` ``.
parseStrike()  : mixed
Parses the strikethrough feature.
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()  : string
Renders a code block.
renderEmph()  : string
Renders empathized elements.
renderInlineCode()  : string
Renders an inline code span `` ` ``.
renderParagraph()  : string
Render a paragraph block.
renderStrike()  : string
Renders the strike through feature.
renderStrong()  : string
Renders strong elements.
renderText()  : mixed
This function renders plain text sections in the markdown text.

Properties

$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 '~', ]

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.

$_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.

consumeFencedCode()

Consume lines for a fenced code block

protected consumeFencedCode(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>
Parameters
$lines : mixed
$current : mixed
Return values
array<string|int, mixed>

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.

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

name of the block type in lower case

identifyFencedCode()

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

protected identifyFencedCode(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

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()

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

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

parseEmphStrong()

Parses emphasized and strong elements.

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

_

marker

parseEscape()

Parses escaped special characters.

protected parseEscape(mixed $text) : mixed
Parameters
$text : 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

`

parseStrike()

Parses the strikethrough feature.

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

~~

prepare()

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

protected prepare() : mixed

You can override it to do some initialization work.

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 $blocks) : mixed
Parameters
$blocks : mixed

renderCode()

Renders a code block.

protected renderCode(array<string|int, mixed> $block) : string
Parameters
$block : array<string|int, mixed>
Return values
string

renderEmph()

Renders empathized elements.

protected renderEmph(array<string|int, mixed> $element) : string
Parameters
$element : array<string|int, mixed>
Return values
string

renderInlineCode()

Renders an inline code span `` ` ``.

protected renderInlineCode(array<string|int, mixed> $element) : string
Parameters
$element : array<string|int, mixed>
Return values
string

renderParagraph()

Render a paragraph block.

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

renderStrike()

Renders the strike through feature.

protected renderStrike(array<string|int, mixed> $element) : string
Parameters
$element : array<string|int, mixed>
Return values
string

renderStrong()

Renders strong elements.

protected renderStrong(array<string|int, mixed> $element) : string
Parameters
$element : array<string|int, mixed>
Return values
string

renderText()

This function renders plain text sections in the markdown text.

protected renderText(mixed $block) : mixed

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

Parameters
$block : mixed

        
On this page

Search results