Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
php-markdown

Functions

 _appendFootnotes_callback ($matches)
 Callback for appending footnotes.
 
 _detab_callback ($matches)
 Replace tabs callback.
 
 _doAbbreviations_callback ($matches)
 Callback for processing abbreviations.
 
 _doAnchors_inline_callback ($matches)
 Callback method to parse inline anchors.
 
 _doAnchors_reference_callback ($matches)
 Callback method to parse referenced anchors.
 
 _doAutoLinks_email_callback ($matches)
 Parse email address callback.
 
 _doAutoLinks_url_callback ($matches)
 Parse URL callback.
 
 _doBlockQuotes_callback ($matches)
 Blockquote parsing callback.
 
 _doBlockQuotes_callback2 ($matches)
 Blockquote parsing callback.
 
 _doCodeBlocks_callback ($matches)
 Code block parsing callback.
 
 _doDefLists_callback ($matches)
 Callback for processing definition lists.
 
 _doFencedCodeBlocks_callback ($matches)
 Callback to process fenced code blocks.
 
 _doFencedCodeBlocks_newlines ($matches)
 Replace new lines in fenced code blocks.
 
 _doFootnotes ()
 Generates the HTML for footnotes.
 
 _doHeaders_callback_atx ($matches)
 ATX header parsing callback.
 
 _doHeaders_callback_setext ($matches)
 Setext header parsing callback.
 
 _doImages_inline_callback ($matches)
 Callback to parse inline image tags.
 
 _doImages_reference_callback ($matches)
 Callback to parse references image tags.
 
 _doLists_callback ($matches)
 List parsing callback.
 
 _doTable_callback ($matches)
 Calback for processing tables.
 
 _doTable_leadingPipe_callback ($matches)
 Callback for removing the leading pipe for each row.
 
 _doTable_makeAlignAttr ($alignname)
 Make the align attribute in a table.
 
 _generateIdFromHeaderValue ($headerValue)
 If a header_id_func property is set, we can use it to automatically generate an id attribute.
 
 _hashHTMLBlocks_inHTML ($text, $hash_method, $md_attr)
 Parse HTML, calling _HashHTMLBlocks_InMarkdown for block tags.
 
 _hashHTMLBlocks_inMarkdown ($text, $indent=0, $enclosing_tag_re='', $span=false)
 Parse markdown text, calling _HashHTMLBlocks_InHTML for block tags.
 
 _initDetab ()
 Check for the availability of the function in the utf8_strlen property (initially mb_strlen).
 
 _processDefListItems_callback_dd ($matches)
 Callback for elements in definition lists.
 
 _processDefListItems_callback_dt ($matches)
 Callback for elements in definition lists.
 
 _processListItems_callback ($matches)
 List item parsing callback.
 
 _stripAbbreviations_callback ($matches)
 Callback for stripping abbreviations.
 
 _stripFootnotes_callback ($matches)
 Callback for stripping footnotes.
 
 _stripLinkDefinitions_callback ($matches)
 Strip link definition callback.
 
 _unhash_callback ($matches)
 Unhashing callback.
 
 appendFootnotes ($text)
 Append footnote list to text.
 
 detab ($text)
 Replace tabs with the appropriate amount of spaces.
 
 doAbbreviations ($text)
 Find defined abbreviations in text and wrap them in <abbr> elements.
 
 doAnchors ($text)
 Turn Markdown link shortcuts into XHTML tags.
 
 doAutoLinks ($text)
 Parse Markdown automatic links to anchor HTML tags.
 
 doBlockQuotes ($text)
 Parse Markdown blockquotes to HTML.
 
 doCodeBlocks ($text)
 Process Markdown <pre><code> blocks.
 
 doDefLists ($text)
 Form HTML definition lists.
 
 doExtraAttributes ($tag_name, $attr, $defaultIdValue=null, $classes=array())
 Parse attributes caught by the $this->id_class_attr_catch_re expression and return the HTML-formatted list of attributes.
 
 doFencedCodeBlocks ($text)
 Adding the fenced code block syntax to regular Markdown:
 
 doFootnotes ($text)
 Replace footnote references in $text [^id] with a special text-token which will be replaced by the actual footnote marker in appendFootnotes.
 
 doHeaders ($text)
 Parse Markdown heading elements to HTML.
 
 doImages ($text)
 Turn Markdown image shortcuts into.
 
 doItalicsAndBold ($text)
 Convert Markdown italics (emphasis) and bold (strong) to HTML.
 
 doLists ($text)
 Form HTML ordered (numbered) and unordered (bulleted) lists.
 
 doTables ($text)
 Form HTML tables.
 
 encodeAmpsAndAngles ($text)
 Smart processing for ampersands and angle brackets that need to be encoded.
 
 encodeAttribute ($text)
 Encode text for a double-quoted HTML attribute.
 
 encodeEntityObfuscatedAttribute ($text, &$tail=null, $head_length=0)
 Input: some text to obfuscate, e.g.
 
 encodeURLAttribute ($url, &$text=null)
 Encode text for a double-quoted HTML attribute containing a URL, applying the URL filter if set.
 
 formParagraphs ($text, $wrap_in_p=true)
 Parse paragraphs.
 
 handleSpanToken ($token, &$str)
 Handle $token provided by parseSpan by determining its nature and returning the corresponding value that should replace it.
 
 hashClean ($text)
 Called whenever a tag must be hashed when a function inserts a "clean" tag in $text, it passes through this function and is automaticaly escaped, blocking invalid nested overlap.
 
 hashHTMLBlocks ($text)
 Hashify HTML Blocks and "clean tags".
 
 makeCodeSpan ($code)
 Create a code span markup for $code.
 
 outdent ($text)
 Remove one level of line-leading tabs or spaces.
 
 parseFootnotePlaceholders ($label, $footnote_number, $reference_number)
 Build footnote label by evaluating any placeholders.
 
 parseSpan ($str)
 Take the string $str and parse it into tokens, hashing embeded HTML, escaped characters and handling code spans.
 
 prepareItalicsAndBold ()
 Prepare regular expressions for searching emphasis tokens in any context.
 
 processDefListItems ($list_str)
 Process the contents of a single definition list, splitting it into individual term and definition list items.
 
 processListItems ($list_str, $marker_any_re)
 Process the contents of a single ordered or unordered list, splitting it into individual list items.
 
 setup ()
 Setting up Extra-specific variables.
 
 stripAbbreviations ($text)
 Abbreviations - strips abbreviations from text, stores titles in hash references.
 
 stripFootnotes ($text)
 Footnotes - Strips link definitions from text, stores the URLs and titles in hash references.
 
 stripLinkDefinitions ($text)
 Strips link definitions from text, stores the URLs and titles in hash references.
 
 teardown ()
 Clearing Extra-specific variables.
 
