MarkdownParser
extends Parser
in package
Converts Markdown to BBCode or HTML.
Follows the CommonMark specification, with the following changes:
-
Supports the GitHub Flavoured Markdown tables extension.
-
Supports the GitHub Flavoured Markdown strikethough extension.
-
Is more accurate (and thus restrictive) when identifying absolute URIs. For example, CommonMark will accept obviously invalid URIs like these:
a+b+c:d made-up-scheme://foo,bar http://../
SMF is capable of much more robust URI validation, so we use it.
Table of Contents
Constants
- BR_IN_PARAGRAPHS = 0b10
- BR_LINES = 0b1
- ESCAPEABLE = ['!', '"', '#', '$', '%', '&', '\'', '\\', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '|', '[', ']', '^', '_', '`', '{', '}', '~']
- INPUT_BBC = 0b1
- INPUT_MARKDOWN = 0b10
- INPUT_SMILEYS = 0b100
- OUTPUT_BBC = 2
- OUTPUT_HTML = 0
- OUTPUT_HTML_STRICT = 3
- OUTPUT_TEXT = 1
- REGEX_HTML_TAG = '(' . '(?P>opening_tag)' . '|' . '(?P>closing_tag)' . '|' . '(?P>comment)' . '|' . '(?P>processing_instruction)' . '|' . '(?P>declaration)' . '|' . '(?P>cdata)' . ')' . '(?(DEFINE)' . '(?<tag_name>[a-zA-Z][a-zA-Z0-9\-]*)' . '(?<attribute_value_unquoted>[^\s"\'=<>`])' . '(?<attribute_value_single_quoted>\'[^\']*\')' . '(?<attribute_value_double_quoted>"[^"]*")' . '(?<attribute_value>(?P>attribute_value_unquoted)|(?P>attribute_value_single_quoted)|(?P>attribute_value_double_quoted))' . '(?<attribute_value_specification>\s*=\s*(?P>attribute_value))' . '(?<attribute_name>[a-zA-Z_:][a-zA-Z0-9_.:\-]*)' . '(?<attribute>\s+(?P>attribute_name)(?P>attribute_value_specification)?)' . '(?<opening_tag><(?P>tag_name)(?P>attribute)*\s*/?>)' . '(?<closing_tag></(?P>tag_name)\s*>)' . '(?<comment><!--(?!-?>)\X*?-->)' . '(?<processing_instruction><' . '\?\X*?\?' . '>)' . '(?<declaration><![A-Z]+\s+[^>]+>)' . '(?<cdata><!\[CDATA\[\X*?\]\]>)' . ')'
- REGEX_LINK_DESTINATION = '(?P<destination>' . '(?:' . '<[^\v>]*>' . '|' . '[^\s\p{Cc}]+?' . ')' . ')'
- REGEX_LINK_INLINE = self::REGEX_LINK_TEXT . '\(' . '\s*' . '(?:' . self::REGEX_LINK_DESTINATION . ')?' . '(?:' . '\s+' . self::REGEX_LINK_TITLE . ')?' . '\s*' . '\)'
- REGEX_LINK_LABEL = '(?P<label>' . '\[' . '(?=\s*\S)' . '(?:' . '\X(?!\])' . '|' . '\\\\(?=\])' . ')*' . '\X?' . '\]' . ')'
- REGEX_LINK_REF_COLLAPSED = self::REGEX_LINK_LABEL . '\[\]'
- REGEX_LINK_REF_DEF = '^\h{0,3}' . self::REGEX_LINK_LABEL . ':' . '\h*\n?\h*' . self::REGEX_LINK_DESTINATION . '(?:' . '(?:\h+\n?|\n)\h*' . self::REGEX_LINK_TITLE . ')?' . '\h*(?:\n|$)'
- REGEX_LINK_REF_FULL = self::REGEX_LINK_TEXT . self::REGEX_LINK_LABEL
- REGEX_LINK_REF_SHORTCUT = self::REGEX_LINK_LABEL . '(?!\[)'
- REGEX_LINK_TEXT = '(?P<text>' . '\[' . '(?' . '>' . '(?' . '>' . '[^\[\]]' . '|' . '\\\\[\[\]]' . ')' . '|' . '(?P>text)' . ')*' . '\]' . ')'
- REGEX_LINK_TITLE = '(?P<title>' . '(?P<quote>["\'])' . '(?:' . '\X(?!(?P>quote))' . '|' . '\\\\(?=(?P>quote))' . ')*' . '\X?' . '(?P>quote)' . '|' . '\(' . '(?:' . '\X(?!\))' . '|' . '\\\\(?=\))' . ')*' . '\X?' . '\)' . ')'
Properties
- $custom_smileys_enabled : bool
- $defalt_options : array<string|int, mixed>
- $disabled : array<string|int, mixed>
- $enable_bbc : bool
- $enable_markdown : bool
- $enable_post_html : bool
- $encoding : string
- $for_print : bool
- $hard_breaks : int
- $locale : string
- $output_type : int
- $parse_tags : array<string|int, mixed>
- $smiley_set : string
- $smileys_url : string
- $time_format : string
- $time_offset : int
- $block_types : array<string|int, mixed>
- $render_methods : array<string|int, mixed>
- $in_code : int
- $in_html : int
- $info_string : string
- $last_block : array<string|int, mixed>|null
- $line_info : array<string|int, mixed>
- $link_reference_definitions : array<string|int, mixed>
- $open : array<string|int, mixed>
- $opening_fence : string
- $opening_fence_linenum : int|null
- $parsers : array<string|int, mixed>
- $placeholders : array<string|int, mixed>
- $rendered : string
- $results : array<string|int, mixed>
- $structure : array<string|int, mixed>
- $table_align : array<string|int, mixed>
Methods
- __construct() : mixed
- Constructor.
- getBBCodes() : array<string|int, mixed>
- Get the list of supported BBCodes, including any added by modifications.
- getBBCodeTagsRegex() : string
- Gets a regular expression to match all known BBC tags.
- getSigTags() : array<string|int, mixed>
- Returns an array of BBCodes tags that are allowed in signatures.
- highlightPhpCode() : string
- Highlight any code.
- load() : object
- Returns a reusable instance of this class.
- parse() : string
- Parses Markdown in the supplied string.
- transform() : string
- Transforms one type of markup into another.
- addAtxHeading() : void
- Adds an ATX heading to the structure.
- addBlock() : void
- The default method for adding a new block element to the structure.
- addFencedCode() : void
- Adds a fenced code block to the structure.
- addIndentedCode() : void
- Adds an indented code block to the structure.
- addListItem() : void
- Adds a list item to the structure.
- addSetextHeading() : void
- Adds a setext heading to the structure.
- addTable() : void
- Adds a table to the structure.
- amalgamateStrings() : void
- Combines contiguous strings within a block's content.
- analyzeLine() : array<string|int, mixed>
- Analyzes a line to build a complete set of information about it.
- appendBlank() : void
- Appends a blank line to the currently open block.
- appendContent() : void
- The default method for appending content to an existing block element.
- appendFencedCode() : void
- Appends a line to a currently open fenced code block.
- appendIndentedCode() : void
- Appends a line to a currently open indented code block.
- appendTableRow() : void
- Appends a line to a currently open table as a new table row.
- checkRuleOfThree() : bool
- Helper method for $this->parseEmphasis().
- closeBlock() : void
- The default method for closing an open block element.
- closeCodeBlock() : void
- Closes a code block.
- closeParagraph() : void
- Closes a paragraph.
- closeTable() : void
- Closes an open table.
- disableCode() : array<string|int, mixed>
- Adjusts a BBCode definition so that it outputs its disabled version.
- extractLinkLabel() : string
- Extracts and normalizes the text for a link label.
- extractLinkTitle() : string
- Extracts the title for a link.
- extractLinkUrl() : string
- Extracts the URL for a link.
- findOpen() : void
- Finds the elements of $this->structure that are currently open.
- getCacheKey() : string
- Generates a unique cache key for the combination of string, parameters, settings, etc., that apply to this particular call to self::transform().
- getMethod() : A
- Helper method that returns the requested callable.
- highLoadAverage() : bool
- Checks whether the server's load average is too high to parse BBCode.
- parseBlocks() : void
- Parses the string to build a structured series of block elements.
- parseEmphasis() : void
- Parses Markdown emphasis and strikethrough text.
- parseInlineFirstPass() : array<string|int, mixed>
- Parses inline code spans, HTML tags, and `<http://example.com>` links.
- parseInlines() : void
- Parses inline markup inside a block element and all of its children.
- parseInlineSecondPass() : array<string|int, mixed>
- Parses all other types of inline Markdown syntax.
- parseLink() : void
- Parses Markdown links.
- render() : void
- Transforms a block or string into its final output form and appends it to $this->rendered.
- renderBlockquote() : void
- Renders blockquotes.
- renderCodeBlock() : void
- Renders code blocks.
- renderEm() : void
- Renders emphasis.
- renderHeading() : void
- Renders headings.
- renderHr() : void
- Renders thematic breaks.
- renderHtmlBlock() : void
- Renders HTML blocks.
- renderHtmlInline() : void
- Renders inline HTML.
- renderImage() : void
- Renders images.
- renderInlineCode() : void
- Renders inline code.
- renderLink() : void
- Renders links.
- renderList() : void
- Renders lists.
- renderListItem() : void
- Renders list items.
- renderParagraph() : void
- Renders paragraphs.
- renderStrikethrough() : void
- Renders strikethrough text.
- renderStrong() : void
- Renders strong emphasis.
- renderTable() : void
- Renders tables.
- renderTableCell() : void
- Renders table cells.
- resetRuntimeProperties() : void
- Resets runtime properties to their default values.
- setDisabled() : void
- Sets $this->disabled.
- setOptions() : array<string|int, mixed>
- Fills in any missing elements of $options with the default values.
- setStaticVars() : void
- Sets the values of this class's static variables.
- testClosesHtml() : bool
- Helper for the various testClosesHtml* methods that performs the tests.
- testClosesHtml1() : bool
- Tests whether a line closes a type 1 HTML block.
- testClosesHtml2() : bool
- Tests whether a line closes a type 2 HTML block.
- testClosesHtml3() : bool
- Tests whether a line closes a type 3 HTML block.
- testClosesHtml4() : bool
- Tests whether a line closes a type 4 HTML block.
- testClosesHtml5() : bool
- Tests whether a line closes a type 5 HTML block.
- testClosesHtml6() : bool
- Tests whether a line closes a type 6 HTML block.
- testClosesHtml7() : bool
- Tests whether a line closes a type 7 HTML block.
- testClosesListItem() : bool
- Tests whether a line closes a list item.
- testClosesQuote() : bool
- Tests whether a line closes a blockquote.
- testIsAtxHeading() : bool
- Tests whether a line is part of an ATX heading.
- testIsBlank() : bool
- Tests whether a line is blank.
- testIsCodeFence() : bool
- Helper for testIsFencedCode(). Tests whether a line is a code fence.
- testIsFencedCode() : bool
- Tests whether a line is part of a fenced code block.
- testIsHr() : bool
- Tests whether a line is a thematic break.
- testIsIndentedCode() : bool
- Tests whether a line is part of an indented code block.
- testIsParagraph() : bool
- Tests whether a line can be part of a paragraph.
- testIsSetextHeading() : bool
- Tests whether a line is part of a setext heading.
- testIsTable() : bool
- Tests whether a line is part of a table.
- testOpensHtml() : bool
- Helper for the various testOpensHtml* methods that performs the tests.
- testOpensHtml1() : bool
- Tests whether a line opens a type 1 HTML block.
- testOpensHtml2() : bool
- Tests whether a line opens a type 2 HTML block.
- testOpensHtml3() : bool
- Tests whether a line opens a type 3 HTML block.
- testOpensHtml4() : bool
- Tests whether a line opens a type 4 HTML block.
- testOpensHtml5() : bool
- Tests whether a line opens a type 5 HTML block.
- testOpensHtml6() : bool
- Tests whether a line opens a type 6 HTML block.
- testOpensHtml7() : bool
- Tests whether a line opens a type 7 HTML block.
- testOpensListItem() : bool
- Tests whether a line opens a list item.
- testOpensQuote() : bool
- Tests whether a line opens a blockquote.
- toBBC() : string
- Transforms the input string into BBCode.
- toHTML() : string
- Transforms the input string into HTML.
- toText() : string
- Transforms the input string into plain text (i.e. removes all markup).
Constants
BR_IN_PARAGRAPHS
public
int
BR_IN_PARAGRAPHS
= 0b10
Possible value for $this->hard_breaks.
Using this option, line breaks will be converted to
elements inside
paragraphs, etc.
BR_LINES
public
int
BR_LINES
= 0b1
Possible value for $this->hard_breaks.
Using this option, line breaks will be converted to
elements when
the line breaks create blank lines. This can be used to preserve blank
lines in the input while still parsing paragraph content normally.
ESCAPEABLE
public
array<string|int, mixed>
ESCAPEABLE
= ['!', '"', '#', '$', '%', '&', '\'', '\\', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '|', '[', ']', '^', '_', '`', '{', '}', '~']
Characters that can be escaped with a backslash.
INPUT_BBC
public
int
INPUT_BBC
= 0b1
Indicates that BBCode should be parsed in the input string.
INPUT_MARKDOWN
public
int
INPUT_MARKDOWN
= 0b10
Indicates that Markdown should be parsed in the input string.
INPUT_SMILEYS
public
int
INPUT_SMILEYS
= 0b100
Indicates that smileys should be parsed in the input string.
When the output type is HTML, this controls whether smiley text will
be transformed into tags pointing to smiley images.
When the output type is plain text, this controls whether tags for
smiley images will be transformed into smiley text or removed.
When the output type is BBCode, this controls whether tags for
smiley images will be transformed into smiley text or [img] BBCodes.
OUTPUT_BBC
public
int
OUTPUT_BBC
= 2
Used to set the output to BBCode.
When this is used, HTML and Markdown in the input will be transformed into the equivalent BBCode. Unsupported HTML tags will be removed.
OUTPUT_HTML
public
int
OUTPUT_HTML
= 0
Used to set the output to HTML.
This is the default output type.
OUTPUT_HTML_STRICT
public
int
OUTPUT_HTML_STRICT
= 3
Possible value for $this->output_type.
Used to set the output to HTML rendered the same way that the reference implementation of CommonMark would.
OUTPUT_TEXT
public
int
OUTPUT_TEXT
= 1
Used to set the output to plain text.
When this is used, the input will be parsed into HTML and then the HTML tags will be stripped.
REGEX_HTML_TAG
public
string
REGEX_HTML_TAG
= '(' . '(?P>opening_tag)' . '|' . '(?P>closing_tag)' . '|' . '(?P>comment)' . '|' . '(?P>processing_instruction)' . '|' . '(?P>declaration)' . '|' . '(?P>cdata)' . ')' . '(?(DEFINE)' . '(?<tag_name>[a-zA-Z][a-zA-Z0-9\-]*)' . '(?<attribute_value_unquoted>[^\s"\'=<>`])' . '(?<attribute_value_single_quoted>\'[^\']*\')' . '(?<attribute_value_double_quoted>"[^"]*")' . '(?<attribute_value>(?P>attribute_value_unquoted)|(?P>attribute_value_single_quoted)|(?P>attribute_value_double_quoted))' . '(?<attribute_value_specification>\s*=\s*(?P>attribute_value))' . '(?<attribute_name>[a-zA-Z_:][a-zA-Z0-9_.:\-]*)' . '(?<attribute>\s+(?P>attribute_name)(?P>attribute_value_specification)?)' . '(?<opening_tag><(?P>tag_name)(?P>attribute)*\s*/?>)' . '(?<closing_tag></(?P>tag_name)\s*>)' . '(?<comment><!--(?!-?>)\X*?-->)' . '(?<processing_instruction><' . '\?\X*?\?' . '>)' . '(?<declaration><![A-Z]+\s+[^>]+>)' . '(?<cdata><!\[CDATA\[\X*?\]\]>)' . ')'
Regex to match HTML tags, including opening tags, closing tags, comments, processing instructions, declarations, and CDATA sections. Matches both standard HTML5 tag names and custom tag names.
REGEX_LINK_DESTINATION
public
string
REGEX_LINK_DESTINATION
= '(?P<destination>' . '(?:' . '<[^\v>]*>' . '|' . '[^\s\p{Cc}]+?' . ')' . ')'
Regular expression to match link destinations.
REGEX_LINK_INLINE
public
string
REGEX_LINK_INLINE
= self::REGEX_LINK_TEXT . '\(' . '\s*' . '(?:' . self::REGEX_LINK_DESTINATION . ')?' . '(?:' . '\s+' . self::REGEX_LINK_TITLE . ')?' . '\s*' . '\)'
Regular expression to match link reference definitions.
REGEX_LINK_LABEL
public
string
REGEX_LINK_LABEL
= '(?P<label>' . '\[' . '(?=\s*\S)' . '(?:' . '\X(?!\])' . '|' . '\\\\(?=\])' . ')*' . '\X?' . '\]' . ')'
Regular expression to match link labels.
REGEX_LINK_REF_COLLAPSED
public
string
REGEX_LINK_REF_COLLAPSED
= self::REGEX_LINK_LABEL . '\[\]'
Regular expression to match collapsed link references.
REGEX_LINK_REF_DEF
public
string
REGEX_LINK_REF_DEF
= '^\h{0,3}' . self::REGEX_LINK_LABEL . ':' . '\h*\n?\h*' . self::REGEX_LINK_DESTINATION . '(?:' . '(?:\h+\n?|\n)\h*' . self::REGEX_LINK_TITLE . ')?' . '\h*(?:\n|$)'
Regular expression to match link reference definitions.
REGEX_LINK_REF_FULL
public
string
REGEX_LINK_REF_FULL
= self::REGEX_LINK_TEXT . self::REGEX_LINK_LABEL
Regular expression to match full link references.
REGEX_LINK_REF_SHORTCUT
public
string
REGEX_LINK_REF_SHORTCUT
= self::REGEX_LINK_LABEL . '(?!\[)'
Regular expression to match shortcut link references.
REGEX_LINK_TEXT
public
string
REGEX_LINK_TEXT
= '(?P<text>' . '\[' . '(?' . '>' . '(?' . '>' . '[^\[\]]' . '|' . '\\\\[\[\]]' . ')' . '|' . '(?P>text)' . ')*' . '\]' . ')'
Regular expression to match link text.
REGEX_LINK_TITLE
public
string
REGEX_LINK_TITLE
= '(?P<title>' . '(?P<quote>["\'])' . '(?:' . '\X(?!(?P>quote))' . '|' . '\\\\(?=(?P>quote))' . ')*' . '\X?' . '(?P>quote)' . '|' . '\(' . '(?:' . '\X(?!\))' . '|' . '\\\\(?=\))' . ')*' . '\X?' . '\)' . ')'
Regular expression to match link titles.
Properties
$custom_smileys_enabled
public
static bool
$custom_smileys_enabled
Whether custom smileys are enabled.
$defalt_options
public
static array<string|int, mixed>
$defalt_options
= ['cache_id' => '', 'parse_tags' => [], 'for_print' => false, 'hard_breaks' => null, 'no_paragraphs' => false, 'str_replace' => [], 'preg_replace' => []]
Default options for the various parsers.
-
cache_id: ID string to identify the string for caching purposes. If empty, an ID will be generated automatically. Default: ''
-
parse_tags: A list of specific BBC tags to parse. If empty, all BBC are parsed. Default: []
-
for_print: Whether the output is intended for a non-interactive medium, such as being printed on paper. Default: false
-
hard_breaks: Controls how line breaks are handled by MarkdownParser. For more info, see the documentation for MarkdownParser::__construct(). Default: null
-
str_replace: String replacements to apply when converting to plain text. Keys are the strings to find, and values are the replacements. These replacements are applied after the input has been transformed into HTML and before the HTML tags are stripped out. Default: []
-
preg_replace: Similar to str_replace, except that the keys are regular expressions. Default: []
Mods implementing custom parsers can add values to this array using the integrate_parser_options hook.
$disabled
public
array<string|int, mixed>
$disabled
= []
List of disabled BBCode tags.
$enable_bbc
public
static bool
$enable_bbc
Whether BBCode should be parsed.
$enable_markdown
public
static bool
$enable_markdown
Whether Markdown should be parsed.
$enable_post_html
public
static bool
$enable_post_html
Whether to allow certain basic HTML tags in the input.
$encoding
public
static string
$encoding
The character encoding of the strings to be parsed.
$for_print
public
bool
$for_print
= false
Enables special handling if output is meant for paper printing.
$hard_breaks
public
int
$hard_breaks
= 0
How to render line breaks.
Value should be a bitmask of this class's BR_* constants.
$locale
public
static string
$locale
Language locale to use.
$output_type
public
int
$output_type
= self::OUTPUT_HTML
The type of output to generate.
Value must be one of this class's OUTPUT_* constants.
$parse_tags
public
array<string|int, mixed>
$parse_tags
= []
If not empty, only these BBCode tags will be parsed.
$smiley_set
public
static string
$smiley_set
The smiley set to use when parsing smileys.
$smileys_url
public
static string
$smileys_url
URL of the base smileys directory.
$time_format
public
static string
$time_format
User's time format string.
$time_offset
public
static int
$time_offset
User's time offset from UTC.
$block_types
protected
array<string|int, mixed>
$block_types
= ['blank' => ['is_container' => false, 'interrupts_p' => true, 'marker_pattern' => false, 'opener_test' => 'testIsBlank', 'continue_test' => 'testIsBlank', 'closer_test' => '!testIsBlank', 'add' => null, 'append' => 'appendBlank', 'close' => null], 'root' => ['is_container' => true, 'interrupts_p' => false, 'marker_pattern' => false, 'opener_test' => false, 'continue_test' => false, 'closer_test' => false, 'add' => null, 'append' => null, 'close' => null], 'fenced_code' => ['is_container' => false, 'interrupts_p' => true, 'marker_pattern' => '/^([`~]){3,}(?!\h+\1)/u', 'opener_test' => 'testIsFencedCode', 'continue_test' => true, 'closer_test' => 'testIsCodeFence', 'add' => 'addFencedCode', 'append' => 'appendFencedCode', 'close' => 'closeCodeBlock'], 'blockquote' => ['is_container' => true, 'interrupts_p' => true, 'marker_pattern' => '/^>\h?/u', 'opener_test' => 'testOpensQuote', 'continue_test' => 'testOpensQuote', 'closer_test' => 'testClosesQuote', 'add' => 'addBlock', 'append' => null, 'close' => 'closeBlock'], 'list' => ['is_container' => true, 'interrupts_p' => true, 'marker_pattern' => false, 'opener_test' => false, 'continue_test' => false, 'closer_test' => false, 'add' => null, 'append' => null, 'close' => null], 'list_item' => ['is_container' => true, 'interrupts_p' => true, 'marker_pattern' => '/^((?P<bullet>[*+-])|(?P<number>\d+)(?P<num_punct>[.)]))\h+/u', 'opener_test' => 'testOpensListItem', 'continue_test' => false, 'closer_test' => 'testClosesListItem', 'add' => 'addListItem', 'append' => null, 'close' => 'closeBlock'], 'indented_code' => ['is_container' => false, 'interrupts_p' => false, 'marker_pattern' => '/^\h{4}/u', 'opener_test' => 'testIsIndentedCode', 'continue_test' => 'testIsIndentedCode', 'closer_test' => '!testIsIndentedCode', 'add' => 'addIndentedCode', 'append' => 'appendIndentedCode', 'close' => 'closeCodeBlock'], 'hr' => ['is_container' => false, 'interrupts_p' => true, 'marker_pattern' => '/^[*-_]/u', 'opener_test' => 'testIsHr', 'continue_test' => false, 'closer_test' => true, 'add' => 'addBlock', 'append' => null, 'close' => 'closeBlock'], 'atx_heading' => ['is_container' => false, 'interrupts_p' => true, 'marker_pattern' => '/^#{1,6}/u', 'opener_test' => 'testIsAtxHeading', 'continue_test' => false, 'closer_test' => true, 'add' => 'addAtxHeading', 'append' => null, 'close' => 'closeBlock'], 'setext_heading' => ['is_container' => false, 'interrupts_p' => false, 'marker_pattern' => '/^[=-]/u', 'opener_test' => 'testIsSetextHeading', 'continue_test' => false, 'closer_test' => true, 'add' => 'addSetextHeading', 'append' => null, 'close' => 'closeBlock'], 'html_1' => ['is_container' => false, 'interrupts_p' => true, 'marker_pattern' => '/^<(script|pre|style)(?=\h|>|$)/ui', 'opener_test' => 'testOpensHtml1', 'continue_test' => '!testClosesHtml1', 'closer_test' => 'testClosesHtml1', 'add' => 'addBlock', 'append' => 'appendContent', 'close' => 'closeBlock'], 'html_2' => ['is_container' => false, 'interrupts_p' => true, 'marker_pattern' => '/^<!--/', 'opener_test' => 'testOpensHtml2', 'continue_test' => '!testClosesHtml2', 'closer_test' => 'testClosesHtml2', 'add' => 'addBlock', 'append' => 'appendContent', 'close' => 'closeBlock'], 'html_3' => ['is_container' => false, 'interrupts_p' => true, 'marker_pattern' => '/^<[?]/', 'opener_test' => 'testOpensHtml3', 'continue_test' => '!testClosesHtml3', 'closer_test' => 'testClosesHtml3', 'add' => 'addBlock', 'append' => 'appendContent', 'close' => 'closeBlock'], 'html_4' => ['is_container' => false, 'interrupts_p' => true, 'marker_pattern' => '/^<![A-Z]/', 'opener_test' => 'testOpensHtml4', 'continue_test' => '!testClosesHtml4', 'closer_test' => 'testClosesHtml4', 'add' => 'addBlock', 'append' => 'appendContent', 'close' => 'closeBlock'], 'html_5' => ['is_container' => false, 'interrupts_p' => true, 'marker_pattern' => '/^<!\[CDATA\[/', 'opener_test' => 'testOpensHtml5', 'continue_test' => '!testClosesHtml5', 'closer_test' => 'testClosesHtml5', 'add' => 'addBlock', 'append' => 'appendContent', 'close' => 'closeBlock'], 'html_6' => ['is_container' => false, 'interrupts_p' => true, 'marker_pattern' => '~' . '^' . '</?' . '(?' . '>iframe|ul|a(?' . '>ddress|rticle|side)|b(?' . '>lockquote|ase(?' . '>font|)|ody)|c(?' . '>aption|enter|ol(?' . '>group|))|d(?' . '>etails|d|i(?' . '>alog|r|v)|l|t)|f(?' . '>rame(?' . '>set|)|i(?' . '>eldset|g(?' . '>caption|ure))|o(?' . '>oter|rm))|h(?' . '>ead(?' . '>er|)|tml|1|2|3|4|5|6|r)|l(?' . '>egend|i(?' . '>nk|))|m(?' . '>ain|enu(?' . '>item|))|n(?' . '>oframes|av)|o(?' . '>pt(?' . '>group|ion)|l)|p(?' . '>aram|)|s(?' . '>ection|ummary|ource)|t(?' . '>able|body|foot|itle|d|h(?' . '>ead|)|r(?' . '>ack|)))' . '(?=\h|/?' . '>|$)' . '~ui', 'opener_test' => 'testOpensHtml6', 'continue_test' => '!testClosesHtml6', 'closer_test' => 'testClosesHtml6', 'add' => 'addBlock', 'append' => 'appendContent', 'close' => 'closeBlock'], 'html_7' => ['is_container' => false, 'interrupts_p' => false, 'marker_pattern' => '/^<\/?(?!script|pre|style)[^>]+>(?=\h|$)/ui', 'opener_test' => 'testOpensHtml7', 'continue_test' => '!testClosesHtml7', 'closer_test' => 'testClosesHtml7', 'add' => 'addBlock', 'append' => 'appendContent', 'close' => 'closeBlock'], 'table' => ['is_container' => false, 'interrupts_p' => true, 'marker_pattern' => false, 'opener_test' => 'testIsTable', 'continue_test' => 'testIsTable', 'closer_test' => '!testIsTable', 'add' => 'addTable', 'append' => 'appendTableRow', 'close' => 'closeTable'], 'p' => ['is_container' => false, 'interrupts_p' => false, 'marker_pattern' => false, 'opener_test' => 'testIsParagraph', 'continue_test' => 'testIsParagraph', 'closer_test' => '!testIsParagraph', 'add' => 'addBlock', 'append' => 'appendContent', 'close' => 'closeParagraph']]
Defines all the recognized block level element types.
The order of items in this array matters. Don't change it.
$render_methods
protected
array<string|int, mixed>
$render_methods
= ['fenced_code' => 'renderCodeBlock', 'indented_code' => 'renderCodeBlock', 'blockquote' => 'renderBlockquote', 'list' => 'renderList', 'list_item' => 'renderListItem', 'hr' => 'renderHr', 'atx_heading' => 'renderHeading', 'setext_heading' => 'renderHeading', 'html_1' => 'renderHtmlBlock', 'html_2' => 'renderHtmlBlock', 'html_3' => 'renderHtmlBlock', 'html_4' => 'renderHtmlBlock', 'html_5' => 'renderHtmlBlock', 'html_6' => 'renderHtmlBlock', 'html_7' => 'renderHtmlBlock', 'table' => 'renderTable', 'td' => 'renderTableCell', 'p' => 'renderParagraph', 'html' => 'renderHtmlInline', 'link' => 'renderLink', 'image' => 'renderImage', 'code' => 'renderInlineCode', 'i' => 'renderEm', 'b' => 'renderStrong', 's' => 'renderStrikethrough']
Defines the methods used to render different element types.
This info is separate from $this->block_types because it includes info about how to render both block elements and inline elements.
$in_code
private
int
$in_code
= 0
Tracks whether a code block is currently open.
$in_html
private
int
$in_html
= 0
Tracks whether an HTML block is currently open.
$info_string
private
string
$info_string
= ''
For fenced code blocks, the info string that was given with the fence.
$last_block
private
array<string|int, mixed>|null
$last_block
A reference to the last block element of $this->structure.
$line_info
private
array<string|int, mixed>
$line_info
= []
Information about the line that is currently being parsed.
$link_reference_definitions
private
array<string|int, mixed>
$link_reference_definitions
= []
Holds any link reference definitions that are found in the document.
$open
private
array<string|int, mixed>
$open
= []
Holds references to the elements of $this->structure that are currently open.
$opening_fence
private
string
$opening_fence
= ''
For fenced code blocks, the string of the opening code fence.
$opening_fence_linenum
private
int|null
$opening_fence_linenum
= null
For fenced code blocks, tracks the line number of the opening code fence.
$parsers
private
static array<string|int, mixed>
$parsers
= []
References to existing, reusable instances of this class.
$placeholders
private
array<string|int, mixed>
$placeholders
= []
Holds placeholders for protected strings.
Used to prevent parsing inside pre-existing HTML code blocks.
$rendered
private
string
$rendered
= ''
The rendered output.
$results
private
static array<string|int, mixed>
$results
= []
Holds parsed messages.
$structure
private
array<string|int, mixed>
$structure
= ['type' => 'root', 'open' => true, 'properties' => [], 'content' => []]
Holds the parsed document structure.
$table_align
private
array<string|int, mixed>
$table_align
= []
While in a table, holds the alignment settings for the table's columns.
Methods
__construct()
Constructor.
public
__construct([int $output_type = self::OUTPUT_HTML ]) : mixed
Parameters
- $output_type : int = self::OUTPUT_HTML
-
The type of output to generate. Value must be one of this class's or its parent class's OUTPUT_* constants. Default: self::OUTPUT_HTML.
Tags
getBBCodes()
Get the list of supported BBCodes, including any added by modifications.
public
static getBBCodes() : array<string|int, mixed>
Return values
array<string|int, mixed> —List of supported BBCodes.
getBBCodeTagsRegex()
Gets a regular expression to match all known BBC tags.
public
static getBBCodeTagsRegex() : string
Return values
string —Regular expression to match all BBCode tags.
getSigTags()
Returns an array of BBCodes tags that are allowed in signatures.
public
static getSigTags() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array containing allowed tags for signatures, or an empty array if all tags are allowed.
highlightPhpCode()
Highlight any code.
public
static highlightPhpCode(string $code) : string
Uses PHP's highlight_string() to highlight PHP syntax. Does special handling to keep the tabs in the code available. Used to parse PHP code from inside [code] and [php] tags.
Parameters
- $code : string
-
The code.
Return values
string —The code with highlighted HTML.
load()
Returns a reusable instance of this class.
public
static load([int $output_type = self::OUTPUT_HTML ][, int|null $hard_breaks = null ]) : object
Using this method to get a MarkdownParser instance saves memory by avoiding creating redundant instances.
Parameters
- $output_type : int = self::OUTPUT_HTML
-
The type of output to generate. Value must be one of this class's OUTPUT_* constants. Default: self::OUTPUT_HTML.
- $hard_breaks : int|null = null
-
How to handle line breaks in HTML output. Value should be bitmask of this class's BR_* constants. If null, uses the value of Config::$modSettings['markdown_brs']. Ignored when output is BBCode. Default: null.
Tags
Return values
object —An instance of this class.
parse()
Parses Markdown in the supplied string.
public
parse(string $string[, string $from_bbcode_parser = false ][, array<string|int, mixed> $options = [] ]) : string
Getting Markdown and BBCode to play nicely with each other requires some extra handling, so $from_bbcode_parser should always be set to true if the string was already processed by the SMF\Parsers\BBCodeParser class.
Parameters
- $string : string
-
The string to parse.
- $from_bbcode_parser : string = false
-
Whether the string was the output from the SMF\Parsers\BBCodeParser class.
- $options : array<string|int, mixed> = []
-
Parser options. Recognized options are:
- 'hard_breaks': How to handle line breaks in HTML output. Value should be a bitmask of this class's BR_* constants. If not set, defaults to Config::$modSettings['markdown_brs']. Ignored when output is BBCode.
- 'parse_tags': When not empty, only Markdown that is equivalent to one of these BBCode tags will be rendered.
Return values
string —The result of parsing the string.
transform()
Transforms one type of markup into another.
public
static transform(string $string[, int $input_types = self::INPUT_BBC | self::INPUT_MARKDOWN | self::INPUT_SMILEYS ][, int $output_type = self::OUTPUT_HTML ][, array<string|int, mixed> $options = [] ]) : string
Supported input markup types are BBCode, Markdown, and smileys. Supported output markup types are HTML, BBCode, and plain text.
Parameters
- $string : string
-
The string in which to transform markup.
- $input_types : int = self::INPUT_BBC | self::INPUT_MARKDOWN | self::INPUT_SMILEYS
-
Bitmask of this class's INPUT_* constants. Only the indicated types of markup will be parsed in the input string. Default: self::INPUT_BBC | self::INPUT_MARKDOWN | self::INPUT_SMILEYS
- $output_type : int = self::OUTPUT_HTML
-
One of this class's INPUT_* constants. Default: self::OUTPUT_HTML
- $options : array<string|int, mixed> = []
-
Various parser options. See self::$default_options.
Return values
string —The transformed string.
addAtxHeading()
Adds an ATX heading to the structure.
protected
addAtxHeading(array<string|int, mixed> $line_info, int $last_container, int $o) : void
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
- $last_container : int
-
Key of the last container block in $this->open.
- $o : int
-
Key of the current block in $this->open.
addBlock()
The default method for adding a new block element to the structure.
protected
addBlock(array<string|int, mixed> $line_info, int $last_container, int $o) : void
This is used for any block type that doesn't have its own special method.
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
- $last_container : int
-
Key of the last container block in $this->open.
- $o : int
-
Key of the current block in $this->open.
addFencedCode()
Adds a fenced code block to the structure.
protected
addFencedCode(array<string|int, mixed> $line_info, int $last_container, int $o) : void
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
- $last_container : int
-
Key of the last container block in $this->open.
- $o : int
-
Key of the current block in $this->open.
addIndentedCode()
Adds an indented code block to the structure.
protected
addIndentedCode(array<string|int, mixed> $line_info, int $last_container, int $o) : void
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
- $last_container : int
-
Key of the last container block in $this->open.
- $o : int
-
Key of the current block in $this->open.
addListItem()
Adds a list item to the structure.
protected
addListItem(array<string|int, mixed> $line_info, int $last_container, int $o) : void
If necessary, first adds a list to the structure to hold the list item.
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
- $last_container : int
-
Key of the last container block in $this->open.
- $o : int
-
Key of the current block in $this->open.
addSetextHeading()
Adds a setext heading to the structure.
protected
addSetextHeading(array<string|int, mixed> $line_info, int $last_container, int $o) : void
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
- $last_container : int
-
Key of the last container block in $this->open.
- $o : int
-
Key of the current block in $this->open.
addTable()
Adds a table to the structure.
protected
addTable(array<string|int, mixed> $line_info, int $last_container, int $o) : void
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
- $last_container : int
-
Key of the last container block in $this->open.
- $o : int
-
Key of the current block in $this->open.
amalgamateStrings()
Combines contiguous strings within a block's content.
protected
amalgamateStrings(array<string|int, mixed> &$content) : void
Parameters
- $content : array<string|int, mixed>
-
The 'content' array of the block in which the strings occur.
analyzeLine()
Analyzes a line to build a complete set of information about it.
protected
analyzeLine(array<string|int, mixed> $line_info) : array<string|int, mixed>
Parameters
- $line_info : array<string|int, mixed>
-
Basic line info that we already know.
Return values
array<string|int, mixed> —Complete info about the current line.
appendBlank()
Appends a blank line to the currently open block.
protected
appendBlank(array<string|int, mixed> $line_info, int $last_container, int $o) : void
Blank lines get special handling compared to other appended content.
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
- $last_container : int
-
Key of the last container block in $this->open.
- $o : int
-
Key of the current block in $this->open.
appendContent()
The default method for appending content to an existing block element.
protected
appendContent(array<string|int, mixed> $line_info, int $last_container, int $o) : void
This is used for any block type that doesn't have its own special method.
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
- $last_container : int
-
Key of the last container block in $this->open.
- $o : int
-
Key of the current block in $this->open.
appendFencedCode()
Appends a line to a currently open fenced code block.
protected
appendFencedCode(array<string|int, mixed> $line_info, int $last_container, int $o) : void
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
- $last_container : int
-
Key of the last container block in $this->open.
- $o : int
-
Key of the current block in $this->open.
appendIndentedCode()
Appends a line to a currently open indented code block.
protected
appendIndentedCode(array<string|int, mixed> $line_info, int $last_container, int $o) : void
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
- $last_container : int
-
Key of the last container block in $this->open.
- $o : int
-
Key of the current block in $this->open.
appendTableRow()
Appends a line to a currently open table as a new table row.
protected
appendTableRow(array<string|int, mixed> &$line_info, int $last_container, int $o) : void
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
- $last_container : int
-
Key of the last container block in $this->open.
- $o : int
-
Key of the current block in $this->open.
checkRuleOfThree()
Helper method for $this->parseEmphasis().
protected
checkRuleOfThree(array<string|int, mixed> $opener, array<string|int, mixed> $closer) : bool
https://github.github.com/gfm/#emphasis-and-strong-emphasis:
"If one of the delimiters can both open and close emphasis, then the sum of the lengths of the delimiter runs containing the opening and closing delimiters must not be a multiple of 3 unless both lengths are multiples of 3."
This rule is used to ensure that, e.g., *foo**bar**baz*
becomes
<i>foo<b>bar</b>baz</i>
rather than <i>foo</i><i>bar</i><i>baz</i>
.
Parameters
- $opener : array<string|int, mixed>
-
Info about opening run of delimiter characters.
- $closer : array<string|int, mixed>
-
Info about closing run of delimiter characters.
Return values
bool —Whether this combination of opener and closer is allowed.
closeBlock()
The default method for closing an open block element.
protected
closeBlock(int $o) : void
This is used for any block type that doesn't have its own special method.
Parameters
- $o : int
-
Key of the block in $this->open.
closeCodeBlock()
Closes a code block.
protected
closeCodeBlock(int $o) : void
Parameters
- $o : int
-
Key of the block in $this->open.
closeParagraph()
Closes a paragraph.
protected
closeParagraph(int $o) : void
Parameters
- $o : int
-
Key of the block in $this->open.
closeTable()
Closes an open table.
protected
closeTable(int $o) : void
Parameters
- $o : int
-
Key of the block in $this->open.
disableCode()
Adjusts a BBCode definition so that it outputs its disabled version.
protected
disableCode(array<string|int, mixed> $code) : array<string|int, mixed>
Parameters
- $code : array<string|int, mixed>
-
A BBCode definition.
Return values
array<string|int, mixed> —The disabled version of the BBCode definition.
extractLinkLabel()
Extracts and normalizes the text for a link label.
protected
extractLinkLabel([string $label = '' ]) : string
Note that link labels and link text might look identical a first glance, but are not quite the same thing.
A link label is the part between square brackets in a link reference. Because link labels are used to match link references to link reference definitions, they are normalized for both case and white space so that the matching can happen while ignoring case and white space.
Link text is the part between square brackets in an inline link. Because link text never needs to match with anything else, it does not need to be normalized for case or white space.
Parameters
- $label : string = ''
-
The link's label component, including syntax chars.
Return values
string —The normalized text of the link's label.
extractLinkTitle()
Extracts the title for a link.
protected
extractLinkTitle([string $title = '' ]) : string
Parameters
- $title : string = ''
-
The link's title component, including syntax chars.
Return values
string —The text of the link's title.
extractLinkUrl()
Extracts the URL for a link.
protected
extractLinkUrl([string $destination = '' ]) : string
Parameters
- $destination : string = ''
-
The link's URL component, including syntax chars.
Return values
string —The text of the link's URL.
findOpen()
Finds the elements of $this->structure that are currently open.
protected
findOpen([array<string|int, mixed>|null &$block = null ]) : void
The found items are stored in $this->open.
Parameters
- $block : array<string|int, mixed>|null = null
-
An element of $this->structure. If null, will be set to $this->structure itself.
getCacheKey()
Generates a unique cache key for the combination of string, parameters, settings, etc., that apply to this particular call to self::transform().
protected
static getCacheKey(string $string, int $input_types, int $output_type, array<string|int, mixed> $options) : string
Parameters
- $string : string
-
The string in which to transform markup.
- $input_types : int
-
Bitmask of this class's INPUT_* constants.
- $output_type : int
-
One of this class's INPUT_* constants.
- $options : array<string|int, mixed>
-
An array of parser options.
Return values
string —A unique cache key.
getMethod()
Helper method that returns the requested callable.
protected
getMethod(string|bool|null $method) : A
This is used to allow $this->block_types to define the necessary methods for working with various block types.
Parameters
- $method : string|bool|null
-
Either (a) a boolean to return, (b) null to do nothing, or (c) the name of a method, possibly prepended by '!' if the boolean inverse of the method's results are desired.
Return values
A —callable, a boolean, or null.
highLoadAverage()
Checks whether the server's load average is too high to parse BBCode.
protected
highLoadAverage() : bool
Return values
bool —Whether the load average is too high.
parseBlocks()
Parses the string to build a structured series of block elements.
protected
parseBlocks(string $string) : void
The result is stored as $this->structured.
Parameters
- $string : string
-
The string to parse.
parseEmphasis()
Parses Markdown emphasis and strikethrough text.
protected
parseEmphasis(array<string|int, mixed> &$content[, int $start_after = -1 ]) : void
Parameters
- $content : array<string|int, mixed>
-
The 'content' array of the block in which the emphasis occurs.
- $start_after : int = -1
-
Parsing will only happen in elements of $content whose keys are greater than this. Used to avoid parsing in parts of a string that have already been parsed. Default: -1.
parseInlineFirstPass()
Parses inline code spans, HTML tags, and `<http://example.com>` links.
protected
parseInlineFirstPass(array<string|int, mixed> $content) : array<string|int, mixed>
Parameters
- $content : array<string|int, mixed>
-
The content of a paragraph or heading block.
Return values
array<string|int, mixed>parseInlines()
Parses inline markup inside a block element and all of its children.
protected
parseInlines(array<string|int, mixed> &$block) : void
Parameters
- $block : array<string|int, mixed>
-
A block element in which to parse inline content.
parseInlineSecondPass()
Parses all other types of inline Markdown syntax.
protected
parseInlineSecondPass(array<string|int, mixed> $content) : array<string|int, mixed>
Parameters
- $content : array<string|int, mixed>
-
The content of a paragraph or heading block.
Return values
array<string|int, mixed>parseLink()
Parses Markdown links.
protected
parseLink(array<string|int, mixed> $chars, int &$i, array<string|int, mixed> &$content) : void
Parameters
- $chars : array<string|int, mixed>
-
The characters of the line in which the link occurs.
- $i : int
-
The index of the current character within $chars.
- $content : array<string|int, mixed>
-
The 'content' array of the block in which the link occurs.
render()
Transforms a block or string into its final output form and appends it to $this->rendered.
protected
render(array<string|int, mixed>|string $element) : void
If $element is a block from $this->structure (or is $this->structure itself), this method will recurse into $element's children.
Parameters
- $element : array<string|int, mixed>|string
-
A block or string to render.
renderBlockquote()
Renders blockquotes.
protected
renderBlockquote(array<string|int, mixed> $element) : void
Parameters
- $element : array<string|int, mixed>
-
A blockquote to render.
renderCodeBlock()
Renders code blocks.
protected
renderCodeBlock(array<string|int, mixed> $element) : void
Parameters
- $element : array<string|int, mixed>
-
A code block to render.
renderEm()
Renders emphasis.
protected
renderEm(array<string|int, mixed> $element) : void
Parameters
- $element : array<string|int, mixed>
-
A span of emphasized text to render.
renderHeading()
Renders headings.
protected
renderHeading(array<string|int, mixed> $element) : void
Parameters
- $element : array<string|int, mixed>
-
A heading to render.
renderHr()
Renders thematic breaks.
protected
renderHr(array<string|int, mixed> $element) : void
Parameters
- $element : array<string|int, mixed>
-
A thematic break to render.
renderHtmlBlock()
Renders HTML blocks.
protected
renderHtmlBlock(array<string|int, mixed> $element) : void
Parameters
- $element : array<string|int, mixed>
-
An HTML block to render.
renderHtmlInline()
Renders inline HTML.
protected
renderHtmlInline(array<string|int, mixed> $element) : void
Parameters
- $element : array<string|int, mixed>
-
Some inline HTML to render.
renderImage()
Renders images.
protected
renderImage(array<string|int, mixed> $element) : void
Parameters
- $element : array<string|int, mixed>
-
An image to render.
renderInlineCode()
Renders inline code.
protected
renderInlineCode(array<string|int, mixed> $element) : void
Parameters
- $element : array<string|int, mixed>
-
A span of inline code to render.
renderLink()
Renders links.
protected
renderLink(array<string|int, mixed> $element) : void
Parameters
- $element : array<string|int, mixed>
-
A link to render.
renderList()
Renders lists.
protected
renderList(array<string|int, mixed> $element) : void
Parameters
- $element : array<string|int, mixed>
-
A list to render.
renderListItem()
Renders list items.
protected
renderListItem(array<string|int, mixed> $element) : void
Parameters
- $element : array<string|int, mixed>
-
A list item to render.
renderParagraph()
Renders paragraphs.
protected
renderParagraph(array<string|int, mixed> $element) : void
Parameters
- $element : array<string|int, mixed>
-
A paragraph to render.
renderStrikethrough()
Renders strikethrough text.
protected
renderStrikethrough(array<string|int, mixed> $element) : void
Parameters
- $element : array<string|int, mixed>
-
A span of strikethrough text to render.
renderStrong()
Renders strong emphasis.
protected
renderStrong(array<string|int, mixed> $element) : void
Parameters
- $element : array<string|int, mixed>
-
A span of strongly emphasized text to render.
renderTable()
Renders tables.
protected
renderTable(array<string|int, mixed> $element) : void
Parameters
- $element : array<string|int, mixed>
-
A table to render.
renderTableCell()
Renders table cells.
protected
renderTableCell(array<string|int, mixed> $element) : void
Parameters
- $element : array<string|int, mixed>
-
A table cell to render.
resetRuntimeProperties()
Resets runtime properties to their default values.
protected
resetRuntimeProperties() : void
setDisabled()
Sets $this->disabled.
protected
setDisabled() : void
setOptions()
Fills in any missing elements of $options with the default values.
protected
static setOptions(array<string|int, mixed> $options) : array<string|int, mixed>
Parameters
- $options : array<string|int, mixed>
-
An array of parser options.
Return values
array<string|int, mixed> —An updated copy of $options.
setStaticVars()
Sets the values of this class's static variables.
protected
static setStaticVars() : void
If a variable already has a value, the existing value is not changed. This ensures that custom values set by external code are respected.
testClosesHtml()
Helper for the various testClosesHtml* methods that performs the tests.
protected
testClosesHtml(int $type, array<string|int, mixed> $line_info) : bool
Parameters
- $type : int
-
The type of HTML block to test for.
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line closes an HTML block of the given type.
testClosesHtml1()
Tests whether a line closes a type 1 HTML block.
protected
testClosesHtml1(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line closes a type 1 HTML block.
testClosesHtml2()
Tests whether a line closes a type 2 HTML block.
protected
testClosesHtml2(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line closes a type 2 HTML block.
testClosesHtml3()
Tests whether a line closes a type 3 HTML block.
protected
testClosesHtml3(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line closes a type 3 HTML block.
testClosesHtml4()
Tests whether a line closes a type 4 HTML block.
protected
testClosesHtml4(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line closes a type 4 HTML block.
testClosesHtml5()
Tests whether a line closes a type 5 HTML block.
protected
testClosesHtml5(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line closes a type 5 HTML block.
testClosesHtml6()
Tests whether a line closes a type 6 HTML block.
protected
testClosesHtml6(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line closes a type 6 HTML block.
testClosesHtml7()
Tests whether a line closes a type 7 HTML block.
protected
testClosesHtml7(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line closes a type 7 HTML block.
testClosesListItem()
Tests whether a line closes a list item.
protected
testClosesListItem(array<string|int, mixed> $line_info, int $last_container, int $o) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
- $last_container : int
- $o : int
Return values
bool —Whether this line closes a list item.
testClosesQuote()
Tests whether a line closes a blockquote.
protected
testClosesQuote(array<string|int, mixed> $line_info, int $last_container, int $o) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
- $last_container : int
- $o : int
Return values
bool —Whether this line closes a blockquote.
testIsAtxHeading()
Tests whether a line is part of an ATX heading.
protected
testIsAtxHeading(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line is part of an ATX heading.
testIsBlank()
Tests whether a line is blank.
protected
testIsBlank(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line is blank.
testIsCodeFence()
Helper for testIsFencedCode(). Tests whether a line is a code fence.
protected
testIsCodeFence(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line is a code fence.
testIsFencedCode()
Tests whether a line is part of a fenced code block.
protected
testIsFencedCode(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line is part of a fenced code block.
testIsHr()
Tests whether a line is a thematic break.
protected
testIsHr(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line is a thematic break.
testIsIndentedCode()
Tests whether a line is part of an indented code block.
protected
testIsIndentedCode(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line is part of an indented code block.
testIsParagraph()
Tests whether a line can be part of a paragraph.
protected
testIsParagraph(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line can be part of a paragraph.
testIsSetextHeading()
Tests whether a line is part of a setext heading.
protected
testIsSetextHeading(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line is part of a setext heading.
testIsTable()
Tests whether a line is part of a table.
protected
testIsTable(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line is part of a table.
testOpensHtml()
Helper for the various testOpensHtml* methods that performs the tests.
protected
testOpensHtml(int $type, array<string|int, mixed> $line_info) : bool
Parameters
- $type : int
-
The type of HTML block to test for.
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line opens an HTML block of the given type.
testOpensHtml1()
Tests whether a line opens a type 1 HTML block.
protected
testOpensHtml1(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line opens a type 1 HTML block.
testOpensHtml2()
Tests whether a line opens a type 2 HTML block.
protected
testOpensHtml2(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line opens a type 2 HTML block.
testOpensHtml3()
Tests whether a line opens a type 3 HTML block.
protected
testOpensHtml3(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line opens a type 3 HTML block.
testOpensHtml4()
Tests whether a line opens a type 4 HTML block.
protected
testOpensHtml4(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line opens a type 4 HTML block.
testOpensHtml5()
Tests whether a line opens a type 5 HTML block.
protected
testOpensHtml5(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line opens a type 5 HTML block.
testOpensHtml6()
Tests whether a line opens a type 6 HTML block.
protected
testOpensHtml6(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line opens a type 6 HTML block.
testOpensHtml7()
Tests whether a line opens a type 7 HTML block.
protected
testOpensHtml7(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line opens a type 7 HTML block.
testOpensListItem()
Tests whether a line opens a list item.
protected
testOpensListItem(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line is opens a list item.
testOpensQuote()
Tests whether a line opens a blockquote.
protected
testOpensQuote(array<string|int, mixed> $line_info) : bool
Parameters
- $line_info : array<string|int, mixed>
-
Info about the current line.
Return values
bool —Whether this line opens a blockquote.
toBBC()
Transforms the input string into BBCode.
protected
static toBBC(string $string, int $input_types, array<string|int, mixed> $options) : string
- Markdown is transformed to the equivalent BBCode.
- HTML img tags for smileys are transformed to smiley text.
- Other HTML is transformed to the equivalent BBCode where possible.
- HTML tags that cannot be transformed are removed.
Parameters
- $string : string
-
The string in which to remove markup.
- $input_types : int
-
Bitmask of this class's INPUT_* constants. Only the indicated types of markup will be parsed in the input string.
- $options : array<string|int, mixed>
-
An array of parser options.
Return values
string —The transformed string.
toHTML()
Transforms the input string into HTML.
protected
static toHTML(string $string, int $input_types, array<string|int, mixed> $options) : string
Parameters
- $string : string
-
The string in which to transform markup.
- $input_types : int
-
Bitmask of this class's INPUT_* constants. Only the indicated types of markup will be parsed in the input string.
- $options : array<string|int, mixed>
-
An array of parser options.
Return values
string —The transformed string.
toText()
Transforms the input string into plain text (i.e. removes all markup).
protected
static toText(string $string, int $input_types, array<string|int, mixed> $options) : string
Parameters
- $string : string
-
The string in which to remove markup.
- $input_types : int
-
Bitmask of this class's INPUT_* constants. Only the indicated types of markup will be parsed in the input string.
- $options : array<string|int, mixed>
-
An array of parser options.
Return values
string —The transformed string.