|
| _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.
|
|
|
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='↩︎';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 |
|