Changeset 10000 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/libs/michelf-php-markdown-1.6.0/Michelf/MarkdownExtra.php
- Timestamp:
- 07/03/2020 03:11:38 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/libs/michelf-php-markdown-1.6.0/Michelf/MarkdownExtra.php
r2638 r10000 4 4 # 5 5 # PHP Markdown Extra 6 # Copyright (c) 2004-2015 Michel Fortin 6 # Copyright (c) 2004-2015 Michel Fortin 7 7 # <https://michelf.ca/projects/php-markdown/> 8 8 # 9 9 # Original Markdown 10 # Copyright (c) 2004-2006 John Gruber 10 # Copyright (c) 2004-2006 John Gruber 11 11 # <https://daringfireball.net/projects/markdown/> 12 12 # … … 58 58 # Constructor function. Initialize the parser object. 59 59 # 60 # Add extra escapable characters before parent constructor 60 # Add extra escapable characters before parent constructor 61 61 # initialize the table. 62 62 $this->escape_chars .= ':|'; 63 63 64 # Insert extra document, block, and span transformations. 64 # Insert extra document, block, and span transformations. 65 65 # Parent constructor will do the sorting. 66 66 $this->document_gamut += array( … … 237 237 # Tags that are always treated as block tags: 238 238 protected $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'; 239 239 240 240 # Tags treated as block tags only if the opening tag is alone on its line: 241 241 protected $context_block_tags_re = 'script|noscript|style|ins|del|iframe|object|source|track|param|math|svg|canvas|audio|video'; … … 244 244 protected $contain_span_tags_re = 'p|h[1-6]|li|dd|dt|td|th|legend|address'; 245 245 246 # Tags which must not have their contents modified, no matter where 246 # Tags which must not have their contents modified, no matter where 247 247 # they appear: 248 248 protected $clean_tags_re = 'script|style|math|svg'; … … 263 263 # 264 264 # This works by calling _HashHTMLBlocks_InMarkdown, which then calls 265 # _HashHTMLBlocks_InHTML when it encounter block tags. When the markdown="1" 265 # _HashHTMLBlocks_InHTML when it encounter block tags. When the markdown="1" 266 266 # attribute is found within a tag, _HashHTMLBlocks_InHTML calls back 267 267 # _HashHTMLBlocks_InMarkdown to handle the Markdown syntax within the tag. … … 283 283 # Parse markdown text, calling _HashHTMLBlocks_InHTML for block tags. 284 284 # 285 # * $indent is the number of space to be ignored when checking for code 286 # blocks. This is important because if we don't take the indent into 285 # * $indent is the number of space to be ignored when checking for code 286 # blocks. This is important because if we don't take the indent into 287 287 # account, something like this (which looks right) won't work as expected: 288 288 # … … 296 296 # you apply the markdown="1" attribute. 297 297 # 298 # * If $enclosing_tag_re is not empty, stops at the first unmatched closing 298 # * If $enclosing_tag_re is not empty, stops at the first unmatched closing 299 299 # tag with that name. Nested tags supported. 300 300 # 301 # * If $span is true, text inside must treated as span. So any double 302 # newline will be replaced by a single newline so that it does not create 301 # * If $span is true, text inside must treated as span. So any double 302 # newline will be replaced by a single newline so that it does not create 303 303 # paragraphs. 304 304 # … … 309 309 # Regex to check for the presense of newlines around a block tag. 310 310 $newline_before_re = '/(?:^\n?|\n\n)*$/'; 311 $newline_after_re = 311 $newline_after_re = 312 312 '{ 313 313 ^ # Start of text following the tag. … … 382 382 # Split the text using the first $tag_match pattern found. 383 383 # Text before pattern will be first in the array, text after 384 # pattern will be at the end, and between will be any catches made 384 # pattern will be at the end, and between will be any catches made 385 385 # by the pattern. 386 386 # 387 $parts = preg_split($block_tag_re, $text, 2, 387 $parts = preg_split($block_tag_re, $text, 2, 388 388 PREG_SPLIT_DELIM_CAPTURE); 389 389 390 # If in Markdown span mode, add a empty-string span-level hash 390 # If in Markdown span mode, add a empty-string span-level hash 391 391 # after each newline to prevent triggering any block element. 392 392 if ($span) { … … 418 418 $fence_re = $capture[2]; # use captured fence in re 419 419 if (preg_match('{^(?>.*\n)*?[ ]{'.($fence_indent).'}'.$fence_re.'[ ]*(?:\n|$)}', $text, 420 $matches)) 420 $matches)) 421 421 { 422 422 # End marker found: pass text unchanged until marker. … … 433 433 # 434 434 else if ($tag{0} == "\n" || $tag{0} == " ") { 435 # Indented code block: pass it unchanged, will be handled 435 # Indented code block: pass it unchanged, will be handled 436 436 # later. 437 437 $parsed .= $tag; … … 458 458 # 459 459 # Check for: Opening Block level tag or 460 # Opening Context Block tag (like ins and del) 460 # Opening Context Block tag (like ins and del) 461 461 # used as a block tag (tag is alone on it's line). 462 462 # … … 468 468 { 469 469 # Need to parse tag and following text using the HTML parser. 470 list($block_text, $text) = 470 list($block_text, $text) = 471 471 $this->_hashHTMLBlocks_inHTML($tag . $text, "hashBlock", true); 472 472 … … 483 483 # Need to parse tag and following text using the HTML parser. 484 484 # (don't check for markdown attribute) 485 list($block_text, $text) = 485 list($block_text, $text) = 486 486 $this->_hashHTMLBlocks_inHTML($tag . $text, "hashClean", false); 487 487 … … 591 591 # Split the text using the first $tag_match pattern found. 592 592 # Text before pattern will be first in the array, text after 593 # pattern will be at the end, and between will be any catches made 593 # pattern will be at the end, and between will be any catches made 594 594 # by the pattern. 595 595 # … … 600 600 # End of $text reached with unbalenced tag(s). 601 601 # In that case, we return original text unchanged and pass the 602 # first character as filtered to prevent an infinite loop in the 602 # first character as filtered to prevent an infinite loop in the 603 603 # parent function. 604 604 # … … 633 633 # Check for `markdown="1"` attribute and handle it. 634 634 # 635 if ($md_attr && 635 if ($md_attr && 636 636 preg_match($markdown_attr_re, $tag, $attr_m) && 637 637 preg_match('/^1|block|span$/', $attr_m[2] . $attr_m[3])) … … 664 664 # Parse the content using the HTML-in-Markdown parser. 665 665 list ($block_text, $text) 666 = $this->_hashHTMLBlocks_inMarkdown($text, $indent, 666 = $this->_hashHTMLBlocks_inMarkdown($text, $indent, 667 667 $tag_name_re, $span_mode); 668 668 669 669 # Outdent markdown text. 670 670 if ($indent > 0) { 671 $block_text = preg_replace("/^[ ]{1,$indent}/m", "", 671 $block_text = preg_replace("/^[ ]{1,$indent}/m", "", 672 672 $block_text); 673 673 } … … 697 697 # 698 698 # Called whenever a tag must be hashed when a function inserts a "clean" tag 699 # in $text, it passes through this function and is automaticaly escaped, 699 # in $text, it passes through this function and is automaticaly escaped, 700 700 # blocking invalid nested overlap. 701 701 # … … 861 861 862 862 ) 863 }xs', 863 }xs', 864 864 array($this, '_doImages_reference_callback'), $text); 865 865 … … 954 954 # Header 1 {#header1} 955 955 # ======== 956 # 956 # 957 957 # Header 2 {#header2 .class1 .class2} 958 958 # -------- … … 1111 1111 } 1112 1112 1113 # Parsing span elements, including code spans, character escapes, 1113 # Parsing span elements, including code spans, character escapes, 1114 1114 # and inline HTML tags, so that pipes inside those gets ignored. 1115 1115 $head = $this->parseSpan($head); … … 1132 1132 $text .= "<tbody>\n"; 1133 1133 foreach ($rows as $row) { 1134 # Parsing span elements, including code spans, character escapes, 1134 # Parsing span elements, including code spans, character escapes, 1135 1135 # and inline HTML tags, so that pipes inside those gets ignored. 1136 1136 $row = $this->parseSpan($row); … … 1225 1225 (?> \S.* \n)+? # actual term (not whitespace). 1226 1226 ) 1227 (?=\n?[ ]{0,3}:[ ]) # lookahead for following line feed 1227 (?=\n?[ ]{0,3}:[ ]) # lookahead for following line feed 1228 1228 # with a definition mark. 1229 1229 }xm', … … 1347 1347 } 1348 1348 protected function _doFencedCodeBlocks_newlines($matches) { 1349 return str_repeat("<br$this->empty_element_suffix", 1349 return str_repeat("<br$this->empty_element_suffix", 1350 1350 strlen($matches[0])); 1351 1351 } … … 1399 1399 } 1400 1400 1401 # Join grafs in one text, then unhash HTML tags. 1401 # Join grafs in one text, then unhash HTML tags. 1402 1402 $text = implode("\n\n", $grafs); 1403 1403 … … 1427 1427 .+ # actual text 1428 1428 | 1429 \n # newlines but 1429 \n # newlines but 1430 1430 (?!\[.+?\][ ]?:\s)# negative lookahead for footnote or link definition marker. 1431 (?!\n+[ ]{0,3}\S)# ensure line is not blank and followed 1431 (?!\n+[ ]{0,3}\S)# ensure line is not blank and followed 1432 1432 # by non-indented content 1433 1433 )* … … 1447 1447 protected function doFootnotes($text) { 1448 1448 # 1449 # Replace footnote references in $text [^id] with a special text-token 1449 # Replace footnote references in $text [^id] with a special text-token 1450 1450 # which will be replaced by the actual footnote marker in appendFootnotes. 1451 1451 # … … 1461 1461 # Append footnote list to text. 1462 1462 # 1463 $text = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', 1463 $text = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', 1464 1464 array($this, '_appendFootnotes_callback'), $text); 1465 1465 … … 1494 1494 $footnote .= "\n"; # Need to append newline before parsing. 1495 1495 $footnote = $this->runBlockGamut("$footnote\n"); 1496 $footnote = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', 1496 $footnote = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', 1497 1497 array($this, '_appendFootnotes_callback'), $footnote); 1498 1498 … … 1598 1598 # 1599 1599 if ($this->abbr_word_re) { 1600 // cannot use the /x modifier because abbr_word_re may 1600 // cannot use the /x modifier because abbr_word_re may 1601 1601 // contain significant spaces: 1602 1602 $text = preg_replace_callback('{'. … … 1604 1604 '(?:'.$this->abbr_word_re.')'. 1605 1605 '(?![\w\x1A])'. 1606 '}', 1606 '}', 1607 1607 array($this, '_doAbbreviations_callback'), $text); 1608 1608 }
Note: See TracChangeset
for help on using the changeset viewer.