Constants |
public
|
FORMAT_REGEX = "/\n(?(DEFINE)\n (?<endofline> \\h*+ \\n )\n (?<endofblock> ^ \\k<indent> \\k<fence> \\h*+ $ )\n (?<endofspan> \\k<backtickstring> (?! ` ) )\n)\n# No gaps between matches\n\\G\n# No empty matches\n(?= . )\n# Match indentation early so horizontal whitespace before code blocks is not\n# mistaken for text\n(?<indent> ^ \\h*+ )?\n(?:\n # Whitespace before paragraphs\n (?<breaks> (?&endofline)+ ) |\n # Everything except unescaped backticks until the next paragraph\n (?<text> (?> (?: [^\\\\`\\n]+ | \\\\ [-\\\\!\"\\#$%&'()*+,.\\/:;<=>?@[\\]^_`{|}~\\n] | \\\\ | \\n (?! (?&endofline) ) )+ (?&endofline)* ) ) |\n # CommonMark-compliant fenced code blocks\n (?> (?(indent)\n (?> (?<fence> ```+ ) (?<infostring> [^\\n]* ) \\n )\n # Match empty blocks--with no trailing newline--and blocks with an empty\n # line by making the subsequent newline conditional on inblock\n (?<block> (?> (?<inblock> (?: (?! (?&endofblock) ) (?: \\k<indent> | (?= (?&endofline) ) ) [^\\n]* (?: (?= \\n (?&endofblock) ) | \\n | \\z ) )+ )? ) )\n # Allow code fences to terminate at the end of the subject\n (?: (?(inblock) \\n ) (?&endofblock) | \\z ) | \\z\n ) ) |\n # CommonMark-compliant code spans\n (?<backtickstring> (?> `+ ) ) (?<span> (?> (?: [^`]+ | (?! (?&endofspan) ) `+ )* ) ) (?&endofspan) |\n # Unmatched backticks\n (?<extra> `+ ) |\n \\z\n) /mxs"
Splits the subject into text, code blocks and code spans
Splits the subject into text, code blocks and code spans
|
#
|
public
|
TAG_REGEX = "/\n(?(DEFINE)\n (?<esc> \\\\ [-\\\\!\"\\#$%&'()*+,.\\/:;<=>?@[\\]^_`{|}~] | \\\\ )\n)\n(?<! \\\\ ) (?: \\\\\\\\ )* \\K (?|\n \\b (?<tag> _ {1,3}+ ) (?! \\s ) (?> (?<text> (?: [^_\\\\]+ | (?&esc) | (?! (?<! \\s ) \\k<tag> \\b ) _ + )* ) ) (?<! \\s ) \\k<tag> \\b |\n (?<tag> \\* {1,3}+ ) (?! \\s ) (?> (?<text> (?: [^*\\\\]+ | (?&esc) | (?! (?<! \\s ) \\k<tag> ) \\* + )* ) ) (?<! \\s ) \\k<tag> |\n (?<tag> < ) (?! \\s ) (?> (?<text> (?: [^>\\\\]+ | (?&esc) | (?! (?<! \\s ) > ) > + )* ) ) (?<! \\s ) > |\n (?<tag> ~~ ) (?! \\s ) (?> (?<text> (?: [^~\\\\]+ | (?&esc) | (?! (?<! \\s ) ~~ ) ~ + )* ) ) (?<! \\s ) ~~ |\n ^ (?<tag> \\#\\# ) \\h+ (?> (?<text> (?: [^\\#\\s\\\\]+ | (?&esc) | \\#+ (?! \\h* $ ) | \\h++ (?! (?: \\#+ \\h* )? $ ) )* ) ) (?: \\h+ \\#+ | \\h* ) $\n) /mx"
Matches inline formatting tags used outside code blocks and spans
Matches inline formatting tags used outside code blocks and spans
|
#
|
public
|
ESCAPE_REGEX = "/\n(?|\n \\\\ ( [-\\\\ !\"\\#$%&'()*+,.\\/:;<=>?@[\\]^_`{|}~] ) |\n # Lookbehind assertions are unnecessary because the first branch matches\n # escaped spaces and backslashes\n \\ ? \\\\ ( \\n )\n) /x"
Matches a CommonMark-compliant backslash escape, or an escaped line break
with an optional leading space
Matches a CommonMark-compliant backslash escape, or an escaped line break
with an optional leading space
|
#
|