*ingroup php markdown *author Michel Fortin< michel.fortin @michelf.com > *copyright Michel Fortin< https:* @copyright(Original Markdown) 2004-2006 John Gruber< https:*/namespace Michelf;class Markdown implements MarkdownInterface { string const MARKDOWNLIB_VERSION="2.0.0";public static defaultTransform(string $text):string { $parser_class=static::class;static $parser_list;$parser=& $parser_list[$parser_class];if(! $parser) { $parser=new $parser_class;} return $parser->transform($text);} public string $empty_element_suffix=" /> enhanced ordered list n n n n stripLinkDefinitions runBasicBlockGamut optional title (](.*?) # title=$4[")] [ ]* )? # title is optional (?:\n+|Z) }xm', array($this, '_stripLinkDefinitions_callback'), $text ); return $text; } /** * The callback to strip link definitions * @param array $matches * @retval string */ protected function _stripLinkDefinitions_callback($matches) { $link_id = strtolower($matches[1]); $url = $matches[2] == '' ? $matches[3] : $matches[2]; $this->urls[$link_id] = $url; $this->titles[$link_id] =& $matches[4]; return ''; // String that will replace the block } /** * Hashify HTML blocks * @param string $text * @retval string */ protected function hashHTMLBlocks($text) { if ($this->no_markup) { return $text; } $less_than_tab = $this->tab_width - 1; /** * Hashify HTML blocks: * * We only want to do this for block-level HTML tags, such as headers, * lists, and tables. That's because we still want to wrap <p>s around * "paragraphs" that are wrapped in non-block-level tags, such as * anchors, phrase emphasis, and spans. The list of tags we're looking * for is hard-coded: * * * List "a" is made of tags which can be both inline or block-level. * These will be treated block-level when the start tag is alone on * its line, otherwise they're not matched here and will be taken as * inline later. * * List "b" is made of tags which are always block-level; */ $block_tags_a_re = 'ins|del'; $block_tags_b_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|'. 'script|noscript|style|form|fieldset|iframe|math|svg|'. 'article|section|nav|aside|hgroup|header|footer|'. 'figure|details|summary'; // Regular expression for the content of a block tag. $nested_tags_level = 4; $attr = ' (?> # optional tag attributes s # starts with whitespace (?> [^>"/]+# text outside quotes|/+(?!>) # slash not followed by ">"|"[^"] *" # text inside double quotes (tolerate ">") | '[^\']*::' # text inside single quotes (tolerate ">") )* )? '; $content = str_repeat(' (?> [^<]+ # content without tag | <\2 # nested opening tag '.$attr.' # attributes (?> /> | >', $nested_tags_level). // end of opening tag '.*?'. // last level nested tag content str_repeat(' </\2\s*> # closing nested tag ) | <(?!/\2\s*> # other tags with a different name ) )*', $nested_tags_level); $content2 = str_replace('\2', '\3', $content); /** * First, look for nested blocks, e.g.: * <div> * <div> * tags for inner block must be indented. * </div> * </div> * * The outermost tags must start at the left margin for this to match, * and the inner nested divs must be indented. * We need to do this before the next, more liberal match, because the * next match will start at the first `<div>` and stop at the * first `</div>`. */ $text = preg_replace_callback('{(?> (?> (?<=\n) # Starting on its own line | # or A\n? # the at beginning of the doc ) ( # save in $1 # Match from `\n<tag>` to `</tag>\n`, handling nested tags # in between. [ ]{0,'.$less_than_tab.'} <('.$block_tags_b_re.')# start tag = $2 '.$attr.'> # attributes followed by > and n '.$content.' # content, support nesting </\2> # the matching end tag [ ]* # trailing spaces/tabs (?=\n+|Z) # followed by a newline or end of document | # Special version for tags of group a. [ ]{0,'.$less_than_tab.'} <('.$block_tags_a_re.')# start tag = $3 '.$attr.'>[ ]*::n # attributes followed by > '.$content2.' # content, support nesting </\3> # the matching end tag [ ]* # trailing spaces/tabs (?=\n+|Z) # followed by a newline or end of document | # Special case just for <hr />. It was easier to make a special # case than to make the other regex more complicated. [ ]{0,'.$less_than_tab.'} <(hr) # start tag = $2 '.$attr.' # attributes /?> # the matching end tag [ ]* (?=\n{2,}|Z) # followed by a blank line or end of document | # Special case for standalone HTML comments: [ ]{0,'.$less_than_tab.'} (?s: <!-- .*? --> ) [ ]* (?=\n{2,}|Z) # followed by a blank line or end of document | # PHP and ASP-style processor instructions (<? and <%) [ ]{0,'.$less_than_tab.'} (?s: <([?%]) # $2 .*? 2> ) [ ]* (?=\n{2,}|Z) # followed by a blank line or end of document ) )}Sxmi', array($this, '_hashHTMLBlocks_callback'), $text ); return $text; } /** * The callback for hashing HTML blocks * @param string $matches * @retval string */ protected function _hashHTMLBlocks_callback($matches) { $text = $matches[1]; $key = $this->hashBlock($text); return "\n\n$key\n\n"; } /** * Called whenever a tag must be hashed when a function insert an atomic * element in the text stream. Passing $text to through this function gives * a unique text-token which will be reverted back when calling unhash. * * The $boundary argument specify what character should be used to surround * the token. By convension, "B" is used for block elements that needs not * to be wrapped into paragraph tags at the end, ":" is used for elements * that are word separators and "X" is used in the general case. * * @param string $text * @param string $boundary * @retval string */ protected function hashPart($text, $boundary = 'X') { // Swap back any tag hash found in $text so we do not have to `unhash` // multiple times at the end. $text = $this->unhash($text); // Then hash the block. static $i = 0; $key = " $boundary\x1A" . ++$i . $boundary; $this->html_hashes[$key] = $text; return $key; // String that will replace the tag. } /** * Shortcut function for hashPart with block-level boundaries. * @param string $text * @retval string */ protected function hashBlock($text) { return $this->hashPart($text, 'B'); } /** * Define the block gamut - these are all the transformations that form * block-level tags like paragraphs, headers, and list items. */ protected array $block_gamut = array( "doHeaders" => 10, "doHorizontalRules" => 20, "doLists" => 40, "doCodeBlocks" => 50, "doBlockQuotes" => 60, ); /** * Run block gamut tranformations. * * We need to escape raw HTML in Markdown source before doing anything * else. This need to be done for each block, and not only at the * begining in the Markdown function since hashed blocks can be part of * list items and could have been indented. Indented blocks would have * been seen as a code block in a previous pass of hashHTMLBlocks. * * @param string $text * @retval string */ protected function runBlockGamut($text) { $text = $this->hashHTMLBlocks($text); return $this->runBasicBlockGamut($text); } /** * Run block gamut tranformations, without hashing HTML blocks. This is * useful when HTML blocks are known to be already hashed, like in the first * whole-document pass. * * @param string $text * @retval string */ protected function runBasicBlockGamut($text) { foreach ($this->block_gamut as $method => $priority) { $text = $this->$method($text); } // Finally form paragraph and restore hashed blocks. $text = $this->formParagraphs($text); return $text; } /** * Convert horizontal rules * @param string $text * @retval string */ protected function doHorizontalRules($text) { return preg_replace( '{ ^[ ]{0,3} # Leading space ([-*_]) # $1: First marker (?> # Repeated marker group [ ]{0,2} # Zero, one, or two spaces. 1 # Marker character ){2,} # Group repeated at least twice [ ]* # Tailing spaces $ # End of line. }mx', "\n".$this->hashBlock("< hr$this->empty_element_suffix")."\n", $text ); } /** * These are all the transformations that occur *within* block-level * tags like paragraphs, headers, and list items. */ protected array $span_gamut = array( // Process character escapes, code spans, and inline HTML // in one shot. "parseSpan" => -30, // Process anchor and image tags. Images must come first, // because ![foo][f] looks like an anchor. "doImages" => 10, "doAnchors" => 20, // Make links out of things like `<https://example.com/>` // Must come after doAnchors, because you can use < and > // delimiters in inline links like [this](<url>). "doAutoLinks" => 30, "encodeAmpsAndAngles" => 40, "doItalicsAndBold" => 50, "doHardBreaks" => 60, ); /** * Run span gamut transformations * @param string $text * @retval string */ protected function runSpanGamut($text) { foreach ($this->span_gamut as $method => $priority) { $text = $this->$method($text); } return $text; } /** * Do hard breaks * @param string $text * @retval string */ protected function doHardBreaks($text) { if ($this->hard_wrap) { return preg_replace_callback('/ *::n/', array($this, '_doHardBreaks_callback'), $text); } else { return preg_replace_callback('/ {2,}\n/', array($this, '_doHardBreaks_callback'), $text); } } /** * Trigger part hashing for the hard break (callback method) * @param array $matches * @retval string */ protected function _doHardBreaks_callback($matches) { return $this->hashPart("< br$this->empty_element_suffix\n"); } /** * Turn Markdown link shortcuts into XHTML <a> tags. * @param string $text * @retval string */ protected function doAnchors($text) { if ($this->in_anchor) { return $text; } $this->in_anchor = true; // First, handle reference-style links: [link text] [id] $text = preg_replace_callback('{ ( # wrap whole match in $1 [ ('.$this->nested_brackets_re.') # link text = $2 ] [ ]? # one optional space (?:\n[ ]*)? # one optional newline followed by spaces [ (.*?) # id = $3 ] ) }xs', array($this, '_doAnchors_reference_callback'), $text); // Next, inline-style links: [link text](url "optional title") $text = preg_replace_callback('{ ( # wrap whole match in $1 [ ('.$this->nested_brackets_re.') # link text = $2 ] ( # literal paren [ n]* (?: <(.+?)> # href = $3 | ('.$this->nested_url_parenthesis_re.') # href = $4 ) [ n]* ( # $5 ([\'"]) # quote char
 
 unhash ($text)
 Swap back in all the tags hashed by _HashHTMLBlocks.
 

