Changeset 10000 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/libs/michelf-php-markdown-1.6.0/Michelf/Markdown.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/Markdown.php
r2638 r10000 3 3 # Markdown - A text-to-HTML conversion tool for web writers 4 4 # 5 # PHP Markdown 6 # Copyright (c) 2004-2015 Michel Fortin 5 # PHP Markdown 6 # Copyright (c) 2004-2015 Michel Fortin 7 7 # <https://michelf.ca/projects/php-markdown/> 8 8 # 9 # Original Markdown 10 # Copyright (c) 2004-2006 John Gruber 9 # Original Markdown 10 # Copyright (c) 2004-2006 John Gruber 11 11 # <https://daringfireball.net/projects/markdown/> 12 12 # … … 74 74 # 2. List item two 75 75 # 3. List item three 76 # 76 # 77 77 # becomes 78 78 # <ol start="2"> … … 104 104 $this->prepareItalicsAndBold(); 105 105 106 $this->nested_brackets_re = 106 $this->nested_brackets_re = 107 107 str_repeat('(?>[^\[\]]+|\[', $this->nested_brackets_depth). 108 108 str_repeat('\])*', $this->nested_brackets_depth); 109 109 110 $this->nested_url_parenthesis_re = 110 $this->nested_url_parenthesis_re = 111 111 str_repeat('(?>[^()\s]+|\(', $this->nested_url_parenthesis_depth). 112 112 str_repeat('(?>\)))*', $this->nested_url_parenthesis_depth); … … 132 132 protected function setup() { 133 133 # 134 # Called before the transformation process starts to setup parser 134 # Called before the transformation process starts to setup parser 135 135 # states. 136 136 # … … 145 145 protected function teardown() { 146 146 # 147 # Called after the transformation process to clear any variable 147 # Called after the transformation process to clear any variable 148 148 # which may be taking up memory unnecessarly. 149 149 # … … 257 257 # 258 258 # * List "a" is made of tags which can be both inline or block-level. 259 # These will be treated block-level when the start tag is alone on 260 # its line, otherwise they're not matched here and will be taken as 259 # These will be treated block-level when the start tag is alone on 260 # its line, otherwise they're not matched here and will be taken as 261 261 # inline later. 262 262 # * List "b" is made of tags which are always block-level; … … 325 325 ( # save in $1 326 326 327 # Match from `\n<tag>` to `</tag>\n`, handling nested tags 327 # Match from `\n<tag>` to `</tag>\n`, handling nested tags 328 328 # in between. 329 329 … … 346 346 (?=\n+|\Z) # followed by a newline or end of document 347 347 348 | # Special case just for <hr />. It was easier to make a special 348 | # Special case just for <hr />. It was easier to make a special 349 349 # case than to make the other regex more complicated. 350 350 … … 392 392 protected function hashPart($text, $boundary = 'X') { 393 393 # 394 # Called whenever a tag must be hashed when a function insert an atomic 394 # Called whenever a tag must be hashed when a function insert an atomic 395 395 # element in the text stream. Passing $text to through this function gives 396 396 # a unique text-token which will be reverted back when calling unhash. … … 438 438 # Run block gamut tranformations. 439 439 # 440 # We need to escape raw HTML in Markdown source before doing anything 441 # else. This need to be done for each block, and not only at the 440 # We need to escape raw HTML in Markdown source before doing anything 441 # else. This need to be done for each block, and not only at the 442 442 # begining in the Markdown function since hashed blocks can be part of 443 # list items and could have been indented. Indented blocks would have 443 # list items and could have been indented. Indented blocks would have 444 444 # been seen as a code block in a previous pass of hashHTMLBlocks. 445 445 $text = $this->hashHTMLBlocks($text); … … 450 450 protected function runBasicBlockGamut($text) { 451 451 # 452 # Run block gamut tranformations, without hashing HTML blocks. This is 452 # Run block gamut tranformations, without hashing HTML blocks. This is 453 453 # useful when HTML blocks are known to be already hashed, like in the first 454 454 # whole-document pass. … … 478 478 $ # End of line. 479 479 }mx', 480 "\n".$this->hashBlock("<hr$this->empty_element_suffix")."\n", 480 "\n".$this->hashBlock("<hr$this->empty_element_suffix")."\n", 481 481 $text); 482 482 } … … 521 521 protected function doHardBreaks($text) { 522 522 # Do hard breaks: 523 return preg_replace_callback('/ {2,}\n/', 523 return preg_replace_callback('/ {2,}\n/', 524 524 array($this, '_doHardBreaks_callback'), $text); 525 525 } … … 681 681 682 682 ) 683 }xs', 683 }xs', 684 684 array($this, '_doImages_reference_callback'), $text); 685 685 … … 766 766 # Header 1 767 767 # ======== 768 # 768 # 769 769 # Header 2 770 770 # -------- … … 988 988 $tailing_blank_line =& $matches[5]; 989 989 990 if ($leading_line || $tailing_blank_line || 990 if ($leading_line || $tailing_blank_line || 991 991 preg_match('/\n{2,}/', $item)) 992 992 { … … 1105 1105 1106 1106 # 1107 # Each loop iteration search for the next emphasis token. 1107 # Each loop iteration search for the next emphasis token. 1108 1108 # Each token is then passed to handleSpanToken. 1109 1109 # … … 1161 1161 } 1162 1162 } else { 1163 # Reached opening three-char emphasis marker. Push on token 1163 # Reached opening three-char emphasis marker. Push on token 1164 1164 # stack; will be handled by the special condition above. 1165 1165 $em = $token{0}; … … 1235 1235 1236 1236 $bq = preg_replace('/^/m', " ", $bq); 1237 # These leading spaces cause problem with <pre> content, 1237 # These leading spaces cause problem with <pre> content, 1238 1238 # so we need to fix that: 1239 $bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx', 1239 $bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx', 1240 1240 array($this, '_doBlockQuotes_callback2'), $bq); 1241 1241 … … 1359 1359 protected function encodeAmpsAndAngles($text) { 1360 1360 # 1361 # Smart processing for ampersands and angle brackets that need to 1361 # Smart processing for ampersands and angle brackets that need to 1362 1362 # be encoded. Valid character entities are left alone unless the 1363 1363 # no-entities mode is set. … … 1368 1368 # Ampersand-encoding based entirely on Nat Irons's Amputator 1369 1369 # MT plugin: <http://bumppo.net/projects/amputator/> 1370 $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/', 1370 $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/', 1371 1371 '&', $text); 1372 1372 } … … 1498 1498 while (1) { 1499 1499 # 1500 # Each loop iteration seach for either the next tag, the next 1501 # openning code span marker, or the next escaped character. 1500 # Each loop iteration seach for either the next tag, the next 1501 # openning code span marker, or the next escaped character. 1502 1502 # Each token is then passed to handleSpanToken. 1503 1503 # … … 1525 1525 protected function handleSpanToken($token, &$str) { 1526 1526 # 1527 # Handle $token provided by parseSpan by determining its nature and 1527 # Handle $token provided by parseSpan by determining its nature and 1528 1528 # returning the corresponding value that should replace it. 1529 1529 # … … 1533 1533 case "`": 1534 1534 # Search for end marker in remaining text. 1535 if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm', 1535 if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm', 1536 1536 $str, $matches)) 1537 1537 { … … 1555 1555 1556 1556 1557 # String length function for detab. `_initDetab` will create a function to 1557 # String length function for detab. `_initDetab` will create a function to 1558 1558 # hanlde UTF-8 if the default function does not exist. 1559 1559 protected $utf8_strlen = 'mb_strlen'; … … 1564 1564 # 1565 1565 # For each line we separate the line in blocks delemited by 1566 # tab characters. Then we reconstruct every line by adding the 1566 # tab characters. Then we reconstruct every line by adding the 1567 1567 # appropriate number of space between each blocks. 1568 1568 … … 1583 1583 foreach ($blocks as $block) { 1584 1584 # Calculate amount of space, insert spaces, insert block. 1585 $amount = $this->tab_width - 1585 $amount = $this->tab_width - 1586 1586 $strlen($line, 'UTF-8') % $this->tab_width; 1587 1587 $line .= str_repeat(" ", $amount) . $block; … … 1592 1592 # 1593 1593 # Check for the availability of the function in the `utf8_strlen` property 1594 # (initially `mb_strlen`). If the function is not available, create a 1594 # (initially `mb_strlen`). If the function is not available, create a 1595 1595 # function that will loosely count the number of UTF-8 characters with a 1596 1596 # regular expression. … … 1598 1598 if (function_exists($this->utf8_strlen)) return; 1599 1599 $this->utf8_strlen = create_function('$text', 'return preg_match_all( 1600 "/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/", 1600 "/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/", 1601 1601 $text, $m);'); 1602 1602 } … … 1607 1607 # Swap back in all the tags hashed by _HashHTMLBlocks. 1608 1608 # 1609 return preg_replace_callback('/(.)\x1A[0-9]+\1/', 1609 return preg_replace_callback('/(.)\x1A[0-9]+\1/', 1610 1610 array($this, '_unhash_callback'), $text); 1611 1611 }
Note: See TracChangeset
for help on using the changeset viewer.