Variables

array $abbr_desciptions = array()
 
string $abbr_word_re = ''
 
string $auto_close_tags_re = 'hr|img|param|source|track'
 Tags that do not need to be closed.
 
string $block_tags_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend|article|section|nav|aside|hgroup|header|footer|figcaption|figure|details|summary'
 HTML block parser.
 
string $clean_tags_re = 'script|style|math|svg'
 Tags which must not have their contents modified, no matter where they appear.
 
string $contain_span_tags_re = 'p|h[1-6]|li|dd|dt|td|th|legend|address'
 Tags where markdown="1" default to span mode:
 
string $context_block_tags_re = 'script|noscript|style|ins|del|iframe|object|source|track|param|math|svg|canvas|audio|video'
 Tags treated as block tags only if the opening tag is alone on its line.
 
array array $em_relist
 Define the emphasis operators with their regex matches.
 
array array $em_relist
 Redefining emphasis markers so that emphasis by underscore does not work in the middle of a word.
 
array $em_strong_prepared_relist = null
 Container for prepared regular expressions.
 
array array $em_strong_relist
 Define the emphasis + strong operators with their regex matches.
 
array $em_strong_relist
 
int $footnote_counter = 1
 Give the current footnote number.
 
array $footnotes = array()
 Extra variables used during extra transformations.
 
array $footnotes_numbers = array()
 
array $footnotes_ordered = array()
 
array $footnotes_ref_count = array()
 
string $id_class_attr_catch_re = '\{((?>[ ]*[#.a-z][-_:a-zA-Z0-9=]+){1,})[ ]*::}'
 Extra attribute parser.
 
string $id_class_attr_nocatch_re = '\{(?>[ ]*[#.a-z][-_:a-zA-Z0-9=]+){1,}[ ]*::}'
 Expression to use when parsing in a context when no capture is desired.
 
int $list_level = 0
 Nesting tracker for list levels.
 
array $ref_attr = array()
 Ref attribute for links.
 
array array $strong_relist
 Define the strong operators with their regex matches.
 
array $strong_relist
 
return $text
 
 $utf8_strlen = 'mb_strlen'
 String length function for detab.
 
$this block_gamut
 
*ingroup php markdown *author Michel Fortin< michel.fortin @michelf.com > *copyright Michel Fortin< https:*@copyright(Original Markdown) 2004-2006 John Gruber< https:*/namespace Michelf;class MarkdownExtra extends Michelf\Markdown { public string $fn_id_prefix="";public string $fn_link_title="";public string $fn_link_class="footnote-ref";public string $fn_backlink_class="footnote-backref";public string $fn_backlink_html='&#8617;&#xFE0E;';public string $fn_backlink_title="";public string $fn_backlink_label="";public string $table_align_class_tmpl='';public string $code_class_prefix="";public bool $code_attr_on_pre=false;public array $predef_abbr=array();public bool $hashtag_protection=false;public bool $omit_footnotes=false;public ?string $footnotes_assembled=null;public function __construct() { $this->escape_chars .=':|';$this-> document_gamut
 
$this enhanced_ordered_list = true
 
$this in_anchor = false
 
$this span_gamut
 

Detailed Description

Function Documentation

◆ _appendFootnotes_callback()

_appendFootnotes_callback ( $matches)
protected

Callback for appending footnotes.

Parameters
array$matches
Return values
string

◆ _detab_callback()

_detab_callback ( $matches)
protected

Replace tabs callback.

Parameters
string$matches
Return values
string

◆ _doAbbreviations_callback()

_doAbbreviations_callback ( $matches)
protected

Callback for processing abbreviations.

Parameters
array$matches
Return values
string

◆ _doAnchors_inline_callback()

_doAnchors_inline_callback ( $matches)
protected

Callback method to parse inline anchors.

Callback for inline anchors.

Parameters
array$matches
Return values
string

◆ _doAnchors_reference_callback()

_doAnchors_reference_callback ( $matches)
protected

Callback method to parse referenced anchors.

Callback for reference anchors.

Parameters
array$matches
Return values
string

◆ _doAutoLinks_email_callback()

_doAutoLinks_email_callback ( $matches)
protected

Parse email address callback.

Parameters
array$matches
Return values
string

◆ _doAutoLinks_url_callback()

_doAutoLinks_url_callback ( $matches)
protected

Parse URL callback.

Parameters
array$matches
Return values
string

◆ _doBlockQuotes_callback()

_doBlockQuotes_callback ( $matches)
protected

Blockquote parsing callback.

Parameters
array$matches
Return values
string

◆ _doBlockQuotes_callback2()

_doBlockQuotes_callback2 ( $matches)
protected

Blockquote parsing callback.

Parameters
array$matches
Return values
string

◆ _doCodeBlocks_callback()

_doCodeBlocks_callback ( $matches)
protected

Code block parsing callback.

Parameters
array$matches
Return values
string

◆ _doDefLists_callback()

_doDefLists_callback ( $matches)
protected

Callback for processing definition lists.

Parameters
array$matches
Return values
string

◆ _doFencedCodeBlocks_callback()

_doFencedCodeBlocks_callback ( $matches)
protected

Callback to process fenced code blocks.

Parameters
array$matches
Return values
string

◆ _doFencedCodeBlocks_newlines()

_doFencedCodeBlocks_newlines ( $matches)
protected

Replace new lines in fenced code blocks.

Parameters
array$matches
Return values
string

◆ _doFootnotes()

_doFootnotes ( )
protected

Generates the HTML for footnotes.

Called by appendFootnotes, even if footnotes are not being appended.

Return values
void

◆ _doHeaders_callback_atx()

_doHeaders_callback_atx ( $matches)
protected

ATX header parsing callback.

Callback for atx headers.

Parameters
array$matches
Return values
string

◆ _doHeaders_callback_setext()

_doHeaders_callback_setext ( $matches)
protected

Setext header parsing callback.

Callback for setext headers.

Parameters
array$matches
Return values
string

◆ _doImages_inline_callback()

_doImages_inline_callback ( $matches)
protected

Callback to parse inline image tags.

Callback for inline images.

Parameters
array$matches
Return values
string

◆ _doImages_reference_callback()

_doImages_reference_callback ( $matches)
protected

Callback to parse references image tags.

Callback for referenced images.

Parameters
array$matches
Return values
string

◆ _doLists_callback()

_doLists_callback ( $matches)
protected

List parsing callback.

Parameters
array$matches
Return values
string

◆ _doTable_callback()

_doTable_callback ( $matches)
protected

Calback for processing tables.

Parameters
array$matches
Return values
string

◆ _doTable_leadingPipe_callback()

_doTable_leadingPipe_callback ( $matches)
protected

Callback for removing the leading pipe for each row.

Parameters
array$matches
Return values
string

◆ _doTable_makeAlignAttr()

_doTable_makeAlignAttr ( $alignname)
protected

Make the align attribute in a table.

Parameters
string$alignname
Return values
string

◆ _generateIdFromHeaderValue()

_generateIdFromHeaderValue ( $headerValue)
protected

If a header_id_func property is set, we can use it to automatically generate an id attribute.

This method returns a string in the form id="foo", or an empty string otherwise.

Parameters
string$headerValue
Return values
string

◆ _hashHTMLBlocks_inHTML()

_hashHTMLBlocks_inHTML ( $text,
$hash_method,
$md_attr )
protected

Parse HTML, calling _HashHTMLBlocks_InMarkdown for block tags.

  • Calls $hash_method to convert any blocks.
  • Stops when the first opening tag closes.
  • $md_attr indicate if the use of the markdown="1" attribute is allowed. (it is not inside clean tags)

Returns an array of that form: ( processed text , remaining text )

Parameters
string$text
string$hash_method
bool$md_attrHandle markdown="1" attribute
Return values
array

◆ _hashHTMLBlocks_inMarkdown()

_hashHTMLBlocks_inMarkdown ( $text,
$indent = 0,
$enclosing_tag_re = '',
$span = false )
protected

Parse markdown text, calling _HashHTMLBlocks_InHTML for block tags.

  • $indent is the number of space to be ignored when checking for code blocks. This is important because if we don't take the indent into account, something like this (which looks right) won't work as expected:

    Hello World. <– Is this a Markdown code block or text?

    <– Is this a Markdown code block or a real tag?

    If you don't like this, just don't indent the tag on which you apply the markdown="1" attribute.
  • If $enclosing_tag_re is not empty, stops at the first unmatched closing tag with that name. Nested tags supported.
  • If $span is true, text inside must treated as span. So any double newline will be replaced by a single newline so that it does not create paragraphs.
Returns an array of that form: ( processed text , remaining text )
Parameters
string$text
integer$indent
string$enclosing_tag_re
boolean$span
Return values
array

◆ _initDetab()

_initDetab ( )
protected

Check for the availability of the function in the utf8_strlen property (initially mb_strlen).

If the function is not available, create a function that will loosely count the number of UTF-8 characters with a regular expression.

Return values
void

◆ _processDefListItems_callback_dd()

_processDefListItems_callback_dd ( $matches)
protected

Callback for elements in definition lists.

Parameters
array$matches
Return values
string

◆ _processDefListItems_callback_dt()

_processDefListItems_callback_dt ( $matches)
protected

Callback for elements in definition lists.

Parameters
array$matches
Return values
string

◆ _processListItems_callback()

_processListItems_callback ( $matches)
protected

List item parsing callback.

Parameters
array$matches
Return values
string

◆ _stripAbbreviations_callback()

_stripAbbreviations_callback ( $matches)
protected

Callback for stripping abbreviations.

Parameters
array$matches
Return values
string

◆ _stripFootnotes_callback()

_stripFootnotes_callback ( $matches)
protected

Callback for stripping footnotes.

Parameters
array$matches
Return values
string

◆ _stripLinkDefinitions_callback()

_stripLinkDefinitions_callback ( $matches)
protected

Strip link definition callback.

Parameters
array$matches
Return values
string

◆ _unhash_callback()

_unhash_callback ( $matches)
protected

Unhashing callback.

Parameters
array$matches
Return values
string

◆ appendFootnotes()

appendFootnotes ( $text)
protected

Append footnote list to text.

Parameters
string$text
Return values
string

◆ detab()

detab ( $text)
protected

Replace tabs with the appropriate amount of spaces.

For each line we separate the line in blocks delemited by tab characters. Then we reconstruct every line by adding the appropriate number of space between each blocks.

Parameters
string$text
Return values
string

◆ doAbbreviations()

doAbbreviations ( $text)
protected

Find defined abbreviations in text and wrap them in <abbr> elements.

Parameters
string$text
Return values
string

◆ doAnchors()

doAnchors ( $text)
protected

Turn Markdown link shortcuts into XHTML tags.

Parameters
string$text
Return values
string

◆ doAutoLinks()

doAutoLinks ( $text)
protected

Parse Markdown automatic links to anchor HTML tags.

Parameters
string$text
Return values
string

◆ doBlockQuotes()

doBlockQuotes ( $text)
protected

Parse Markdown blockquotes to HTML.

Parameters
string$text
Return values
string

◆ doCodeBlocks()

doCodeBlocks ( $text)
protected

Process Markdown <pre><code> blocks.

Parameters
string$text
Return values
string

◆ doDefLists()

doDefLists ( $text)
protected

Form HTML definition lists.

Parameters
string$text
Return values
string

◆ doExtraAttributes()

doExtraAttributes ( $tag_name,
$attr,
$defaultIdValue = null,
$classes = array() )
protected

Parse attributes caught by the $this->id_class_attr_catch_re expression and return the HTML-formatted list of attributes.

Currently supported attributes are .class and id.

In addition, this method also supports supplying a default Id value, which will be used to populate the id attribute in case it was not overridden.

Parameters
string$tag_name
string$attr
mixed$defaultIdValue
array$classes
Return values
string

◆ doFencedCodeBlocks()

doFencedCodeBlocks ( $text)
protected

Adding the fenced code block syntax to regular Markdown:

Code block
Parameters
string$text
Return values
string

◆ doFootnotes()

doFootnotes ( $text)
protected

Replace footnote references in $text [^id] with a special text-token which will be replaced by the actual footnote marker in appendFootnotes.

Parameters
string$text
Return values
string

◆ doHeaders()

doHeaders ( $text)
protected

Parse Markdown heading elements to HTML.

Process markdown headers.

Parameters
string$text
Return values
string

Redefined to add ID and class attribute support.

Parameters
string$text
Return values
string

◆ doImages()

doImages ( $text)
protected

Turn Markdown image shortcuts into.

tags.

Parameters
string$text
Return values
string

◆ doItalicsAndBold()

doItalicsAndBold ( $text)
protected

Convert Markdown italics (emphasis) and bold (strong) to HTML.

Parameters
string$text
Return values
string

◆ doLists()

doLists ( $text)
protected

Form HTML ordered (numbered) and unordered (bulleted) lists.

Parameters
string$text
Return values
string

◆ doTables()

doTables ( $text)
protected

Form HTML tables.

Parameters
string$text
Return values
string

◆ encodeAmpsAndAngles()

encodeAmpsAndAngles ( $text)
protected

Smart processing for ampersands and angle brackets that need to be encoded.

Valid character entities are left alone unless the no-entities mode is set.

Parameters
string$text
Return values
string

◆ encodeAttribute()

encodeAttribute ( $text)
protected

Encode text for a double-quoted HTML attribute.

This function is not suitable for attributes enclosed in single quotes.

Parameters
string$text
Return values
string

◆ encodeEntityObfuscatedAttribute()

encodeEntityObfuscatedAttribute ( $text,
& $tail = null,
$head_length = 0 )
protected

Input: some text to obfuscate, e.g.

"mailto:foo@example.com"

Output: the same text but with most characters encoded as either a decimal or hex entity, in the hopes of foiling most address harvesting spam bots. E.g.:

&#109;&#x61;&#105;&#x6c;&#116;&#x6f;&#58;&#x66;o&#111; &#x40;&#101;&#x78;&#97;&#x6d;&#112;&#x6c;&#101;&#46;&#x63;&#111; &#x6d;

Note: the additional output $tail is assigned the same value as the ouput, minus the number of characters specified by $head_length.

Based by a filter by Matthew Wickline, posted to BBEdit-Talk. With some optimizations by Milian Wolff. Forced encoding of HTML attribute special characters by Allan Odgaard.

Parameters
string$text
string$tailPassed by reference
integer$head_length
Return values
string

◆ encodeURLAttribute()

encodeURLAttribute ( $url,
& $text = null )
protected

Encode text for a double-quoted HTML attribute containing a URL, applying the URL filter if set.

Also generates the textual representation for the URL (removing mailto: or tel:) storing it in $text. This function is not suitable for attributes enclosed in single quotes.

Parameters
string$url
string$textPassed by reference
Return values
stringURL

◆ formParagraphs()

formParagraphs ( $text,
$wrap_in_p = true )
protected

Parse paragraphs.

Parse text into paragraphs.

Parameters
string$textString to process in paragraphs
boolean$wrap_in_pWhether paragraphs should be wrapped in

tags

Return values
string
Parameters
string$textString to process in paragraphs
boolean$wrap_in_pWhether paragraphs should be wrapped in

tags

Return values
stringHTML output

◆ handleSpanToken()

handleSpanToken ( $token,
& $str )
protected

Handle $token provided by parseSpan by determining its nature and returning the corresponding value that should replace it.

Parameters
string$token
string$strPassed by reference
Return values
string

◆ hashClean()

hashClean ( $text)
protected

Called whenever a tag must be hashed when a function inserts a "clean" tag in $text, it passes through this function and is automaticaly escaped, blocking invalid nested overlap.

Parameters
string$text
Return values
string

◆ hashHTMLBlocks()

hashHTMLBlocks ( $text)
protected

Hashify HTML Blocks and "clean tags".

We only want to do this for block-level HTML tags, such as headers, lists, and tables. That's because we still want to wrap

s around "paragraphs" that are wrapped in non-block-level tags, such as anchors, phrase emphasis, and spans. The list of tags we're looking for is hard-coded.

This works by calling _HashHTMLBlocks_InMarkdown, which then calls _HashHTMLBlocks_InHTML when it encounter block tags. When the markdown="1" attribute is found within a tag, _HashHTMLBlocks_InHTML calls back _HashHTMLBlocks_InMarkdown to handle the Markdown syntax within the tag. These two functions are calling each other. It's recursive!

Parameters
string$text
Return values
string

◆ makeCodeSpan()

makeCodeSpan ( $code)
protected

Create a code span markup for $code.

Called from handleSpanToken.

Parameters
string$code
Return values
string

◆ outdent()

outdent ( $text)
protected

Remove one level of line-leading tabs or spaces.

Parameters
string$text
Return values
string

◆ parseFootnotePlaceholders()

parseFootnotePlaceholders ( $label,
$footnote_number,
$reference_number )
protected

Build footnote label by evaluating any placeholders.

  • ^^ footnote number
  • %% footnote reference number (Nth reference to footnote number)
    Parameters
    string$label
    int$footnote_number
    int$reference_number
    Return values
    string

◆ parseSpan()

parseSpan ( $str)
protected

Take the string $str and parse it into tokens, hashing embeded HTML, escaped characters and handling code spans.

Parameters
string$str
Return values
string

◆ prepareItalicsAndBold()

prepareItalicsAndBold ( )
protected

Prepare regular expressions for searching emphasis tokens in any context.

Return values
void

◆ processDefListItems()

processDefListItems ( $list_str)
protected

Process the contents of a single definition list, splitting it into individual term and definition list items.

Parameters
string$list_str
Return values
string

◆ processListItems()

processListItems ( $list_str,
$marker_any_re )
protected

Process the contents of a single ordered or unordered list, splitting it into individual list items.

Parameters
string$list_str
string$marker_any_re
Return values
string

◆ stripAbbreviations()

stripAbbreviations ( $text)
protected

Abbreviations - strips abbreviations from text, stores titles in hash references.

Parameters
string$text
Return values
string

◆ stripFootnotes()

stripFootnotes ( $text)
protected

Footnotes - Strips link definitions from text, stores the URLs and titles in hash references.

Parameters
string$text
Return values
string

◆ stripLinkDefinitions()

stripLinkDefinitions ( $text)
protected

Strips link definitions from text, stores the URLs and titles in hash references.

Parameters
string$text
Return values
string

◆ unhash()

unhash ( $text)
protected

Swap back in all the tags hashed by _HashHTMLBlocks.

Parameters
string$text
Return values
string

Variable Documentation

◆ $block_tags_re

string $block_tags_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend|article|section|nav|aside|hgroup|header|footer|figcaption|figure|details|summary'
protected

HTML block parser.

Tags that are always treated as block tags

◆ $em_relist [1/2]

array array $em_relist
protected
Initial value:
= array(
'' => '(?:(?<!\*)::*(?!::*)|(?<!_)_(?!_))(?![::.,:;]?::s)',
'*' => '(?<![::s*])::*(?!::*)',
'_' => '(?<![\s_])_(?!_)',
)

Define the emphasis operators with their regex matches.

◆ $em_relist [2/2]

array array $em_relist
protected
Initial value:
= array(
'' => '(?:(?<!\*)::*(?!::*)|(?<![a-zA-Z0-9_])_(?!_))(?![::.,:;]?::s)',
'*' => '(?<![::s*])::*(?!::*)',
'_' => '(?<![\s_])_(?![a-zA-Z0-9_])',
)

Redefining emphasis markers so that emphasis by underscore does not work in the middle of a word.

◆ $em_strong_relist [1/2]

array array $em_strong_relist
protected
Initial value:
= array(
'' => '(?:(?<!\*)::*::*::*(?!::*)|(?<!_)___(?!_))(?![::.,:;]?::s)',
'***' => '(?<![::s*])::*::*::*(?!::*)',
'___' => '(?<![\s_])___(?!_)',
)

Define the emphasis + strong operators with their regex matches.

◆ $em_strong_relist [2/2]

array $em_strong_relist
protected
Initial value:
= array(
'' => '(?:(?<!\*)::*::*::*(?!::*)|(?<![a-zA-Z0-9_])___(?!_))(?![::.,:;]?::s)',
'***' => '(?<![::s*])::*::*::*(?!::*)',
'___' => '(?<![\s_])___(?![a-zA-Z0-9_])',
)

◆ $id_class_attr_catch_re

string $id_class_attr_catch_re = '\{((?>[ ]*[#.a-z][-_:a-zA-Z0-9=]+){1,})[ ]*::}'
protected

Extra attribute parser.

Expression to use to catch attributes (includes the braces)

◆ $strong_relist [1/2]

array array $strong_relist
protected
Initial value:
= array(
'' => '(?:(?<!\*)::*::*(?!::*)|(?<!_)__(?!_))(?![::.,:;]?::s)',
'**' => '(?<![::s*])::*::*(?!::*)',
'__' => '(?<![\s_])__(?!_)',
)

Define the strong operators with their regex matches.

◆ $strong_relist [2/2]

array $strong_relist
protected
Initial value:
= array(
'' => '(?:(?<!\*)::*::*(?!::*)|(?<![a-zA-Z0-9_])__(?!_))(?![::.,:;]?::s)',
'**' => '(?<![::s*])::*::*(?!::*)',
'__' => '(?<![\s_])__(?![a-zA-Z0-9_])',
)

◆ $utf8_strlen

$utf8_strlen = 'mb_strlen'
protected

String length function for detab.

_initDetab will create a function to handle UTF-8 if the default function does not exist. can be a string or function

◆ block_gamut

$this block_gamut
Initial value:
= array(
"doFencedCodeBlocks" => 5,
"doTables" => 15,
"doDefLists" => 45,
)

◆ document_gamut

* ingroup php markdown* author Michel Fortin<michel.fortin@michelf.com>* copyright Michel Fortin<https: * @copyright (Original Markdown) 2004-2006 John Gruber <https: */namespace Michelf; class MarkdownExtra extends Michelf\Markdown { public string $fn_id_prefix = ""; public string $fn_link_title = ""; public string $fn_link_class = "footnote-ref"; public string $fn_backlink_class = "footnote-backref"; public string $fn_backlink_html = '&#8617;&#xFE0E;'; public string $fn_backlink_title = ""; public string $fn_backlink_label = ""; public string $table_align_class_tmpl = ''; public string $code_class_prefix = ""; public bool $code_attr_on_pre = false; public array $predef_abbr = array(); public bool $hashtag_protection = false; public bool $omit_footnotes = false; public ?string $footnotes_assembled = null; public function __construct() { $this->escape_chars .= ':|'; $this-> document_gamut
Initial value:
= array(
"doFencedCodeBlocks" => 5,
"stripFootnotes" => 15,
"stripAbbreviations" => 25,
"appendFootnotes" => 50,
)

◆ span_gamut

$this span_gamut
Initial value:
= array(
"doFootnotes" => 5,
"doAbbreviations" => 70,
)