@@ -458,6 +458,9 @@ discard block |
||
| 458 | 458 | const CHARACTR = 4; |
| 459 | 459 | const EOF = 5; |
| 460 | 460 | |
| 461 | + /** |
|
| 462 | + * @param string $data |
|
| 463 | + */ |
|
| 461 | 464 | public function __construct($data) |
| 462 | 465 | { |
| 463 | 466 | $this->data = $data; |
@@ -478,6 +481,9 @@ discard block |
||
| 478 | 481 | return $this->tree->save(); |
| 479 | 482 | } |
| 480 | 483 | |
| 484 | + /** |
|
| 485 | + * @return string |
|
| 486 | + */ |
|
| 481 | 487 | private function char() |
| 482 | 488 | { |
| 483 | 489 | return ($this->char < $this->EOF) |
@@ -485,6 +491,11 @@ discard block |
||
| 485 | 491 | : false; |
| 486 | 492 | } |
| 487 | 493 | |
| 494 | + /** |
|
| 495 | + * @param integer $s |
|
| 496 | + * |
|
| 497 | + * @return string |
|
| 498 | + */ |
|
| 488 | 499 | private function character($s, $l = 0) |
| 489 | 500 | { |
| 490 | 501 | if ($s + $l < $this->EOF) { |
@@ -496,6 +507,10 @@ discard block |
||
| 496 | 507 | } |
| 497 | 508 | } |
| 498 | 509 | |
| 510 | + /** |
|
| 511 | + * @param string $char_class |
|
| 512 | + * @param integer $start |
|
| 513 | + */ |
|
| 499 | 514 | private function characters($char_class, $start) |
| 500 | 515 | { |
| 501 | 516 | return preg_replace('#^([' . $char_class . ']+).*#s', '\\1', substr($this->data, $start)); |
@@ -4645,6 +4660,9 @@ discard block |
||
| 4645 | 4660 | } |
| 4646 | 4661 | } |
| 4647 | 4662 | |
| 4663 | + /** |
|
| 4664 | + * @param string[] $elements |
|
| 4665 | + */ |
|
| 4648 | 4666 | private function clearStackToTableContext($elements) |
| 4649 | 4667 | { |
| 4650 | 4668 | /* When the steps above require the UA to clear the stack back to a |
@@ -469,7 +469,7 @@ discard block |
||
| 469 | 469 | $this->state = 'data'; |
| 470 | 470 | |
| 471 | 471 | while ($this->state !== null) { |
| 472 | - $this->{$this->state . 'State'}(); |
|
| 472 | + $this->{$this->state.'State'}(); |
|
| 473 | 473 | } |
| 474 | 474 | } |
| 475 | 475 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | private function char() |
| 482 | 482 | { |
| 483 | 483 | return ($this->char < $this->EOF) |
| 484 | - ? $this->data[$this->char] |
|
| 484 | + ? $this->data[ $this->char ] |
|
| 485 | 485 | : false; |
| 486 | 486 | } |
| 487 | 487 | |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | { |
| 490 | 490 | if ($s + $l < $this->EOF) { |
| 491 | 491 | if ($l === 0) { |
| 492 | - return $this->data[$s]; |
|
| 492 | + return $this->data[ $s ]; |
|
| 493 | 493 | } else { |
| 494 | 494 | return substr($this->data, $s, $l); |
| 495 | 495 | } |
@@ -498,7 +498,7 @@ discard block |
||
| 498 | 498 | |
| 499 | 499 | private function characters($char_class, $start) |
| 500 | 500 | { |
| 501 | - return preg_replace('#^([' . $char_class . ']+).*#s', '\\1', substr($this->data, $start)); |
|
| 501 | + return preg_replace('#^(['.$char_class.']+).*#s', '\\1', substr($this->data, $start)); |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | private function dataState() |
@@ -845,7 +845,7 @@ discard block |
||
| 845 | 845 | /* Anything else |
| 846 | 846 | Append the current input character to the current tag token's tag name. |
| 847 | 847 | Stay in the tag name state. */ |
| 848 | - $this->token['name'] .= strtolower($char); |
|
| 848 | + $this->token[ 'name' ] .= strtolower($char); |
|
| 849 | 849 | $this->state = 'tagName'; |
| 850 | 850 | } |
| 851 | 851 | } |
@@ -891,7 +891,7 @@ discard block |
||
| 891 | 891 | Start a new attribute in the current tag token. Set that attribute's |
| 892 | 892 | name to the current input character, and its value to the empty string. |
| 893 | 893 | Switch to the attribute name state. */ |
| 894 | - $this->token['attr'][] = array( |
|
| 894 | + $this->token[ 'attr' ][ ] = array( |
|
| 895 | 895 | 'name' => strtolower($char), |
| 896 | 896 | 'value' => null |
| 897 | 897 | ); |
@@ -945,8 +945,8 @@ discard block |
||
| 945 | 945 | /* Anything else |
| 946 | 946 | Append the current input character to the current attribute's name. |
| 947 | 947 | Stay in the attribute name state. */ |
| 948 | - $last = count($this->token['attr']) - 1; |
|
| 949 | - $this->token['attr'][$last]['name'] .= strtolower($char); |
|
| 948 | + $last = count($this->token[ 'attr' ]) - 1; |
|
| 949 | + $this->token[ 'attr' ][ $last ][ 'name' ] .= strtolower($char); |
|
| 950 | 950 | |
| 951 | 951 | $this->state = 'attributeName'; |
| 952 | 952 | } |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | Start a new attribute in the current tag token. Set that attribute's |
| 999 | 999 | name to the current input character, and its value to the empty string. |
| 1000 | 1000 | Switch to the attribute name state. */ |
| 1001 | - $this->token['attr'][] = array( |
|
| 1001 | + $this->token[ 'attr' ][ ] = array( |
|
| 1002 | 1002 | 'name' => strtolower($char), |
| 1003 | 1003 | 'value' => null |
| 1004 | 1004 | ); |
@@ -1049,8 +1049,8 @@ discard block |
||
| 1049 | 1049 | /* Anything else |
| 1050 | 1050 | Append the current input character to the current attribute's value. |
| 1051 | 1051 | Switch to the attribute value (unquoted) state. */ |
| 1052 | - $last = count($this->token['attr']) - 1; |
|
| 1053 | - $this->token['attr'][$last]['value'] .= $char; |
|
| 1052 | + $last = count($this->token[ 'attr' ]) - 1; |
|
| 1053 | + $this->token[ 'attr' ][ $last ][ 'value' ] .= $char; |
|
| 1054 | 1054 | |
| 1055 | 1055 | $this->state = 'attributeValueUnquoted'; |
| 1056 | 1056 | } |
@@ -1085,8 +1085,8 @@ discard block |
||
| 1085 | 1085 | /* Anything else |
| 1086 | 1086 | Append the current input character to the current attribute's value. |
| 1087 | 1087 | Stay in the attribute value (double-quoted) state. */ |
| 1088 | - $last = count($this->token['attr']) - 1; |
|
| 1089 | - $this->token['attr'][$last]['value'] .= $char; |
|
| 1088 | + $last = count($this->token[ 'attr' ]) - 1; |
|
| 1089 | + $this->token[ 'attr' ][ $last ][ 'value' ] .= $char; |
|
| 1090 | 1090 | |
| 1091 | 1091 | $this->state = 'attributeValueDoubleQuoted'; |
| 1092 | 1092 | } |
@@ -1121,8 +1121,8 @@ discard block |
||
| 1121 | 1121 | /* Anything else |
| 1122 | 1122 | Append the current input character to the current attribute's value. |
| 1123 | 1123 | Stay in the attribute value (single-quoted) state. */ |
| 1124 | - $last = count($this->token['attr']) - 1; |
|
| 1125 | - $this->token['attr'][$last]['value'] .= $char; |
|
| 1124 | + $last = count($this->token[ 'attr' ]) - 1; |
|
| 1125 | + $this->token[ 'attr' ][ $last ][ 'value' ] .= $char; |
|
| 1126 | 1126 | |
| 1127 | 1127 | $this->state = 'attributeValueSingleQuoted'; |
| 1128 | 1128 | } |
@@ -1158,8 +1158,8 @@ discard block |
||
| 1158 | 1158 | /* Anything else |
| 1159 | 1159 | Append the current input character to the current attribute's value. |
| 1160 | 1160 | Stay in the attribute value (unquoted) state. */ |
| 1161 | - $last = count($this->token['attr']) - 1; |
|
| 1162 | - $this->token['attr'][$last]['value'] .= $char; |
|
| 1161 | + $last = count($this->token[ 'attr' ]) - 1; |
|
| 1162 | + $this->token[ 'attr' ][ $last ][ 'value' ] .= $char; |
|
| 1163 | 1163 | |
| 1164 | 1164 | $this->state = 'attributeValueUnquoted'; |
| 1165 | 1165 | } |
@@ -1177,8 +1177,8 @@ discard block |
||
| 1177 | 1177 | ? '&' |
| 1178 | 1178 | : $entity; |
| 1179 | 1179 | |
| 1180 | - $last = count($this->token['attr']) - 1; |
|
| 1181 | - $this->token['attr'][$last]['value'] .= $char; |
|
| 1180 | + $last = count($this->token[ 'attr' ]) - 1; |
|
| 1181 | + $this->token[ 'attr' ][ $last ][ 'value' ] .= $char; |
|
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | private function bogusCommentState() |
@@ -1262,7 +1262,7 @@ discard block |
||
| 1262 | 1262 | } else { |
| 1263 | 1263 | /* Append the input character to the comment token's data. Stay in |
| 1264 | 1264 | the comment state. */ |
| 1265 | - $this->token['data'] .= $char; |
|
| 1265 | + $this->token[ 'data' ] .= $char; |
|
| 1266 | 1266 | } |
| 1267 | 1267 | } |
| 1268 | 1268 | |
@@ -1289,7 +1289,7 @@ discard block |
||
| 1289 | 1289 | } else { |
| 1290 | 1290 | /* Append a U+002D HYPHEN-MINUS (-) character and the input |
| 1291 | 1291 | character to the comment token's data. Switch to the comment state. */ |
| 1292 | - $this->token['data'] .= '-' . $char; |
|
| 1292 | + $this->token[ 'data' ] .= '-'.$char; |
|
| 1293 | 1293 | $this->state = 'comment'; |
| 1294 | 1294 | } |
| 1295 | 1295 | } |
@@ -1305,7 +1305,7 @@ discard block |
||
| 1305 | 1305 | $this->state = 'data'; |
| 1306 | 1306 | |
| 1307 | 1307 | } elseif ($char === '-') { |
| 1308 | - $this->token['data'] .= '-'; |
|
| 1308 | + $this->token[ 'data' ] .= '-'; |
|
| 1309 | 1309 | |
| 1310 | 1310 | } elseif ($this->char === $this->EOF) { |
| 1311 | 1311 | $this->emitToken($this->token); |
@@ -1313,7 +1313,7 @@ discard block |
||
| 1313 | 1313 | $this->state = 'data'; |
| 1314 | 1314 | |
| 1315 | 1315 | } else { |
| 1316 | - $this->token['data'] .= '--' . $char; |
|
| 1316 | + $this->token[ 'data' ] .= '--'.$char; |
|
| 1317 | 1317 | $this->state = 'comment'; |
| 1318 | 1318 | } |
| 1319 | 1319 | } |
@@ -1399,7 +1399,7 @@ discard block |
||
| 1399 | 1399 | $this->state = 'data'; |
| 1400 | 1400 | |
| 1401 | 1401 | } elseif (preg_match('/^[a-z]$/', $char)) { |
| 1402 | - $this->token['name'] .= strtoupper($char); |
|
| 1402 | + $this->token[ 'name' ] .= strtoupper($char); |
|
| 1403 | 1403 | |
| 1404 | 1404 | } elseif ($this->char === $this->EOF) { |
| 1405 | 1405 | $this->emitToken($this->token); |
@@ -1407,10 +1407,10 @@ discard block |
||
| 1407 | 1407 | $this->state = 'data'; |
| 1408 | 1408 | |
| 1409 | 1409 | } else { |
| 1410 | - $this->token['name'] .= $char; |
|
| 1410 | + $this->token[ 'name' ] .= $char; |
|
| 1411 | 1411 | } |
| 1412 | 1412 | |
| 1413 | - $this->token['error'] = ($this->token['name'] === 'HTML') |
|
| 1413 | + $this->token[ 'error' ] = ($this->token[ 'name' ] === 'HTML') |
|
| 1414 | 1414 | ? false |
| 1415 | 1415 | : true; |
| 1416 | 1416 | } |
@@ -1434,7 +1434,7 @@ discard block |
||
| 1434 | 1434 | $this->state = 'data'; |
| 1435 | 1435 | |
| 1436 | 1436 | } else { |
| 1437 | - $this->token['error'] = true; |
|
| 1437 | + $this->token[ 'error' ] = true; |
|
| 1438 | 1438 | $this->state = 'bogusDoctype'; |
| 1439 | 1439 | } |
| 1440 | 1440 | } |
@@ -1523,8 +1523,8 @@ discard block |
||
| 1523 | 1523 | $this->char++; |
| 1524 | 1524 | |
| 1525 | 1525 | if (in_array($id, $this->entities)) { |
| 1526 | - if ($e_name[$c - 1] !== ';') { |
|
| 1527 | - if ($c < $len && $e_name[$c] == ';') { |
|
| 1526 | + if ($e_name[ $c - 1 ] !== ';') { |
|
| 1527 | + if ($c < $len && $e_name[ $c ] == ';') { |
|
| 1528 | 1528 | $this->char++; // consume extra semicolon |
| 1529 | 1529 | } |
| 1530 | 1530 | } |
@@ -1547,7 +1547,7 @@ discard block |
||
| 1547 | 1547 | |
| 1548 | 1548 | // Return a character token for the character corresponding to the |
| 1549 | 1549 | // entity name (as given by the second column of the entities table). |
| 1550 | - return html_entity_decode('&' . $entity . ';', ENT_QUOTES, 'UTF-8'); |
|
| 1550 | + return html_entity_decode('&'.$entity.';', ENT_QUOTES, 'UTF-8'); |
|
| 1551 | 1551 | } |
| 1552 | 1552 | |
| 1553 | 1553 | private function emitToken($token) |
@@ -1557,7 +1557,7 @@ discard block |
||
| 1557 | 1557 | if (is_int($emit)) { |
| 1558 | 1558 | $this->content_model = $emit; |
| 1559 | 1559 | |
| 1560 | - } elseif ($token['type'] === self::ENDTAG) { |
|
| 1560 | + } elseif ($token[ 'type' ] === self::ENDTAG) { |
|
| 1561 | 1561 | $this->content_model = self::PCDATA; |
| 1562 | 1562 | } |
| 1563 | 1563 | } |
@@ -1740,13 +1740,13 @@ discard block |
||
| 1740 | 1740 | U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF), |
| 1741 | 1741 | or U+0020 SPACE |
| 1742 | 1742 | An end-of-file token */ |
| 1743 | - if ((isset($token['error']) && $token['error']) || |
|
| 1744 | - $token['type'] === HTML5::COMMENT || |
|
| 1745 | - $token['type'] === HTML5::STARTTAG || |
|
| 1746 | - $token['type'] === HTML5::ENDTAG || |
|
| 1747 | - $token['type'] === HTML5::EOF || |
|
| 1748 | - ($token['type'] === HTML5::CHARACTR && isset($token['data']) && |
|
| 1749 | - !preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) |
|
| 1743 | + if ((isset($token[ 'error' ]) && $token[ 'error' ]) || |
|
| 1744 | + $token[ 'type' ] === HTML5::COMMENT || |
|
| 1745 | + $token[ 'type' ] === HTML5::STARTTAG || |
|
| 1746 | + $token[ 'type' ] === HTML5::ENDTAG || |
|
| 1747 | + $token[ 'type' ] === HTML5::EOF || |
|
| 1748 | + ($token[ 'type' ] === HTML5::CHARACTR && isset($token[ 'data' ]) && |
|
| 1749 | + !preg_match('/^[\t\n\x0b\x0c ]+$/', $token[ 'data' ])) |
|
| 1750 | 1750 | ) { |
| 1751 | 1751 | /* This specification does not define how to handle this case. In |
| 1752 | 1752 | particular, user agents may ignore the entirety of this specification |
@@ -1757,7 +1757,7 @@ discard block |
||
| 1757 | 1757 | return $this->rootElementPhase($token); |
| 1758 | 1758 | |
| 1759 | 1759 | /* A DOCTYPE token marked as being correct */ |
| 1760 | - } elseif (isset($token['error']) && !$token['error']) { |
|
| 1760 | + } elseif (isset($token[ 'error' ]) && !$token[ 'error' ]) { |
|
| 1761 | 1761 | /* Append a DocumentType node to the Document node, with the name |
| 1762 | 1762 | attribute set to the name given in the DOCTYPE token (which will be |
| 1763 | 1763 | "HTML"), and the other attributes specific to DocumentType objects |
@@ -1771,13 +1771,13 @@ discard block |
||
| 1771 | 1771 | /* A character token that is one of one of U+0009 CHARACTER TABULATION, |
| 1772 | 1772 | U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF), |
| 1773 | 1773 | or U+0020 SPACE */ |
| 1774 | - } elseif (isset($token['data']) && preg_match( |
|
| 1774 | + } elseif (isset($token[ 'data' ]) && preg_match( |
|
| 1775 | 1775 | '/^[\t\n\x0b\x0c ]+$/', |
| 1776 | - $token['data'] |
|
| 1776 | + $token[ 'data' ] |
|
| 1777 | 1777 | ) |
| 1778 | 1778 | ) { |
| 1779 | 1779 | /* Append that character to the Document node. */ |
| 1780 | - $text = $this->dom->createTextNode($token['data']); |
|
| 1780 | + $text = $this->dom->createTextNode($token[ 'data' ]); |
|
| 1781 | 1781 | $this->dom->appendChild($text); |
| 1782 | 1782 | } |
| 1783 | 1783 | } |
@@ -1788,24 +1788,24 @@ discard block |
||
| 1788 | 1788 | stage, it must be processed as described in this section. */ |
| 1789 | 1789 | |
| 1790 | 1790 | /* A DOCTYPE token */ |
| 1791 | - if ($token['type'] === HTML5::DOCTYPE) { |
|
| 1791 | + if ($token[ 'type' ] === HTML5::DOCTYPE) { |
|
| 1792 | 1792 | // Parse error. Ignore the token. |
| 1793 | 1793 | |
| 1794 | 1794 | /* A comment token */ |
| 1795 | - } elseif ($token['type'] === HTML5::COMMENT) { |
|
| 1795 | + } elseif ($token[ 'type' ] === HTML5::COMMENT) { |
|
| 1796 | 1796 | /* Append a Comment node to the Document object with the data |
| 1797 | 1797 | attribute set to the data given in the comment token. */ |
| 1798 | - $comment = $this->dom->createComment($token['data']); |
|
| 1798 | + $comment = $this->dom->createComment($token[ 'data' ]); |
|
| 1799 | 1799 | $this->dom->appendChild($comment); |
| 1800 | 1800 | |
| 1801 | 1801 | /* A character token that is one of one of U+0009 CHARACTER TABULATION, |
| 1802 | 1802 | U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF), |
| 1803 | 1803 | or U+0020 SPACE */ |
| 1804 | - } elseif ($token['type'] === HTML5::CHARACTR && |
|
| 1805 | - preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data']) |
|
| 1804 | + } elseif ($token[ 'type' ] === HTML5::CHARACTR && |
|
| 1805 | + preg_match('/^[\t\n\x0b\x0c ]+$/', $token[ 'data' ]) |
|
| 1806 | 1806 | ) { |
| 1807 | 1807 | /* Append that character to the Document node. */ |
| 1808 | - $text = $this->dom->createTextNode($token['data']); |
|
| 1808 | + $text = $this->dom->createTextNode($token[ 'data' ]); |
|
| 1809 | 1809 | $this->dom->appendChild($text); |
| 1810 | 1810 | |
| 1811 | 1811 | /* A character token that is not one of U+0009 CHARACTER TABULATION, |
@@ -1814,18 +1814,18 @@ discard block |
||
| 1814 | 1814 | A start tag token |
| 1815 | 1815 | An end tag token |
| 1816 | 1816 | An end-of-file token */ |
| 1817 | - } elseif (($token['type'] === HTML5::CHARACTR && |
|
| 1818 | - !preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) || |
|
| 1819 | - $token['type'] === HTML5::STARTTAG || |
|
| 1820 | - $token['type'] === HTML5::ENDTAG || |
|
| 1821 | - $token['type'] === HTML5::EOF |
|
| 1817 | + } elseif (($token[ 'type' ] === HTML5::CHARACTR && |
|
| 1818 | + !preg_match('/^[\t\n\x0b\x0c ]+$/', $token[ 'data' ])) || |
|
| 1819 | + $token[ 'type' ] === HTML5::STARTTAG || |
|
| 1820 | + $token[ 'type' ] === HTML5::ENDTAG || |
|
| 1821 | + $token[ 'type' ] === HTML5::EOF |
|
| 1822 | 1822 | ) { |
| 1823 | 1823 | /* Create an HTMLElement node with the tag name html, in the HTML |
| 1824 | 1824 | namespace. Append it to the Document object. Switch to the main |
| 1825 | 1825 | phase and reprocess the current token. */ |
| 1826 | 1826 | $html = $this->dom->createElement('html'); |
| 1827 | 1827 | $this->dom->appendChild($html); |
| 1828 | - $this->stack[] = $html; |
|
| 1828 | + $this->stack[ ] = $html; |
|
| 1829 | 1829 | |
| 1830 | 1830 | $this->phase = self::MAIN_PHASE; |
| 1831 | 1831 | return $this->mainPhase($token); |
@@ -1837,11 +1837,11 @@ discard block |
||
| 1837 | 1837 | /* Tokens in the main phase must be handled as follows: */ |
| 1838 | 1838 | |
| 1839 | 1839 | /* A DOCTYPE token */ |
| 1840 | - if ($token['type'] === HTML5::DOCTYPE) { |
|
| 1840 | + if ($token[ 'type' ] === HTML5::DOCTYPE) { |
|
| 1841 | 1841 | // Parse error. Ignore the token. |
| 1842 | 1842 | |
| 1843 | 1843 | /* A start tag token with the tag name "html" */ |
| 1844 | - } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'html') { |
|
| 1844 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && $token[ 'name' ] === 'html') { |
|
| 1845 | 1845 | /* If this start tag token was not the first start tag token, then |
| 1846 | 1846 | it is a parse error. */ |
| 1847 | 1847 | |
@@ -1849,14 +1849,14 @@ discard block |
||
| 1849 | 1849 | is already present on the top element of the stack of open elements. |
| 1850 | 1850 | If it is not, add the attribute and its corresponding value to that |
| 1851 | 1851 | element. */ |
| 1852 | - foreach ($token['attr'] as $attr) { |
|
| 1853 | - if (!$this->stack[0]->hasAttribute($attr['name'])) { |
|
| 1854 | - $this->stack[0]->setAttribute($attr['name'], $attr['value']); |
|
| 1852 | + foreach ($token[ 'attr' ] as $attr) { |
|
| 1853 | + if (!$this->stack[ 0 ]->hasAttribute($attr[ 'name' ])) { |
|
| 1854 | + $this->stack[ 0 ]->setAttribute($attr[ 'name' ], $attr[ 'value' ]); |
|
| 1855 | 1855 | } |
| 1856 | 1856 | } |
| 1857 | 1857 | |
| 1858 | 1858 | /* An end-of-file token */ |
| 1859 | - } elseif ($token['type'] === HTML5::EOF) { |
|
| 1859 | + } elseif ($token[ 'type' ] === HTML5::EOF) { |
|
| 1860 | 1860 | /* Generate implied end tags. */ |
| 1861 | 1861 | $this->generateImpliedEndTags(); |
| 1862 | 1862 | |
@@ -1920,20 +1920,20 @@ discard block |
||
| 1920 | 1920 | /* A character token that is one of one of U+0009 CHARACTER TABULATION, |
| 1921 | 1921 | U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF), |
| 1922 | 1922 | or U+0020 SPACE */ |
| 1923 | - if ($token['type'] === HTML5::CHARACTR && |
|
| 1924 | - preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data']) |
|
| 1923 | + if ($token[ 'type' ] === HTML5::CHARACTR && |
|
| 1924 | + preg_match('/^[\t\n\x0b\x0c ]+$/', $token[ 'data' ]) |
|
| 1925 | 1925 | ) { |
| 1926 | 1926 | /* Append the character to the current node. */ |
| 1927 | - $this->insertText($token['data']); |
|
| 1927 | + $this->insertText($token[ 'data' ]); |
|
| 1928 | 1928 | |
| 1929 | 1929 | /* A comment token */ |
| 1930 | - } elseif ($token['type'] === HTML5::COMMENT) { |
|
| 1930 | + } elseif ($token[ 'type' ] === HTML5::COMMENT) { |
|
| 1931 | 1931 | /* Append a Comment node to the current node with the data attribute |
| 1932 | 1932 | set to the data given in the comment token. */ |
| 1933 | - $this->insertComment($token['data']); |
|
| 1933 | + $this->insertComment($token[ 'data' ]); |
|
| 1934 | 1934 | |
| 1935 | 1935 | /* A start tag token with the tag name "head" */ |
| 1936 | - } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'head') { |
|
| 1936 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && $token[ 'name' ] === 'head') { |
|
| 1937 | 1937 | /* Create an element for the token, append the new element to the |
| 1938 | 1938 | current node and push it onto the stack of open elements. */ |
| 1939 | 1939 | $element = $this->insertElement($token); |
@@ -1949,11 +1949,11 @@ discard block |
||
| 1949 | 1949 | Or a character token that is not one of U+0009 CHARACTER TABULATION, |
| 1950 | 1950 | U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF), |
| 1951 | 1951 | or U+0020 SPACE. Or any other start tag token */ |
| 1952 | - } elseif ($token['type'] === HTML5::STARTTAG || |
|
| 1953 | - ($token['type'] === HTML5::ENDTAG && $token['name'] === 'html') || |
|
| 1954 | - ($token['type'] === HTML5::CHARACTR && !preg_match( |
|
| 1952 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG || |
|
| 1953 | + ($token[ 'type' ] === HTML5::ENDTAG && $token[ 'name' ] === 'html') || |
|
| 1954 | + ($token[ 'type' ] === HTML5::CHARACTR && !preg_match( |
|
| 1955 | 1955 | '/^[\t\n\x0b\x0c ]$/', |
| 1956 | - $token['data'] |
|
| 1956 | + $token[ 'data' ] |
|
| 1957 | 1957 | )) |
| 1958 | 1958 | ) { |
| 1959 | 1959 | /* Act as if a start tag token with the tag name "head" and no |
@@ -1969,7 +1969,7 @@ discard block |
||
| 1969 | 1969 | return $this->inHead($token); |
| 1970 | 1970 | |
| 1971 | 1971 | /* Any other end tag */ |
| 1972 | - } elseif ($token['type'] === HTML5::ENDTAG) { |
|
| 1972 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG) { |
|
| 1973 | 1973 | /* Parse error. Ignore the token. */ |
| 1974 | 1974 | } |
| 1975 | 1975 | } |
@@ -1985,30 +1985,30 @@ discard block |
||
| 1985 | 1985 | THIS DIFFERS FROM THE SPEC: If the current node is either a title, style |
| 1986 | 1986 | or script element, append the character to the current node regardless |
| 1987 | 1987 | of its content. */ |
| 1988 | - if (($token['type'] === HTML5::CHARACTR && |
|
| 1989 | - preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) || ( |
|
| 1990 | - $token['type'] === HTML5::CHARACTR && in_array( |
|
| 1988 | + if (($token[ 'type' ] === HTML5::CHARACTR && |
|
| 1989 | + preg_match('/^[\t\n\x0b\x0c ]+$/', $token[ 'data' ])) || ( |
|
| 1990 | + $token[ 'type' ] === HTML5::CHARACTR && in_array( |
|
| 1991 | 1991 | end($this->stack)->nodeName, |
| 1992 | 1992 | array('title', 'style', 'script') |
| 1993 | 1993 | )) |
| 1994 | 1994 | ) { |
| 1995 | 1995 | /* Append the character to the current node. */ |
| 1996 | - $this->insertText($token['data']); |
|
| 1996 | + $this->insertText($token[ 'data' ]); |
|
| 1997 | 1997 | |
| 1998 | 1998 | /* A comment token */ |
| 1999 | - } elseif ($token['type'] === HTML5::COMMENT) { |
|
| 1999 | + } elseif ($token[ 'type' ] === HTML5::COMMENT) { |
|
| 2000 | 2000 | /* Append a Comment node to the current node with the data attribute |
| 2001 | 2001 | set to the data given in the comment token. */ |
| 2002 | - $this->insertComment($token['data']); |
|
| 2002 | + $this->insertComment($token[ 'data' ]); |
|
| 2003 | 2003 | |
| 2004 | - } elseif ($token['type'] === HTML5::ENDTAG && |
|
| 2005 | - in_array($token['name'], array('title', 'style', 'script')) |
|
| 2004 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG && |
|
| 2005 | + in_array($token[ 'name' ], array('title', 'style', 'script')) |
|
| 2006 | 2006 | ) { |
| 2007 | 2007 | array_pop($this->stack); |
| 2008 | 2008 | return HTML5::PCDATA; |
| 2009 | 2009 | |
| 2010 | 2010 | /* A start tag with the tag name "title" */ |
| 2011 | - } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'title') { |
|
| 2011 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && $token[ 'name' ] === 'title') { |
|
| 2012 | 2012 | /* Create an element for the token and append the new element to the |
| 2013 | 2013 | node pointed to by the head element pointer, or, if that is null |
| 2014 | 2014 | (innerHTML case), to the current node. */ |
@@ -2024,7 +2024,7 @@ discard block |
||
| 2024 | 2024 | return HTML5::RCDATA; |
| 2025 | 2025 | |
| 2026 | 2026 | /* A start tag with the tag name "style" */ |
| 2027 | - } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'style') { |
|
| 2027 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && $token[ 'name' ] === 'style') { |
|
| 2028 | 2028 | /* Create an element for the token and append the new element to the |
| 2029 | 2029 | node pointed to by the head element pointer, or, if that is null |
| 2030 | 2030 | (innerHTML case), to the current node. */ |
@@ -2040,7 +2040,7 @@ discard block |
||
| 2040 | 2040 | return HTML5::CDATA; |
| 2041 | 2041 | |
| 2042 | 2042 | /* A start tag with the tag name "script" */ |
| 2043 | - } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'script') { |
|
| 2043 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && $token[ 'name' ] === 'script') { |
|
| 2044 | 2044 | /* Create an element for the token. */ |
| 2045 | 2045 | $element = $this->insertElement($token, false); |
| 2046 | 2046 | $this->head_pointer->appendChild($element); |
@@ -2049,8 +2049,8 @@ discard block |
||
| 2049 | 2049 | return HTML5::CDATA; |
| 2050 | 2050 | |
| 2051 | 2051 | /* A start tag with the tag name "base", "link", or "meta" */ |
| 2052 | - } elseif ($token['type'] === HTML5::STARTTAG && in_array( |
|
| 2053 | - $token['name'], |
|
| 2052 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && in_array( |
|
| 2053 | + $token[ 'name' ], |
|
| 2054 | 2054 | array('base', 'link', 'meta') |
| 2055 | 2055 | ) |
| 2056 | 2056 | ) { |
@@ -2067,7 +2067,7 @@ discard block |
||
| 2067 | 2067 | } |
| 2068 | 2068 | |
| 2069 | 2069 | /* An end tag with the tag name "head" */ |
| 2070 | - } elseif ($token['type'] === HTML5::ENDTAG && $token['name'] === 'head') { |
|
| 2070 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG && $token[ 'name' ] === 'head') { |
|
| 2071 | 2071 | /* If the current node is a head element, pop the current node off |
| 2072 | 2072 | the stack of open elements. */ |
| 2073 | 2073 | if ($this->head_pointer->isSameNode(end($this->stack))) { |
@@ -2082,8 +2082,8 @@ discard block |
||
| 2082 | 2082 | $this->mode = self::AFTER_HEAD; |
| 2083 | 2083 | |
| 2084 | 2084 | /* A start tag with the tag name "head" or an end tag except "html". */ |
| 2085 | - } elseif (($token['type'] === HTML5::STARTTAG && $token['name'] === 'head') || |
|
| 2086 | - ($token['type'] === HTML5::ENDTAG && $token['name'] !== 'html') |
|
| 2085 | + } elseif (($token[ 'type' ] === HTML5::STARTTAG && $token[ 'name' ] === 'head') || |
|
| 2086 | + ($token[ 'type' ] === HTML5::ENDTAG && $token[ 'name' ] !== 'html') |
|
| 2087 | 2087 | ) { |
| 2088 | 2088 | // Parse error. Ignore the token. |
| 2089 | 2089 | |
@@ -2116,20 +2116,20 @@ discard block |
||
| 2116 | 2116 | /* A character token that is one of one of U+0009 CHARACTER TABULATION, |
| 2117 | 2117 | U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF), |
| 2118 | 2118 | or U+0020 SPACE */ |
| 2119 | - if ($token['type'] === HTML5::CHARACTR && |
|
| 2120 | - preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data']) |
|
| 2119 | + if ($token[ 'type' ] === HTML5::CHARACTR && |
|
| 2120 | + preg_match('/^[\t\n\x0b\x0c ]+$/', $token[ 'data' ]) |
|
| 2121 | 2121 | ) { |
| 2122 | 2122 | /* Append the character to the current node. */ |
| 2123 | - $this->insertText($token['data']); |
|
| 2123 | + $this->insertText($token[ 'data' ]); |
|
| 2124 | 2124 | |
| 2125 | 2125 | /* A comment token */ |
| 2126 | - } elseif ($token['type'] === HTML5::COMMENT) { |
|
| 2126 | + } elseif ($token[ 'type' ] === HTML5::COMMENT) { |
|
| 2127 | 2127 | /* Append a Comment node to the current node with the data attribute |
| 2128 | 2128 | set to the data given in the comment token. */ |
| 2129 | - $this->insertComment($token['data']); |
|
| 2129 | + $this->insertComment($token[ 'data' ]); |
|
| 2130 | 2130 | |
| 2131 | 2131 | /* A start tag token with the tag name "body" */ |
| 2132 | - } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'body') { |
|
| 2132 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && $token[ 'name' ] === 'body') { |
|
| 2133 | 2133 | /* Insert a body element for the token. */ |
| 2134 | 2134 | $this->insertElement($token); |
| 2135 | 2135 | |
@@ -2137,7 +2137,7 @@ discard block |
||
| 2137 | 2137 | $this->mode = self::IN_BODY; |
| 2138 | 2138 | |
| 2139 | 2139 | /* A start tag token with the tag name "frameset" */ |
| 2140 | - } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'frameset') { |
|
| 2140 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && $token[ 'name' ] === 'frameset') { |
|
| 2141 | 2141 | /* Insert a frameset element for the token. */ |
| 2142 | 2142 | $this->insertElement($token); |
| 2143 | 2143 | |
@@ -2146,8 +2146,8 @@ discard block |
||
| 2146 | 2146 | |
| 2147 | 2147 | /* A start tag token whose tag name is one of: "base", "link", "meta", |
| 2148 | 2148 | "script", "style", "title" */ |
| 2149 | - } elseif ($token['type'] === HTML5::STARTTAG && in_array( |
|
| 2150 | - $token['name'], |
|
| 2149 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && in_array( |
|
| 2150 | + $token[ 'name' ], |
|
| 2151 | 2151 | array('base', 'link', 'meta', 'script', 'style', 'title') |
| 2152 | 2152 | ) |
| 2153 | 2153 | ) { |
@@ -2176,25 +2176,25 @@ discard block |
||
| 2176 | 2176 | { |
| 2177 | 2177 | /* Handle the token as follows: */ |
| 2178 | 2178 | |
| 2179 | - switch ($token['type']) { |
|
| 2179 | + switch ($token[ 'type' ]) { |
|
| 2180 | 2180 | /* A character token */ |
| 2181 | 2181 | case HTML5::CHARACTR: |
| 2182 | 2182 | /* Reconstruct the active formatting elements, if any. */ |
| 2183 | 2183 | $this->reconstructActiveFormattingElements(); |
| 2184 | 2184 | |
| 2185 | 2185 | /* Append the token's character to the current node. */ |
| 2186 | - $this->insertText($token['data']); |
|
| 2186 | + $this->insertText($token[ 'data' ]); |
|
| 2187 | 2187 | break; |
| 2188 | 2188 | |
| 2189 | 2189 | /* A comment token */ |
| 2190 | 2190 | case HTML5::COMMENT: |
| 2191 | 2191 | /* Append a Comment node to the current node with the data |
| 2192 | 2192 | attribute set to the data given in the comment token. */ |
| 2193 | - $this->insertComment($token['data']); |
|
| 2193 | + $this->insertComment($token[ 'data' ]); |
|
| 2194 | 2194 | break; |
| 2195 | 2195 | |
| 2196 | 2196 | case HTML5::STARTTAG: |
| 2197 | - switch ($token['name']) { |
|
| 2197 | + switch ($token[ 'name' ]) { |
|
| 2198 | 2198 | /* A start tag token whose tag name is one of: "script", |
| 2199 | 2199 | "style" */ |
| 2200 | 2200 | case 'script': |
@@ -2221,7 +2221,7 @@ discard block |
||
| 2221 | 2221 | elements is not a body element, or, if the stack of open |
| 2222 | 2222 | elements has only one node on it, then ignore the token. |
| 2223 | 2223 | (innerHTML case) */ |
| 2224 | - if (count($this->stack) === 1 || $this->stack[1]->nodeName !== 'body') { |
|
| 2224 | + if (count($this->stack) === 1 || $this->stack[ 1 ]->nodeName !== 'body') { |
|
| 2225 | 2225 | // Ignore |
| 2226 | 2226 | |
| 2227 | 2227 | /* Otherwise, for each attribute on the token, check to see |
@@ -2230,9 +2230,9 @@ discard block |
||
| 2230 | 2230 | add the attribute and its corresponding value to that |
| 2231 | 2231 | element. */ |
| 2232 | 2232 | } else { |
| 2233 | - foreach ($token['attr'] as $attr) { |
|
| 2234 | - if (!$this->stack[1]->hasAttribute($attr['name'])) { |
|
| 2235 | - $this->stack[1]->setAttribute($attr['name'], $attr['value']); |
|
| 2233 | + foreach ($token[ 'attr' ] as $attr) { |
|
| 2234 | + if (!$this->stack[ 1 ]->hasAttribute($attr[ 'name' ])) { |
|
| 2235 | + $this->stack[ 1 ]->setAttribute($attr[ 'name' ], $attr[ 'value' ]); |
|
| 2236 | 2236 | } |
| 2237 | 2237 | } |
| 2238 | 2238 | } |
@@ -2319,13 +2319,13 @@ discard block |
||
| 2319 | 2319 | /* 1. Initialise node to be the current node (the |
| 2320 | 2320 | bottommost node of the stack). */ |
| 2321 | 2321 | $stop = false; |
| 2322 | - $node = $this->stack[$n]; |
|
| 2322 | + $node = $this->stack[ $n ]; |
|
| 2323 | 2323 | $cat = $this->getElementCategory($node->tagName); |
| 2324 | 2324 | |
| 2325 | 2325 | /* 2. If node is an li, dd or dt element, then pop all |
| 2326 | 2326 | the nodes from the current node up to node, including |
| 2327 | 2327 | node, then stop this algorithm. */ |
| 2328 | - if ($token['name'] === $node->tagName || ($token['name'] !== 'li' |
|
| 2328 | + if ($token[ 'name' ] === $node->tagName || ($token[ 'name' ] !== 'li' |
|
| 2329 | 2329 | && ($node->tagName === 'dd' || $node->tagName === 'dt')) |
| 2330 | 2330 | ) { |
| 2331 | 2331 | for ($x = $stack_length; $x >= $n; $x--) { |
@@ -2416,10 +2416,10 @@ discard block |
||
| 2416 | 2416 | $leng = count($this->a_formatting); |
| 2417 | 2417 | |
| 2418 | 2418 | for ($n = $leng - 1; $n >= 0; $n--) { |
| 2419 | - if ($this->a_formatting[$n] === self::MARKER) { |
|
| 2419 | + if ($this->a_formatting[ $n ] === self::MARKER) { |
|
| 2420 | 2420 | break; |
| 2421 | 2421 | |
| 2422 | - } elseif ($this->a_formatting[$n]->nodeName === 'a') { |
|
| 2422 | + } elseif ($this->a_formatting[ $n ]->nodeName === 'a') { |
|
| 2423 | 2423 | $this->emitToken( |
| 2424 | 2424 | array( |
| 2425 | 2425 | 'name' => 'a', |
@@ -2438,7 +2438,7 @@ discard block |
||
| 2438 | 2438 | |
| 2439 | 2439 | /* Add that element to the list of active formatting |
| 2440 | 2440 | elements. */ |
| 2441 | - $this->a_formatting[] = $el; |
|
| 2441 | + $this->a_formatting[ ] = $el; |
|
| 2442 | 2442 | break; |
| 2443 | 2443 | |
| 2444 | 2444 | /* A start tag whose tag name is one of: "b", "big", "em", "font", |
@@ -2463,7 +2463,7 @@ discard block |
||
| 2463 | 2463 | |
| 2464 | 2464 | /* Add that element to the list of active formatting |
| 2465 | 2465 | elements. */ |
| 2466 | - $this->a_formatting[] = $el; |
|
| 2466 | + $this->a_formatting[ ] = $el; |
|
| 2467 | 2467 | break; |
| 2468 | 2468 | |
| 2469 | 2469 | /* A start tag token whose tag name is "button" */ |
@@ -2489,7 +2489,7 @@ discard block |
||
| 2489 | 2489 | |
| 2490 | 2490 | /* Insert a marker at the end of the list of active |
| 2491 | 2491 | formatting elements. */ |
| 2492 | - $this->a_formatting[] = self::MARKER; |
|
| 2492 | + $this->a_formatting[ ] = self::MARKER; |
|
| 2493 | 2493 | break; |
| 2494 | 2494 | |
| 2495 | 2495 | /* A start tag token whose tag name is one of: "marquee", "object" */ |
@@ -2503,7 +2503,7 @@ discard block |
||
| 2503 | 2503 | |
| 2504 | 2504 | /* Insert a marker at the end of the list of active |
| 2505 | 2505 | formatting elements. */ |
| 2506 | - $this->a_formatting[] = self::MARKER; |
|
| 2506 | + $this->a_formatting[ ] = self::MARKER; |
|
| 2507 | 2507 | break; |
| 2508 | 2508 | |
| 2509 | 2509 | /* A start tag token whose tag name is "xmp" */ |
@@ -2583,7 +2583,7 @@ discard block |
||
| 2583 | 2583 | case 'image': |
| 2584 | 2584 | /* Parse error. Change the token's tag name to "img" and |
| 2585 | 2585 | reprocess it. (Don't ask.) */ |
| 2586 | - $token['name'] = 'img'; |
|
| 2586 | + $token[ 'name' ] = 'img'; |
|
| 2587 | 2587 | return $this->inBody($token); |
| 2588 | 2588 | break; |
| 2589 | 2589 | |
@@ -2656,7 +2656,7 @@ discard block |
||
| 2656 | 2656 | |
| 2657 | 2657 | /* Act as if a stream of character tokens had been seen. */ |
| 2658 | 2658 | $this->insertText( |
| 2659 | - 'This is a searchable index. ' . |
|
| 2659 | + 'This is a searchable index. '. |
|
| 2660 | 2660 | 'Insert your search keywords here: ' |
| 2661 | 2661 | ); |
| 2662 | 2662 | |
@@ -2664,8 +2664,8 @@ discard block |
||
| 2664 | 2664 | had been seen, with all the attributes from the "isindex" |
| 2665 | 2665 | token, except with the "name" attribute set to the value |
| 2666 | 2666 | "isindex" (ignoring any explicit "name" attribute). */ |
| 2667 | - $attr = $token['attr']; |
|
| 2668 | - $attr[] = array('name' => 'name', 'value' => 'isindex'); |
|
| 2667 | + $attr = $token[ 'attr' ]; |
|
| 2668 | + $attr[ ] = array('name' => 'name', 'value' => 'isindex'); |
|
| 2669 | 2669 | |
| 2670 | 2670 | $this->inBody( |
| 2671 | 2671 | array( |
@@ -2678,7 +2678,7 @@ discard block |
||
| 2678 | 2678 | /* Act as if a stream of character tokens had been seen |
| 2679 | 2679 | (see below for what they should say). */ |
| 2680 | 2680 | $this->insertText( |
| 2681 | - 'This is a searchable index. ' . |
|
| 2681 | + 'This is a searchable index. '. |
|
| 2682 | 2682 | 'Insert your search keywords here: ' |
| 2683 | 2683 | ); |
| 2684 | 2684 | |
@@ -2798,13 +2798,13 @@ discard block |
||
| 2798 | 2798 | break; |
| 2799 | 2799 | |
| 2800 | 2800 | case HTML5::ENDTAG: |
| 2801 | - switch ($token['name']) { |
|
| 2801 | + switch ($token[ 'name' ]) { |
|
| 2802 | 2802 | /* An end tag with the tag name "body" */ |
| 2803 | 2803 | case 'body': |
| 2804 | 2804 | /* If the second element in the stack of open elements is |
| 2805 | 2805 | not a body element, this is a parse error. Ignore the token. |
| 2806 | 2806 | (innerHTML case) */ |
| 2807 | - if (count($this->stack) < 2 || $this->stack[1]->nodeName !== 'body') { |
|
| 2807 | + if (count($this->stack) < 2 || $this->stack[ 1 ]->nodeName !== 'body') { |
|
| 2808 | 2808 | // Ignore. |
| 2809 | 2809 | |
| 2810 | 2810 | /* If the current node is not the body element, then this |
@@ -2850,7 +2850,7 @@ discard block |
||
| 2850 | 2850 | /* If the stack of open elements has an element in scope |
| 2851 | 2851 | with the same tag name as that of the token, then generate |
| 2852 | 2852 | implied end tags. */ |
| 2853 | - if ($this->elementInScope($token['name'])) { |
|
| 2853 | + if ($this->elementInScope($token[ 'name' ])) { |
|
| 2854 | 2854 | $this->generateImpliedEndTags(); |
| 2855 | 2855 | |
| 2856 | 2856 | /* Now, if the current node is not an element with |
@@ -2863,7 +2863,7 @@ discard block |
||
| 2863 | 2863 | then pop elements from this stack until an element |
| 2864 | 2864 | with that tag name has been popped from the stack. */ |
| 2865 | 2865 | for ($n = count($this->stack) - 1; $n >= 0; $n--) { |
| 2866 | - if ($this->stack[$n]->nodeName === $token['name']) { |
|
| 2866 | + if ($this->stack[ $n ]->nodeName === $token[ 'name' ]) { |
|
| 2867 | 2867 | $n = -1; |
| 2868 | 2868 | } |
| 2869 | 2869 | |
@@ -2877,12 +2877,12 @@ discard block |
||
| 2877 | 2877 | /* If the stack of open elements has an element in scope |
| 2878 | 2878 | with the same tag name as that of the token, then generate |
| 2879 | 2879 | implied end tags. */ |
| 2880 | - if ($this->elementInScope($token['name'])) { |
|
| 2880 | + if ($this->elementInScope($token[ 'name' ])) { |
|
| 2881 | 2881 | $this->generateImpliedEndTags(); |
| 2882 | 2882 | |
| 2883 | 2883 | } |
| 2884 | 2884 | |
| 2885 | - if (end($this->stack)->nodeName !== $token['name']) { |
|
| 2885 | + if (end($this->stack)->nodeName !== $token[ 'name' ]) { |
|
| 2886 | 2886 | /* Now, if the current node is not an element with the |
| 2887 | 2887 | same tag name as that of the token, then this is a parse |
| 2888 | 2888 | error. */ |
@@ -2932,8 +2932,8 @@ discard block |
||
| 2932 | 2932 | whose tag name matches the tag name of the token, then |
| 2933 | 2933 | generate implied end tags, except for elements with the |
| 2934 | 2934 | same tag name as the token. */ |
| 2935 | - if ($this->elementInScope($token['name'])) { |
|
| 2936 | - $this->generateImpliedEndTags(array($token['name'])); |
|
| 2935 | + if ($this->elementInScope($token[ 'name' ])) { |
|
| 2936 | + $this->generateImpliedEndTags(array($token[ 'name' ])); |
|
| 2937 | 2937 | |
| 2938 | 2938 | /* If the current node is not an element with the same |
| 2939 | 2939 | tag name as the token, then this is a parse error. */ |
@@ -2944,7 +2944,7 @@ discard block |
||
| 2944 | 2944 | pop elements from this stack until an element with that |
| 2945 | 2945 | tag name has been popped from the stack. */ |
| 2946 | 2946 | for ($n = count($this->stack) - 1; $n >= 0; $n--) { |
| 2947 | - if ($this->stack[$n]->nodeName === $token['name']) { |
|
| 2947 | + if ($this->stack[ $n ]->nodeName === $token[ 'name' ]) { |
|
| 2948 | 2948 | $n = -1; |
| 2949 | 2949 | } |
| 2950 | 2950 | |
@@ -3007,11 +3007,11 @@ discard block |
||
| 3007 | 3007 | */ |
| 3008 | 3008 | while (true) { |
| 3009 | 3009 | for ($a = count($this->a_formatting) - 1; $a >= 0; $a--) { |
| 3010 | - if ($this->a_formatting[$a] === self::MARKER) { |
|
| 3010 | + if ($this->a_formatting[ $a ] === self::MARKER) { |
|
| 3011 | 3011 | break; |
| 3012 | 3012 | |
| 3013 | - } elseif ($this->a_formatting[$a]->tagName === $token['name']) { |
|
| 3014 | - $formatting_element = $this->a_formatting[$a]; |
|
| 3013 | + } elseif ($this->a_formatting[ $a ]->tagName === $token[ 'name' ]) { |
|
| 3014 | + $formatting_element = $this->a_formatting[ $a ]; |
|
| 3015 | 3015 | $in_stack = in_array($formatting_element, $this->stack, true); |
| 3016 | 3016 | $fe_af_pos = $a; |
| 3017 | 3017 | break; |
@@ -3023,7 +3023,7 @@ discard block |
||
| 3023 | 3023 | is not in scope, then this is a parse error. Abort |
| 3024 | 3024 | these steps. The token is ignored. */ |
| 3025 | 3025 | if (!isset($formatting_element) || ($in_stack && |
| 3026 | - !$this->elementInScope($token['name'])) |
|
| 3026 | + !$this->elementInScope($token[ 'name' ])) |
|
| 3027 | 3027 | ) { |
| 3028 | 3028 | break; |
| 3029 | 3029 | |
@@ -3032,7 +3032,7 @@ discard block |
||
| 3032 | 3032 | parse error; remove the element from the list, and |
| 3033 | 3033 | abort these steps. */ |
| 3034 | 3034 | } elseif (isset($formatting_element) && !$in_stack) { |
| 3035 | - unset($this->a_formatting[$fe_af_pos]); |
|
| 3035 | + unset($this->a_formatting[ $fe_af_pos ]); |
|
| 3036 | 3036 | $this->a_formatting = array_merge($this->a_formatting); |
| 3037 | 3037 | break; |
| 3038 | 3038 | } |
@@ -3046,10 +3046,10 @@ discard block |
||
| 3046 | 3046 | $length = count($this->stack); |
| 3047 | 3047 | |
| 3048 | 3048 | for ($s = $fe_s_pos + 1; $s < $length; $s++) { |
| 3049 | - $category = $this->getElementCategory($this->stack[$s]->nodeName); |
|
| 3049 | + $category = $this->getElementCategory($this->stack[ $s ]->nodeName); |
|
| 3050 | 3050 | |
| 3051 | 3051 | if ($category !== self::PHRASING && $category !== self::FORMATTING) { |
| 3052 | - $furthest_block = $this->stack[$s]; |
|
| 3052 | + $furthest_block = $this->stack[ $s ]; |
|
| 3053 | 3053 | } |
| 3054 | 3054 | } |
| 3055 | 3055 | |
@@ -3064,7 +3064,7 @@ discard block |
||
| 3064 | 3064 | array_pop($this->stack); |
| 3065 | 3065 | } |
| 3066 | 3066 | |
| 3067 | - unset($this->a_formatting[$fe_af_pos]); |
|
| 3067 | + unset($this->a_formatting[ $fe_af_pos ]); |
|
| 3068 | 3068 | $this->a_formatting = array_merge($this->a_formatting); |
| 3069 | 3069 | break; |
| 3070 | 3070 | } |
@@ -3072,7 +3072,7 @@ discard block |
||
| 3072 | 3072 | /* 4. Let the common ancestor be the element |
| 3073 | 3073 | immediately above the formatting element in the stack |
| 3074 | 3074 | of open elements. */ |
| 3075 | - $common_ancestor = $this->stack[$fe_s_pos - 1]; |
|
| 3075 | + $common_ancestor = $this->stack[ $fe_s_pos - 1 ]; |
|
| 3076 | 3076 | |
| 3077 | 3077 | /* 5. If the furthest block has a parent node, then |
| 3078 | 3078 | remove the furthest block from its parent node. */ |
@@ -3095,14 +3095,14 @@ discard block |
||
| 3095 | 3095 | for ($n = array_search($node, $this->stack, true) - 1; $n >= 0; $n--) { |
| 3096 | 3096 | /* 7.1 Let node be the element immediately |
| 3097 | 3097 | prior to node in the stack of open elements. */ |
| 3098 | - $node = $this->stack[$n]; |
|
| 3098 | + $node = $this->stack[ $n ]; |
|
| 3099 | 3099 | |
| 3100 | 3100 | /* 7.2 If node is not in the list of active |
| 3101 | 3101 | formatting elements, then remove node from |
| 3102 | 3102 | the stack of open elements and then go back |
| 3103 | 3103 | to step 1. */ |
| 3104 | 3104 | if (!in_array($node, $this->a_formatting, true)) { |
| 3105 | - unset($this->stack[$n]); |
|
| 3105 | + unset($this->stack[ $n ]); |
|
| 3106 | 3106 | $this->stack = array_merge($this->stack); |
| 3107 | 3107 | |
| 3108 | 3108 | } else { |
@@ -3135,8 +3135,8 @@ discard block |
||
| 3135 | 3135 | $s_pos = array_search($node, $this->stack, true); |
| 3136 | 3136 | $a_pos = array_search($node, $this->a_formatting, true); |
| 3137 | 3137 | |
| 3138 | - $this->stack[$s_pos] = $clone; |
|
| 3139 | - $this->a_formatting[$a_pos] = $clone; |
|
| 3138 | + $this->stack[ $s_pos ] = $clone; |
|
| 3139 | + $this->a_formatting[ $a_pos ] = $clone; |
|
| 3140 | 3140 | $node = $clone; |
| 3141 | 3141 | } |
| 3142 | 3142 | |
@@ -3183,7 +3183,7 @@ discard block |
||
| 3183 | 3183 | into the list of active formatting elements at the |
| 3184 | 3184 | position of the aforementioned bookmark. */ |
| 3185 | 3185 | $fe_af_pos = array_search($formatting_element, $this->a_formatting, true); |
| 3186 | - unset($this->a_formatting[$fe_af_pos]); |
|
| 3186 | + unset($this->a_formatting[ $fe_af_pos ]); |
|
| 3187 | 3187 | $this->a_formatting = array_merge($this->a_formatting); |
| 3188 | 3188 | |
| 3189 | 3189 | $af_part1 = array_slice($this->a_formatting, 0, $bookmark - 1); |
@@ -3197,7 +3197,7 @@ discard block |
||
| 3197 | 3197 | furthest block in that stack. */ |
| 3198 | 3198 | $fe_s_pos = array_search($formatting_element, $this->stack, true); |
| 3199 | 3199 | $fb_s_pos = array_search($furthest_block, $this->stack, true); |
| 3200 | - unset($this->stack[$fe_s_pos]); |
|
| 3200 | + unset($this->stack[ $fe_s_pos ]); |
|
| 3201 | 3201 | |
| 3202 | 3202 | $s_part1 = array_slice($this->stack, 0, $fb_s_pos); |
| 3203 | 3203 | $s_part2 = array_slice($this->stack, $fb_s_pos + 1, count($this->stack)); |
@@ -3216,7 +3216,7 @@ discard block |
||
| 3216 | 3216 | /* If the stack of open elements has an element in scope whose |
| 3217 | 3217 | tag name matches the tag name of the token, then generate implied |
| 3218 | 3218 | tags. */ |
| 3219 | - if ($this->elementInScope($token['name'])) { |
|
| 3219 | + if ($this->elementInScope($token[ 'name' ])) { |
|
| 3220 | 3220 | $this->generateImpliedEndTags(); |
| 3221 | 3221 | |
| 3222 | 3222 | /* Now, if the current node is not an element with the same |
@@ -3229,7 +3229,7 @@ discard block |
||
| 3229 | 3229 | the stack, and clear the list of active formatting elements up |
| 3230 | 3230 | to the last marker. */ |
| 3231 | 3231 | for ($n = count($this->stack) - 1; $n >= 0; $n--) { |
| 3232 | - if ($this->stack[$n]->nodeName === $token['name']) { |
|
| 3232 | + if ($this->stack[ $n ]->nodeName === $token[ 'name' ]) { |
|
| 3233 | 3233 | $n = -1; |
| 3234 | 3234 | } |
| 3235 | 3235 | |
@@ -3279,7 +3279,7 @@ discard block |
||
| 3279 | 3279 | |
| 3280 | 3280 | /* If node has the same tag name as the end tag token, |
| 3281 | 3281 | then: */ |
| 3282 | - if ($token['name'] === $node->nodeName) { |
|
| 3282 | + if ($token[ 'name' ] === $node->nodeName) { |
|
| 3283 | 3283 | /* Generate implied end tags. */ |
| 3284 | 3284 | $this->generateImpliedEndTags(); |
| 3285 | 3285 | |
@@ -3319,30 +3319,30 @@ discard block |
||
| 3319 | 3319 | /* A character token that is one of one of U+0009 CHARACTER TABULATION, |
| 3320 | 3320 | U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF), |
| 3321 | 3321 | or U+0020 SPACE */ |
| 3322 | - if ($token['type'] === HTML5::CHARACTR && |
|
| 3323 | - preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data']) |
|
| 3322 | + if ($token[ 'type' ] === HTML5::CHARACTR && |
|
| 3323 | + preg_match('/^[\t\n\x0b\x0c ]+$/', $token[ 'data' ]) |
|
| 3324 | 3324 | ) { |
| 3325 | 3325 | /* Append the character to the current node. */ |
| 3326 | - $text = $this->dom->createTextNode($token['data']); |
|
| 3326 | + $text = $this->dom->createTextNode($token[ 'data' ]); |
|
| 3327 | 3327 | end($this->stack)->appendChild($text); |
| 3328 | 3328 | |
| 3329 | 3329 | /* A comment token */ |
| 3330 | - } elseif ($token['type'] === HTML5::COMMENT) { |
|
| 3330 | + } elseif ($token[ 'type' ] === HTML5::COMMENT) { |
|
| 3331 | 3331 | /* Append a Comment node to the current node with the data |
| 3332 | 3332 | attribute set to the data given in the comment token. */ |
| 3333 | - $comment = $this->dom->createComment($token['data']); |
|
| 3333 | + $comment = $this->dom->createComment($token[ 'data' ]); |
|
| 3334 | 3334 | end($this->stack)->appendChild($comment); |
| 3335 | 3335 | |
| 3336 | 3336 | /* A start tag whose tag name is "caption" */ |
| 3337 | - } elseif ($token['type'] === HTML5::STARTTAG && |
|
| 3338 | - $token['name'] === 'caption' |
|
| 3337 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && |
|
| 3338 | + $token[ 'name' ] === 'caption' |
|
| 3339 | 3339 | ) { |
| 3340 | 3340 | /* Clear the stack back to a table context. */ |
| 3341 | 3341 | $this->clearStackToTableContext($clear); |
| 3342 | 3342 | |
| 3343 | 3343 | /* Insert a marker at the end of the list of active |
| 3344 | 3344 | formatting elements. */ |
| 3345 | - $this->a_formatting[] = self::MARKER; |
|
| 3345 | + $this->a_formatting[ ] = self::MARKER; |
|
| 3346 | 3346 | |
| 3347 | 3347 | /* Insert an HTML element for the token, then switch the |
| 3348 | 3348 | insertion mode to "in caption". */ |
@@ -3350,8 +3350,8 @@ discard block |
||
| 3350 | 3350 | $this->mode = self::IN_CAPTION; |
| 3351 | 3351 | |
| 3352 | 3352 | /* A start tag whose tag name is "colgroup" */ |
| 3353 | - } elseif ($token['type'] === HTML5::STARTTAG && |
|
| 3354 | - $token['name'] === 'colgroup' |
|
| 3353 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && |
|
| 3354 | + $token[ 'name' ] === 'colgroup' |
|
| 3355 | 3355 | ) { |
| 3356 | 3356 | /* Clear the stack back to a table context. */ |
| 3357 | 3357 | $this->clearStackToTableContext($clear); |
@@ -3362,8 +3362,8 @@ discard block |
||
| 3362 | 3362 | $this->mode = self::IN_CGROUP; |
| 3363 | 3363 | |
| 3364 | 3364 | /* A start tag whose tag name is "col" */ |
| 3365 | - } elseif ($token['type'] === HTML5::STARTTAG && |
|
| 3366 | - $token['name'] === 'col' |
|
| 3365 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && |
|
| 3366 | + $token[ 'name' ] === 'col' |
|
| 3367 | 3367 | ) { |
| 3368 | 3368 | $this->inTable( |
| 3369 | 3369 | array( |
@@ -3376,8 +3376,8 @@ discard block |
||
| 3376 | 3376 | $this->inColumnGroup($token); |
| 3377 | 3377 | |
| 3378 | 3378 | /* A start tag whose tag name is one of: "tbody", "tfoot", "thead" */ |
| 3379 | - } elseif ($token['type'] === HTML5::STARTTAG && in_array( |
|
| 3380 | - $token['name'], |
|
| 3379 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && in_array( |
|
| 3380 | + $token[ 'name' ], |
|
| 3381 | 3381 | array('tbody', 'tfoot', 'thead') |
| 3382 | 3382 | ) |
| 3383 | 3383 | ) { |
@@ -3390,8 +3390,8 @@ discard block |
||
| 3390 | 3390 | $this->mode = self::IN_TBODY; |
| 3391 | 3391 | |
| 3392 | 3392 | /* A start tag whose tag name is one of: "td", "th", "tr" */ |
| 3393 | - } elseif ($token['type'] === HTML5::STARTTAG && |
|
| 3394 | - in_array($token['name'], array('td', 'th', 'tr')) |
|
| 3393 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && |
|
| 3394 | + in_array($token[ 'name' ], array('td', 'th', 'tr')) |
|
| 3395 | 3395 | ) { |
| 3396 | 3396 | /* Act as if a start tag token with the tag name "tbody" had been |
| 3397 | 3397 | seen, then reprocess the current token. */ |
@@ -3406,8 +3406,8 @@ discard block |
||
| 3406 | 3406 | return $this->inTableBody($token); |
| 3407 | 3407 | |
| 3408 | 3408 | /* A start tag whose tag name is "table" */ |
| 3409 | - } elseif ($token['type'] === HTML5::STARTTAG && |
|
| 3410 | - $token['name'] === 'table' |
|
| 3409 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && |
|
| 3410 | + $token[ 'name' ] === 'table' |
|
| 3411 | 3411 | ) { |
| 3412 | 3412 | /* Parse error. Act as if an end tag token with the tag name "table" |
| 3413 | 3413 | had been seen, then, if that token wasn't ignored, reprocess the |
@@ -3422,13 +3422,13 @@ discard block |
||
| 3422 | 3422 | return $this->mainPhase($token); |
| 3423 | 3423 | |
| 3424 | 3424 | /* An end tag whose tag name is "table" */ |
| 3425 | - } elseif ($token['type'] === HTML5::ENDTAG && |
|
| 3426 | - $token['name'] === 'table' |
|
| 3425 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG && |
|
| 3426 | + $token[ 'name' ] === 'table' |
|
| 3427 | 3427 | ) { |
| 3428 | 3428 | /* If the stack of open elements does not have an element in table |
| 3429 | 3429 | scope with the same tag name as the token, this is a parse error. |
| 3430 | 3430 | Ignore the token. (innerHTML case) */ |
| 3431 | - if (!$this->elementInScope($token['name'], true)) { |
|
| 3431 | + if (!$this->elementInScope($token[ 'name' ], true)) { |
|
| 3432 | 3432 | return false; |
| 3433 | 3433 | |
| 3434 | 3434 | /* Otherwise: */ |
@@ -3457,8 +3457,8 @@ discard block |
||
| 3457 | 3457 | |
| 3458 | 3458 | /* An end tag whose tag name is one of: "body", "caption", "col", |
| 3459 | 3459 | "colgroup", "html", "tbody", "td", "tfoot", "th", "thead", "tr" */ |
| 3460 | - } elseif ($token['type'] === HTML5::ENDTAG && in_array( |
|
| 3461 | - $token['name'], |
|
| 3460 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG && in_array( |
|
| 3461 | + $token[ 'name' ], |
|
| 3462 | 3462 | array( |
| 3463 | 3463 | 'body', |
| 3464 | 3464 | 'caption', |
@@ -3501,8 +3501,8 @@ discard block |
||
| 3501 | 3501 | element is the element before the last table element in the |
| 3502 | 3502 | stack of open elements. */ |
| 3503 | 3503 | for ($n = count($this->stack) - 1; $n >= 0; $n--) { |
| 3504 | - if ($this->stack[$n]->nodeName === 'table') { |
|
| 3505 | - $table = $this->stack[$n]; |
|
| 3504 | + if ($this->stack[ $n ]->nodeName === 'table') { |
|
| 3505 | + $table = $this->stack[ $n ]; |
|
| 3506 | 3506 | break; |
| 3507 | 3507 | } |
| 3508 | 3508 | } |
@@ -3511,12 +3511,12 @@ discard block |
||
| 3511 | 3511 | $this->foster_parent = $table->parentNode; |
| 3512 | 3512 | |
| 3513 | 3513 | } elseif (!isset($table)) { |
| 3514 | - $this->foster_parent = $this->stack[0]; |
|
| 3514 | + $this->foster_parent = $this->stack[ 0 ]; |
|
| 3515 | 3515 | |
| 3516 | 3516 | } elseif (isset($table) && ($table->parentNode === null || |
| 3517 | 3517 | $table->parentNode->nodeType !== XML_ELEMENT_NODE) |
| 3518 | 3518 | ) { |
| 3519 | - $this->foster_parent = $this->stack[$n - 1]; |
|
| 3519 | + $this->foster_parent = $this->stack[ $n - 1 ]; |
|
| 3520 | 3520 | } |
| 3521 | 3521 | } |
| 3522 | 3522 | |
@@ -3527,11 +3527,11 @@ discard block |
||
| 3527 | 3527 | private function inCaption($token) |
| 3528 | 3528 | { |
| 3529 | 3529 | /* An end tag whose tag name is "caption" */ |
| 3530 | - if ($token['type'] === HTML5::ENDTAG && $token['name'] === 'caption') { |
|
| 3530 | + if ($token[ 'type' ] === HTML5::ENDTAG && $token[ 'name' ] === 'caption') { |
|
| 3531 | 3531 | /* If the stack of open elements does not have an element in table |
| 3532 | 3532 | scope with the same tag name as the token, this is a parse error. |
| 3533 | 3533 | Ignore the token. (innerHTML case) */ |
| 3534 | - if (!$this->elementInScope($token['name'], true)) { |
|
| 3534 | + if (!$this->elementInScope($token[ 'name' ], true)) { |
|
| 3535 | 3535 | // Ignore |
| 3536 | 3536 | |
| 3537 | 3537 | /* Otherwise: */ |
@@ -3565,8 +3565,8 @@ discard block |
||
| 3565 | 3565 | /* A start tag whose tag name is one of: "caption", "col", "colgroup", |
| 3566 | 3566 | "tbody", "td", "tfoot", "th", "thead", "tr", or an end tag whose tag |
| 3567 | 3567 | name is "table" */ |
| 3568 | - } elseif (($token['type'] === HTML5::STARTTAG && in_array( |
|
| 3569 | - $token['name'], |
|
| 3568 | + } elseif (($token[ 'type' ] === HTML5::STARTTAG && in_array( |
|
| 3569 | + $token[ 'name' ], |
|
| 3570 | 3570 | array( |
| 3571 | 3571 | 'caption', |
| 3572 | 3572 | 'col', |
@@ -3578,8 +3578,8 @@ discard block |
||
| 3578 | 3578 | 'thead', |
| 3579 | 3579 | 'tr' |
| 3580 | 3580 | ) |
| 3581 | - )) || ($token['type'] === HTML5::ENDTAG && |
|
| 3582 | - $token['name'] === 'table') |
|
| 3581 | + )) || ($token[ 'type' ] === HTML5::ENDTAG && |
|
| 3582 | + $token[ 'name' ] === 'table') |
|
| 3583 | 3583 | ) { |
| 3584 | 3584 | /* Parse error. Act as if an end tag with the tag name "caption" |
| 3585 | 3585 | had been seen, then, if that token wasn't ignored, reprocess the |
@@ -3595,8 +3595,8 @@ discard block |
||
| 3595 | 3595 | |
| 3596 | 3596 | /* An end tag whose tag name is one of: "body", "col", "colgroup", |
| 3597 | 3597 | "html", "tbody", "td", "tfoot", "th", "thead", "tr" */ |
| 3598 | - } elseif ($token['type'] === HTML5::ENDTAG && in_array( |
|
| 3599 | - $token['name'], |
|
| 3598 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG && in_array( |
|
| 3599 | + $token[ 'name' ], |
|
| 3600 | 3600 | array( |
| 3601 | 3601 | 'body', |
| 3602 | 3602 | 'col', |
@@ -3624,30 +3624,30 @@ discard block |
||
| 3624 | 3624 | /* A character token that is one of one of U+0009 CHARACTER TABULATION, |
| 3625 | 3625 | U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF), |
| 3626 | 3626 | or U+0020 SPACE */ |
| 3627 | - if ($token['type'] === HTML5::CHARACTR && |
|
| 3628 | - preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data']) |
|
| 3627 | + if ($token[ 'type' ] === HTML5::CHARACTR && |
|
| 3628 | + preg_match('/^[\t\n\x0b\x0c ]+$/', $token[ 'data' ]) |
|
| 3629 | 3629 | ) { |
| 3630 | 3630 | /* Append the character to the current node. */ |
| 3631 | - $text = $this->dom->createTextNode($token['data']); |
|
| 3631 | + $text = $this->dom->createTextNode($token[ 'data' ]); |
|
| 3632 | 3632 | end($this->stack)->appendChild($text); |
| 3633 | 3633 | |
| 3634 | 3634 | /* A comment token */ |
| 3635 | - } elseif ($token['type'] === HTML5::COMMENT) { |
|
| 3635 | + } elseif ($token[ 'type' ] === HTML5::COMMENT) { |
|
| 3636 | 3636 | /* Append a Comment node to the current node with the data |
| 3637 | 3637 | attribute set to the data given in the comment token. */ |
| 3638 | - $comment = $this->dom->createComment($token['data']); |
|
| 3638 | + $comment = $this->dom->createComment($token[ 'data' ]); |
|
| 3639 | 3639 | end($this->stack)->appendChild($comment); |
| 3640 | 3640 | |
| 3641 | 3641 | /* A start tag whose tag name is "col" */ |
| 3642 | - } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'col') { |
|
| 3642 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && $token[ 'name' ] === 'col') { |
|
| 3643 | 3643 | /* Insert a col element for the token. Immediately pop the current |
| 3644 | 3644 | node off the stack of open elements. */ |
| 3645 | 3645 | $this->insertElement($token); |
| 3646 | 3646 | array_pop($this->stack); |
| 3647 | 3647 | |
| 3648 | 3648 | /* An end tag whose tag name is "colgroup" */ |
| 3649 | - } elseif ($token['type'] === HTML5::ENDTAG && |
|
| 3650 | - $token['name'] === 'colgroup' |
|
| 3649 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG && |
|
| 3650 | + $token[ 'name' ] === 'colgroup' |
|
| 3651 | 3651 | ) { |
| 3652 | 3652 | /* If the current node is the root html element, then this is a |
| 3653 | 3653 | parse error, ignore the token. (innerHTML case) */ |
@@ -3663,7 +3663,7 @@ discard block |
||
| 3663 | 3663 | } |
| 3664 | 3664 | |
| 3665 | 3665 | /* An end tag whose tag name is "col" */ |
| 3666 | - } elseif ($token['type'] === HTML5::ENDTAG && $token['name'] === 'col') { |
|
| 3666 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG && $token[ 'name' ] === 'col') { |
|
| 3667 | 3667 | /* Parse error. Ignore the token. */ |
| 3668 | 3668 | |
| 3669 | 3669 | /* Anything else */ |
@@ -3686,7 +3686,7 @@ discard block |
||
| 3686 | 3686 | $clear = array('tbody', 'tfoot', 'thead', 'html'); |
| 3687 | 3687 | |
| 3688 | 3688 | /* A start tag whose tag name is "tr" */ |
| 3689 | - if ($token['type'] === HTML5::STARTTAG && $token['name'] === 'tr') { |
|
| 3689 | + if ($token[ 'type' ] === HTML5::STARTTAG && $token[ 'name' ] === 'tr') { |
|
| 3690 | 3690 | /* Clear the stack back to a table body context. */ |
| 3691 | 3691 | $this->clearStackToTableContext($clear); |
| 3692 | 3692 | |
@@ -3696,8 +3696,8 @@ discard block |
||
| 3696 | 3696 | $this->mode = self::IN_ROW; |
| 3697 | 3697 | |
| 3698 | 3698 | /* A start tag whose tag name is one of: "th", "td" */ |
| 3699 | - } elseif ($token['type'] === HTML5::STARTTAG && |
|
| 3700 | - ($token['name'] === 'th' || $token['name'] === 'td') |
|
| 3699 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && |
|
| 3700 | + ($token[ 'name' ] === 'th' || $token[ 'name' ] === 'td') |
|
| 3701 | 3701 | ) { |
| 3702 | 3702 | /* Parse error. Act as if a start tag with the tag name "tr" had |
| 3703 | 3703 | been seen, then reprocess the current token. */ |
@@ -3712,13 +3712,13 @@ discard block |
||
| 3712 | 3712 | return $this->inRow($token); |
| 3713 | 3713 | |
| 3714 | 3714 | /* An end tag whose tag name is one of: "tbody", "tfoot", "thead" */ |
| 3715 | - } elseif ($token['type'] === HTML5::ENDTAG && |
|
| 3716 | - in_array($token['name'], array('tbody', 'tfoot', 'thead')) |
|
| 3715 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG && |
|
| 3716 | + in_array($token[ 'name' ], array('tbody', 'tfoot', 'thead')) |
|
| 3717 | 3717 | ) { |
| 3718 | 3718 | /* If the stack of open elements does not have an element in table |
| 3719 | 3719 | scope with the same tag name as the token, this is a parse error. |
| 3720 | 3720 | Ignore the token. */ |
| 3721 | - if (!$this->elementInScope($token['name'], true)) { |
|
| 3721 | + if (!$this->elementInScope($token[ 'name' ], true)) { |
|
| 3722 | 3722 | // Ignore |
| 3723 | 3723 | |
| 3724 | 3724 | /* Otherwise: */ |
@@ -3734,11 +3734,11 @@ discard block |
||
| 3734 | 3734 | |
| 3735 | 3735 | /* A start tag whose tag name is one of: "caption", "col", "colgroup", |
| 3736 | 3736 | "tbody", "tfoot", "thead", or an end tag whose tag name is "table" */ |
| 3737 | - } elseif (($token['type'] === HTML5::STARTTAG && in_array( |
|
| 3738 | - $token['name'], |
|
| 3737 | + } elseif (($token[ 'type' ] === HTML5::STARTTAG && in_array( |
|
| 3738 | + $token[ 'name' ], |
|
| 3739 | 3739 | array('caption', 'col', 'colgroup', 'tbody', 'tfoor', 'thead') |
| 3740 | 3740 | )) || |
| 3741 | - ($token['type'] === HTML5::STARTTAG && $token['name'] === 'table') |
|
| 3741 | + ($token[ 'type' ] === HTML5::STARTTAG && $token[ 'name' ] === 'table') |
|
| 3742 | 3742 | ) { |
| 3743 | 3743 | /* If the stack of open elements does not have a tbody, thead, or |
| 3744 | 3744 | tfoot element in table scope, this is a parse error. Ignore the |
@@ -3766,8 +3766,8 @@ discard block |
||
| 3766 | 3766 | |
| 3767 | 3767 | /* An end tag whose tag name is one of: "body", "caption", "col", |
| 3768 | 3768 | "colgroup", "html", "td", "th", "tr" */ |
| 3769 | - } elseif ($token['type'] === HTML5::ENDTAG && in_array( |
|
| 3770 | - $token['name'], |
|
| 3769 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG && in_array( |
|
| 3770 | + $token[ 'name' ], |
|
| 3771 | 3771 | array('body', 'caption', 'col', 'colgroup', 'html', 'td', 'th', 'tr') |
| 3772 | 3772 | ) |
| 3773 | 3773 | ) { |
@@ -3785,8 +3785,8 @@ discard block |
||
| 3785 | 3785 | $clear = array('tr', 'html'); |
| 3786 | 3786 | |
| 3787 | 3787 | /* A start tag whose tag name is one of: "th", "td" */ |
| 3788 | - if ($token['type'] === HTML5::STARTTAG && |
|
| 3789 | - ($token['name'] === 'th' || $token['name'] === 'td') |
|
| 3788 | + if ($token[ 'type' ] === HTML5::STARTTAG && |
|
| 3789 | + ($token[ 'name' ] === 'th' || $token[ 'name' ] === 'td') |
|
| 3790 | 3790 | ) { |
| 3791 | 3791 | /* Clear the stack back to a table row context. */ |
| 3792 | 3792 | $this->clearStackToTableContext($clear); |
@@ -3798,14 +3798,14 @@ discard block |
||
| 3798 | 3798 | |
| 3799 | 3799 | /* Insert a marker at the end of the list of active formatting |
| 3800 | 3800 | elements. */ |
| 3801 | - $this->a_formatting[] = self::MARKER; |
|
| 3801 | + $this->a_formatting[ ] = self::MARKER; |
|
| 3802 | 3802 | |
| 3803 | 3803 | /* An end tag whose tag name is "tr" */ |
| 3804 | - } elseif ($token['type'] === HTML5::ENDTAG && $token['name'] === 'tr') { |
|
| 3804 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG && $token[ 'name' ] === 'tr') { |
|
| 3805 | 3805 | /* If the stack of open elements does not have an element in table |
| 3806 | 3806 | scope with the same tag name as the token, this is a parse error. |
| 3807 | 3807 | Ignore the token. (innerHTML case) */ |
| 3808 | - if (!$this->elementInScope($token['name'], true)) { |
|
| 3808 | + if (!$this->elementInScope($token[ 'name' ], true)) { |
|
| 3809 | 3809 | // Ignore. |
| 3810 | 3810 | |
| 3811 | 3811 | /* Otherwise: */ |
@@ -3822,8 +3822,8 @@ discard block |
||
| 3822 | 3822 | |
| 3823 | 3823 | /* A start tag whose tag name is one of: "caption", "col", "colgroup", |
| 3824 | 3824 | "tbody", "tfoot", "thead", "tr" or an end tag whose tag name is "table" */ |
| 3825 | - } elseif ($token['type'] === HTML5::STARTTAG && in_array( |
|
| 3826 | - $token['name'], |
|
| 3825 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && in_array( |
|
| 3826 | + $token[ 'name' ], |
|
| 3827 | 3827 | array('caption', 'col', 'colgroup', 'tbody', 'tfoot', 'thead', 'tr') |
| 3828 | 3828 | ) |
| 3829 | 3829 | ) { |
@@ -3839,13 +3839,13 @@ discard block |
||
| 3839 | 3839 | return $this->inCell($token); |
| 3840 | 3840 | |
| 3841 | 3841 | /* An end tag whose tag name is one of: "tbody", "tfoot", "thead" */ |
| 3842 | - } elseif ($token['type'] === HTML5::ENDTAG && |
|
| 3843 | - in_array($token['name'], array('tbody', 'tfoot', 'thead')) |
|
| 3842 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG && |
|
| 3843 | + in_array($token[ 'name' ], array('tbody', 'tfoot', 'thead')) |
|
| 3844 | 3844 | ) { |
| 3845 | 3845 | /* If the stack of open elements does not have an element in table |
| 3846 | 3846 | scope with the same tag name as the token, this is a parse error. |
| 3847 | 3847 | Ignore the token. */ |
| 3848 | - if (!$this->elementInScope($token['name'], true)) { |
|
| 3848 | + if (!$this->elementInScope($token[ 'name' ], true)) { |
|
| 3849 | 3849 | // Ignore. |
| 3850 | 3850 | |
| 3851 | 3851 | /* Otherwise: */ |
@@ -3864,8 +3864,8 @@ discard block |
||
| 3864 | 3864 | |
| 3865 | 3865 | /* An end tag whose tag name is one of: "body", "caption", "col", |
| 3866 | 3866 | "colgroup", "html", "td", "th" */ |
| 3867 | - } elseif ($token['type'] === HTML5::ENDTAG && in_array( |
|
| 3868 | - $token['name'], |
|
| 3867 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG && in_array( |
|
| 3868 | + $token[ 'name' ], |
|
| 3869 | 3869 | array('body', 'caption', 'col', 'colgroup', 'html', 'td', 'th', 'tr') |
| 3870 | 3870 | ) |
| 3871 | 3871 | ) { |
@@ -3881,20 +3881,20 @@ discard block |
||
| 3881 | 3881 | private function inCell($token) |
| 3882 | 3882 | { |
| 3883 | 3883 | /* An end tag whose tag name is one of: "td", "th" */ |
| 3884 | - if ($token['type'] === HTML5::ENDTAG && |
|
| 3885 | - ($token['name'] === 'td' || $token['name'] === 'th') |
|
| 3884 | + if ($token[ 'type' ] === HTML5::ENDTAG && |
|
| 3885 | + ($token[ 'name' ] === 'td' || $token[ 'name' ] === 'th') |
|
| 3886 | 3886 | ) { |
| 3887 | 3887 | /* If the stack of open elements does not have an element in table |
| 3888 | 3888 | scope with the same tag name as that of the token, then this is a |
| 3889 | 3889 | parse error and the token must be ignored. */ |
| 3890 | - if (!$this->elementInScope($token['name'], true)) { |
|
| 3890 | + if (!$this->elementInScope($token[ 'name' ], true)) { |
|
| 3891 | 3891 | // Ignore. |
| 3892 | 3892 | |
| 3893 | 3893 | /* Otherwise: */ |
| 3894 | 3894 | } else { |
| 3895 | 3895 | /* Generate implied end tags, except for elements with the same |
| 3896 | 3896 | tag name as the token. */ |
| 3897 | - $this->generateImpliedEndTags(array($token['name'])); |
|
| 3897 | + $this->generateImpliedEndTags(array($token[ 'name' ])); |
|
| 3898 | 3898 | |
| 3899 | 3899 | /* Now, if the current node is not an element with the same tag |
| 3900 | 3900 | name as the token, then this is a parse error. */ |
@@ -3906,7 +3906,7 @@ discard block |
||
| 3906 | 3906 | $node = end($this->stack)->nodeName; |
| 3907 | 3907 | array_pop($this->stack); |
| 3908 | 3908 | |
| 3909 | - if ($node === $token['name']) { |
|
| 3909 | + if ($node === $token[ 'name' ]) { |
|
| 3910 | 3910 | break; |
| 3911 | 3911 | } |
| 3912 | 3912 | } |
@@ -3922,8 +3922,8 @@ discard block |
||
| 3922 | 3922 | |
| 3923 | 3923 | /* A start tag whose tag name is one of: "caption", "col", "colgroup", |
| 3924 | 3924 | "tbody", "td", "tfoot", "th", "thead", "tr" */ |
| 3925 | - } elseif ($token['type'] === HTML5::STARTTAG && in_array( |
|
| 3926 | - $token['name'], |
|
| 3925 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && in_array( |
|
| 3926 | + $token[ 'name' ], |
|
| 3927 | 3927 | array( |
| 3928 | 3928 | 'caption', |
| 3929 | 3929 | 'col', |
@@ -3952,8 +3952,8 @@ discard block |
||
| 3952 | 3952 | |
| 3953 | 3953 | /* A start tag whose tag name is one of: "caption", "col", "colgroup", |
| 3954 | 3954 | "tbody", "td", "tfoot", "th", "thead", "tr" */ |
| 3955 | - } elseif ($token['type'] === HTML5::STARTTAG && in_array( |
|
| 3956 | - $token['name'], |
|
| 3955 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && in_array( |
|
| 3956 | + $token[ 'name' ], |
|
| 3957 | 3957 | array( |
| 3958 | 3958 | 'caption', |
| 3959 | 3959 | 'col', |
@@ -3982,8 +3982,8 @@ discard block |
||
| 3982 | 3982 | |
| 3983 | 3983 | /* An end tag whose tag name is one of: "body", "caption", "col", |
| 3984 | 3984 | "colgroup", "html" */ |
| 3985 | - } elseif ($token['type'] === HTML5::ENDTAG && in_array( |
|
| 3986 | - $token['name'], |
|
| 3985 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG && in_array( |
|
| 3986 | + $token[ 'name' ], |
|
| 3987 | 3987 | array('body', 'caption', 'col', 'colgroup', 'html') |
| 3988 | 3988 | ) |
| 3989 | 3989 | ) { |
@@ -3991,8 +3991,8 @@ discard block |
||
| 3991 | 3991 | |
| 3992 | 3992 | /* An end tag whose tag name is one of: "table", "tbody", "tfoot", |
| 3993 | 3993 | "thead", "tr" */ |
| 3994 | - } elseif ($token['type'] === HTML5::ENDTAG && in_array( |
|
| 3995 | - $token['name'], |
|
| 3994 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG && in_array( |
|
| 3995 | + $token[ 'name' ], |
|
| 3996 | 3996 | array('table', 'tbody', 'tfoot', 'thead', 'tr') |
| 3997 | 3997 | ) |
| 3998 | 3998 | ) { |
@@ -4000,7 +4000,7 @@ discard block |
||
| 4000 | 4000 | scope with the same tag name as that of the token (which can only |
| 4001 | 4001 | happen for "tbody", "tfoot" and "thead", or, in the innerHTML case), |
| 4002 | 4002 | then this is a parse error and the token must be ignored. */ |
| 4003 | - if (!$this->elementInScope($token['name'], true)) { |
|
| 4003 | + if (!$this->elementInScope($token[ 'name' ], true)) { |
|
| 4004 | 4004 | // Ignore. |
| 4005 | 4005 | |
| 4006 | 4006 | /* Otherwise, close the cell (see below) and reprocess the current |
@@ -4022,19 +4022,19 @@ discard block |
||
| 4022 | 4022 | /* Handle the token as follows: */ |
| 4023 | 4023 | |
| 4024 | 4024 | /* A character token */ |
| 4025 | - if ($token['type'] === HTML5::CHARACTR) { |
|
| 4025 | + if ($token[ 'type' ] === HTML5::CHARACTR) { |
|
| 4026 | 4026 | /* Append the token's character to the current node. */ |
| 4027 | - $this->insertText($token['data']); |
|
| 4027 | + $this->insertText($token[ 'data' ]); |
|
| 4028 | 4028 | |
| 4029 | 4029 | /* A comment token */ |
| 4030 | - } elseif ($token['type'] === HTML5::COMMENT) { |
|
| 4030 | + } elseif ($token[ 'type' ] === HTML5::COMMENT) { |
|
| 4031 | 4031 | /* Append a Comment node to the current node with the data |
| 4032 | 4032 | attribute set to the data given in the comment token. */ |
| 4033 | - $this->insertComment($token['data']); |
|
| 4033 | + $this->insertComment($token[ 'data' ]); |
|
| 4034 | 4034 | |
| 4035 | 4035 | /* A start tag token whose tag name is "option" */ |
| 4036 | - } elseif ($token['type'] === HTML5::STARTTAG && |
|
| 4037 | - $token['name'] === 'option' |
|
| 4036 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && |
|
| 4037 | + $token[ 'name' ] === 'option' |
|
| 4038 | 4038 | ) { |
| 4039 | 4039 | /* If the current node is an option element, act as if an end tag |
| 4040 | 4040 | with the tag name "option" had been seen. */ |
@@ -4051,8 +4051,8 @@ discard block |
||
| 4051 | 4051 | $this->insertElement($token); |
| 4052 | 4052 | |
| 4053 | 4053 | /* A start tag token whose tag name is "optgroup" */ |
| 4054 | - } elseif ($token['type'] === HTML5::STARTTAG && |
|
| 4055 | - $token['name'] === 'optgroup' |
|
| 4054 | + } elseif ($token[ 'type' ] === HTML5::STARTTAG && |
|
| 4055 | + $token[ 'name' ] === 'optgroup' |
|
| 4056 | 4056 | ) { |
| 4057 | 4057 | /* If the current node is an option element, act as if an end tag |
| 4058 | 4058 | with the tag name "option" had been seen. */ |
@@ -4080,8 +4080,8 @@ discard block |
||
| 4080 | 4080 | $this->insertElement($token); |
| 4081 | 4081 | |
| 4082 | 4082 | /* An end tag token whose tag name is "optgroup" */ |
| 4083 | - } elseif ($token['type'] === HTML5::ENDTAG && |
|
| 4084 | - $token['name'] === 'optgroup' |
|
| 4083 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG && |
|
| 4084 | + $token[ 'name' ] === 'optgroup' |
|
| 4085 | 4085 | ) { |
| 4086 | 4086 | /* First, if the current node is an option element, and the node |
| 4087 | 4087 | immediately before it in the stack of open elements is an optgroup |
@@ -4089,8 +4089,8 @@ discard block |
||
| 4089 | 4089 | been seen. */ |
| 4090 | 4090 | $elements_in_stack = count($this->stack); |
| 4091 | 4091 | |
| 4092 | - if ($this->stack[$elements_in_stack - 1]->nodeName === 'option' && |
|
| 4093 | - $this->stack[$elements_in_stack - 2]->nodeName === 'optgroup' |
|
| 4092 | + if ($this->stack[ $elements_in_stack - 1 ]->nodeName === 'option' && |
|
| 4093 | + $this->stack[ $elements_in_stack - 2 ]->nodeName === 'optgroup' |
|
| 4094 | 4094 | ) { |
| 4095 | 4095 | $this->inSelect( |
| 4096 | 4096 | array( |
@@ -4103,13 +4103,13 @@ discard block |
||
| 4103 | 4103 | /* If the current node is an optgroup element, then pop that node |
| 4104 | 4104 | from the stack of open elements. Otherwise, this is a parse error, |
| 4105 | 4105 | ignore the token. */ |
| 4106 | - if ($this->stack[$elements_in_stack - 1] === 'optgroup') { |
|
| 4106 | + if ($this->stack[ $elements_in_stack - 1 ] === 'optgroup') { |
|
| 4107 | 4107 | array_pop($this->stack); |
| 4108 | 4108 | } |
| 4109 | 4109 | |
| 4110 | 4110 | /* An end tag token whose tag name is "option" */ |
| 4111 | - } elseif ($token['type'] === HTML5::ENDTAG && |
|
| 4112 | - $token['name'] === 'option' |
|
| 4111 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG && |
|
| 4112 | + $token[ 'name' ] === 'option' |
|
| 4113 | 4113 | ) { |
| 4114 | 4114 | /* If the current node is an option element, then pop that node |
| 4115 | 4115 | from the stack of open elements. Otherwise, this is a parse error, |
@@ -4119,13 +4119,13 @@ discard block |
||
| 4119 | 4119 | } |
| 4120 | 4120 | |
| 4121 | 4121 | /* An end tag whose tag name is "select" */ |
| 4122 | - } elseif ($token['type'] === HTML5::ENDTAG && |
|
| 4123 | - $token['name'] === 'select' |
|
| 4122 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG && |
|
| 4123 | + $token[ 'name' ] === 'select' |
|
| 4124 | 4124 | ) { |
| 4125 | 4125 | /* If the stack of open elements does not have an element in table |
| 4126 | 4126 | scope with the same tag name as the token, this is a parse error. |
| 4127 | 4127 | Ignore the token. (innerHTML case) */ |
| 4128 | - if (!$this->elementInScope($token['name'], true)) { |
|
| 4128 | + if (!$this->elementInScope($token[ 'name' ], true)) { |
|
| 4129 | 4129 | // w/e |
| 4130 | 4130 | |
| 4131 | 4131 | /* Otherwise: */ |
@@ -4146,8 +4146,8 @@ discard block |
||
| 4146 | 4146 | } |
| 4147 | 4147 | |
| 4148 | 4148 | /* A start tag whose tag name is "select" */ |
| 4149 | - } elseif ($token['name'] === 'select' && |
|
| 4150 | - $token['type'] === HTML5::STARTTAG |
|
| 4149 | + } elseif ($token[ 'name' ] === 'select' && |
|
| 4150 | + $token[ 'type' ] === HTML5::STARTTAG |
|
| 4151 | 4151 | ) { |
| 4152 | 4152 | /* Parse error. Act as if the token had been an end tag with the |
| 4153 | 4153 | tag name "select" instead. */ |
@@ -4161,7 +4161,7 @@ discard block |
||
| 4161 | 4161 | /* An end tag whose tag name is one of: "caption", "table", "tbody", |
| 4162 | 4162 | "tfoot", "thead", "tr", "td", "th" */ |
| 4163 | 4163 | } elseif (in_array( |
| 4164 | - $token['name'], |
|
| 4164 | + $token[ 'name' ], |
|
| 4165 | 4165 | array( |
| 4166 | 4166 | 'caption', |
| 4167 | 4167 | 'table', |
@@ -4172,7 +4172,7 @@ discard block |
||
| 4172 | 4172 | 'td', |
| 4173 | 4173 | 'th' |
| 4174 | 4174 | ) |
| 4175 | - ) && $token['type'] === HTML5::ENDTAG |
|
| 4175 | + ) && $token[ 'type' ] === HTML5::ENDTAG |
|
| 4176 | 4176 | ) { |
| 4177 | 4177 | /* Parse error. */ |
| 4178 | 4178 | // w/e |
@@ -4181,7 +4181,7 @@ discard block |
||
| 4181 | 4181 | the same tag name as that of the token, then act as if an end tag |
| 4182 | 4182 | with the tag name "select" had been seen, and reprocess the token. |
| 4183 | 4183 | Otherwise, ignore the token. */ |
| 4184 | - if ($this->elementInScope($token['name'], true)) { |
|
| 4184 | + if ($this->elementInScope($token[ 'name' ], true)) { |
|
| 4185 | 4185 | $this->inSelect( |
| 4186 | 4186 | array( |
| 4187 | 4187 | 'name' => 'select', |
@@ -4205,23 +4205,23 @@ discard block |
||
| 4205 | 4205 | /* A character token that is one of one of U+0009 CHARACTER TABULATION, |
| 4206 | 4206 | U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF), |
| 4207 | 4207 | or U+0020 SPACE */ |
| 4208 | - if ($token['type'] === HTML5::CHARACTR && |
|
| 4209 | - preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data']) |
|
| 4208 | + if ($token[ 'type' ] === HTML5::CHARACTR && |
|
| 4209 | + preg_match('/^[\t\n\x0b\x0c ]+$/', $token[ 'data' ]) |
|
| 4210 | 4210 | ) { |
| 4211 | 4211 | /* Process the token as it would be processed if the insertion mode |
| 4212 | 4212 | was "in body". */ |
| 4213 | 4213 | $this->inBody($token); |
| 4214 | 4214 | |
| 4215 | 4215 | /* A comment token */ |
| 4216 | - } elseif ($token['type'] === HTML5::COMMENT) { |
|
| 4216 | + } elseif ($token[ 'type' ] === HTML5::COMMENT) { |
|
| 4217 | 4217 | /* Append a Comment node to the first element in the stack of open |
| 4218 | 4218 | elements (the html element), with the data attribute set to the |
| 4219 | 4219 | data given in the comment token. */ |
| 4220 | - $comment = $this->dom->createComment($token['data']); |
|
| 4221 | - $this->stack[0]->appendChild($comment); |
|
| 4220 | + $comment = $this->dom->createComment($token[ 'data' ]); |
|
| 4221 | + $this->stack[ 0 ]->appendChild($comment); |
|
| 4222 | 4222 | |
| 4223 | 4223 | /* An end tag with the tag name "html" */ |
| 4224 | - } elseif ($token['type'] === HTML5::ENDTAG && $token['name'] === 'html') { |
|
| 4224 | + } elseif ($token[ 'type' ] === HTML5::ENDTAG && $token[ 'name' ] === 'html') { |
|
| 4225 | 4225 | /* If the parser was originally created in order to handle the |
| 4226 | 4226 | setting of an element's innerHTML attribute, this is a parse error; |
| 4227 | 4227 | ignore the token. (The element will be an html element in this |
@@ -4246,27 +4246,27 @@ discard block |
||
| 4246 | 4246 | /* A character token that is one of one of U+0009 CHARACTER TABULATION, |
| 4247 | 4247 | U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF), |
| 4248 | 4248 | U+000D CARRIAGE RETURN (CR), or U+0020 SPACE */ |
| 4249 | - if ($token['type'] === HTML5::CHARACTR && |
|
| 4250 | - preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data']) |
|
| 4249 | + if ($token[ 'type' ] === HTML5::CHARACTR && |
|
| 4250 | + preg_match('/^[\t\n\x0b\x0c ]+$/', $token[ 'data' ]) |
|
| 4251 | 4251 | ) { |
| 4252 | 4252 | /* Append the character to the current node. */ |
| 4253 | - $this->insertText($token['data']); |
|
| 4253 | + $this->insertText($token[ 'data' ]); |
|
| 4254 | 4254 | |
| 4255 | 4255 | /* A comment token */ |
| 4256 | - } elseif ($token['type'] === HTML5::COMMENT) { |
|
| 4256 | + } elseif ($token[ 'type' ] === HTML5::COMMENT) { |
|
| 4257 | 4257 | /* Append a Comment node to the current node with the data |
| 4258 | 4258 | attribute set to the data given in the comment token. */ |
| 4259 | - $this->insertComment($token['data']); |
|
| 4259 | + $this->insertComment($token[ 'data' ]); |
|
| 4260 | 4260 | |
| 4261 | 4261 | /* A start tag with the tag name "frameset" */ |
| 4262 | - } elseif ($token['name'] === 'frameset' && |
|
| 4263 | - $token['type'] === HTML5::STARTTAG |
|
| 4262 | + } elseif ($token[ 'name' ] === 'frameset' && |
|
| 4263 | + $token[ 'type' ] === HTML5::STARTTAG |
|
| 4264 | 4264 | ) { |
| 4265 | 4265 | $this->insertElement($token); |
| 4266 | 4266 | |
| 4267 | 4267 | /* An end tag with the tag name "frameset" */ |
| 4268 | - } elseif ($token['name'] === 'frameset' && |
|
| 4269 | - $token['type'] === HTML5::ENDTAG |
|
| 4268 | + } elseif ($token[ 'name' ] === 'frameset' && |
|
| 4269 | + $token[ 'type' ] === HTML5::ENDTAG |
|
| 4270 | 4270 | ) { |
| 4271 | 4271 | /* If the current node is the root html element, then this is a |
| 4272 | 4272 | parse error; ignore the token. (innerHTML case) */ |
@@ -4286,8 +4286,8 @@ discard block |
||
| 4286 | 4286 | } |
| 4287 | 4287 | |
| 4288 | 4288 | /* A start tag with the tag name "frame" */ |
| 4289 | - } elseif ($token['name'] === 'frame' && |
|
| 4290 | - $token['type'] === HTML5::STARTTAG |
|
| 4289 | + } elseif ($token[ 'name' ] === 'frame' && |
|
| 4290 | + $token[ 'type' ] === HTML5::STARTTAG |
|
| 4291 | 4291 | ) { |
| 4292 | 4292 | /* Insert an HTML element for the token. */ |
| 4293 | 4293 | $this->insertElement($token); |
@@ -4296,8 +4296,8 @@ discard block |
||
| 4296 | 4296 | array_pop($this->stack); |
| 4297 | 4297 | |
| 4298 | 4298 | /* A start tag with the tag name "noframes" */ |
| 4299 | - } elseif ($token['name'] === 'noframes' && |
|
| 4300 | - $token['type'] === HTML5::STARTTAG |
|
| 4299 | + } elseif ($token[ 'name' ] === 'noframes' && |
|
| 4300 | + $token[ 'type' ] === HTML5::STARTTAG |
|
| 4301 | 4301 | ) { |
| 4302 | 4302 | /* Process the token as if the insertion mode had been "in body". */ |
| 4303 | 4303 | $this->inBody($token); |
@@ -4315,28 +4315,28 @@ discard block |
||
| 4315 | 4315 | /* A character token that is one of one of U+0009 CHARACTER TABULATION, |
| 4316 | 4316 | U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF), |
| 4317 | 4317 | U+000D CARRIAGE RETURN (CR), or U+0020 SPACE */ |
| 4318 | - if ($token['type'] === HTML5::CHARACTR && |
|
| 4319 | - preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data']) |
|
| 4318 | + if ($token[ 'type' ] === HTML5::CHARACTR && |
|
| 4319 | + preg_match('/^[\t\n\x0b\x0c ]+$/', $token[ 'data' ]) |
|
| 4320 | 4320 | ) { |
| 4321 | 4321 | /* Append the character to the current node. */ |
| 4322 | - $this->insertText($token['data']); |
|
| 4322 | + $this->insertText($token[ 'data' ]); |
|
| 4323 | 4323 | |
| 4324 | 4324 | /* A comment token */ |
| 4325 | - } elseif ($token['type'] === HTML5::COMMENT) { |
|
| 4325 | + } elseif ($token[ 'type' ] === HTML5::COMMENT) { |
|
| 4326 | 4326 | /* Append a Comment node to the current node with the data |
| 4327 | 4327 | attribute set to the data given in the comment token. */ |
| 4328 | - $this->insertComment($token['data']); |
|
| 4328 | + $this->insertComment($token[ 'data' ]); |
|
| 4329 | 4329 | |
| 4330 | 4330 | /* An end tag with the tag name "html" */ |
| 4331 | - } elseif ($token['name'] === 'html' && |
|
| 4332 | - $token['type'] === HTML5::ENDTAG |
|
| 4331 | + } elseif ($token[ 'name' ] === 'html' && |
|
| 4332 | + $token[ 'type' ] === HTML5::ENDTAG |
|
| 4333 | 4333 | ) { |
| 4334 | 4334 | /* Switch to the trailing end phase. */ |
| 4335 | 4335 | $this->phase = self::END_PHASE; |
| 4336 | 4336 | |
| 4337 | 4337 | /* A start tag with the tag name "noframes" */ |
| 4338 | - } elseif ($token['name'] === 'noframes' && |
|
| 4339 | - $token['type'] === HTML5::STARTTAG |
|
| 4338 | + } elseif ($token[ 'name' ] === 'noframes' && |
|
| 4339 | + $token[ 'type' ] === HTML5::STARTTAG |
|
| 4340 | 4340 | ) { |
| 4341 | 4341 | /* Process the token as if the insertion mode had been "in body". */ |
| 4342 | 4342 | $this->inBody($token); |
@@ -4353,21 +4353,21 @@ discard block |
||
| 4353 | 4353 | stage, it must be processed as described in this section. */ |
| 4354 | 4354 | |
| 4355 | 4355 | /* A DOCTYPE token */ |
| 4356 | - if ($token['type'] === HTML5::DOCTYPE) { |
|
| 4356 | + if ($token[ 'type' ] === HTML5::DOCTYPE) { |
|
| 4357 | 4357 | // Parse error. Ignore the token. |
| 4358 | 4358 | |
| 4359 | 4359 | /* A comment token */ |
| 4360 | - } elseif ($token['type'] === HTML5::COMMENT) { |
|
| 4360 | + } elseif ($token[ 'type' ] === HTML5::COMMENT) { |
|
| 4361 | 4361 | /* Append a Comment node to the Document object with the data |
| 4362 | 4362 | attribute set to the data given in the comment token. */ |
| 4363 | - $comment = $this->dom->createComment($token['data']); |
|
| 4363 | + $comment = $this->dom->createComment($token[ 'data' ]); |
|
| 4364 | 4364 | $this->dom->appendChild($comment); |
| 4365 | 4365 | |
| 4366 | 4366 | /* A character token that is one of one of U+0009 CHARACTER TABULATION, |
| 4367 | 4367 | U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF), |
| 4368 | 4368 | or U+0020 SPACE */ |
| 4369 | - } elseif ($token['type'] === HTML5::CHARACTR && |
|
| 4370 | - preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data']) |
|
| 4369 | + } elseif ($token[ 'type' ] === HTML5::CHARACTR && |
|
| 4370 | + preg_match('/^[\t\n\x0b\x0c ]+$/', $token[ 'data' ]) |
|
| 4371 | 4371 | ) { |
| 4372 | 4372 | /* Process the token as it would be processed in the main phase. */ |
| 4373 | 4373 | $this->mainPhase($token); |
@@ -4375,9 +4375,9 @@ discard block |
||
| 4375 | 4375 | /* A character token that is not one of U+0009 CHARACTER TABULATION, |
| 4376 | 4376 | U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF), |
| 4377 | 4377 | or U+0020 SPACE. Or a start tag token. Or an end tag token. */ |
| 4378 | - } elseif (($token['type'] === HTML5::CHARACTR && |
|
| 4379 | - preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) || |
|
| 4380 | - $token['type'] === HTML5::STARTTAG || $token['type'] === HTML5::ENDTAG |
|
| 4378 | + } elseif (($token[ 'type' ] === HTML5::CHARACTR && |
|
| 4379 | + preg_match('/^[\t\n\x0b\x0c ]+$/', $token[ 'data' ])) || |
|
| 4380 | + $token[ 'type' ] === HTML5::STARTTAG || $token[ 'type' ] === HTML5::ENDTAG |
|
| 4381 | 4381 | ) { |
| 4382 | 4382 | /* Parse error. Switch back to the main phase and reprocess the |
| 4383 | 4383 | token. */ |
@@ -4385,7 +4385,7 @@ discard block |
||
| 4385 | 4385 | return $this->mainPhase($token); |
| 4386 | 4386 | |
| 4387 | 4387 | /* An end-of-file token */ |
| 4388 | - } elseif ($token['type'] === HTML5::EOF) { |
|
| 4388 | + } elseif ($token[ 'type' ] === HTML5::EOF) { |
|
| 4389 | 4389 | /* OMG DONE!! */ |
| 4390 | 4390 | } |
| 4391 | 4391 | } |
@@ -4396,25 +4396,25 @@ discard block |
||
| 4396 | 4396 | if ($check) { |
| 4397 | 4397 | // Slightly modified HTML5 tag-name modification, |
| 4398 | 4398 | // removing anything that's not an ASCII letter, digit, or hyphen |
| 4399 | - $token['name'] = preg_replace('/[^a-z0-9-]/i', '', $token['name']); |
|
| 4399 | + $token[ 'name' ] = preg_replace('/[^a-z0-9-]/i', '', $token[ 'name' ]); |
|
| 4400 | 4400 | // Remove leading hyphens and numbers |
| 4401 | - $token['name'] = ltrim($token['name'], '-0..9'); |
|
| 4401 | + $token[ 'name' ] = ltrim($token[ 'name' ], '-0..9'); |
|
| 4402 | 4402 | // In theory, this should ever be needed, but just in case |
| 4403 | - if ($token['name'] === '') { |
|
| 4404 | - $token['name'] = 'span'; |
|
| 4403 | + if ($token[ 'name' ] === '') { |
|
| 4404 | + $token[ 'name' ] = 'span'; |
|
| 4405 | 4405 | } // arbitrary generic choice |
| 4406 | 4406 | } |
| 4407 | 4407 | |
| 4408 | - $el = $this->dom->createElement($token['name']); |
|
| 4408 | + $el = $this->dom->createElement($token[ 'name' ]); |
|
| 4409 | 4409 | |
| 4410 | - foreach ($token['attr'] as $attr) { |
|
| 4411 | - if (!$el->hasAttribute($attr['name'])) { |
|
| 4412 | - $el->setAttribute($attr['name'], $attr['value']); |
|
| 4410 | + foreach ($token[ 'attr' ] as $attr) { |
|
| 4411 | + if (!$el->hasAttribute($attr[ 'name' ])) { |
|
| 4412 | + $el->setAttribute($attr[ 'name' ], $attr[ 'value' ]); |
|
| 4413 | 4413 | } |
| 4414 | 4414 | } |
| 4415 | 4415 | |
| 4416 | 4416 | $this->appendToRealParent($el); |
| 4417 | - $this->stack[] = $el; |
|
| 4417 | + $this->stack[ ] = $el; |
|
| 4418 | 4418 | |
| 4419 | 4419 | return $el; |
| 4420 | 4420 | } |
@@ -4444,10 +4444,10 @@ discard block |
||
| 4444 | 4444 | otherwise, the new node must be appended to the foster parent |
| 4445 | 4445 | element. */ |
| 4446 | 4446 | for ($n = count($this->stack) - 1; $n >= 0; $n--) { |
| 4447 | - if ($this->stack[$n]->nodeName === 'table' && |
|
| 4448 | - $this->stack[$n]->parentNode !== null |
|
| 4447 | + if ($this->stack[ $n ]->nodeName === 'table' && |
|
| 4448 | + $this->stack[ $n ]->parentNode !== null |
|
| 4449 | 4449 | ) { |
| 4450 | - $table = $this->stack[$n]; |
|
| 4450 | + $table = $this->stack[ $n ]; |
|
| 4451 | 4451 | break; |
| 4452 | 4452 | } |
| 4453 | 4453 | } |
@@ -4479,7 +4479,7 @@ discard block |
||
| 4479 | 4479 | for ($n = 0; $n < $leng; $n++) { |
| 4480 | 4480 | /* 1. Initialise node to be the current node (the bottommost node of |
| 4481 | 4481 | the stack). */ |
| 4482 | - $node = $this->stack[$leng - 1 - $n]; |
|
| 4482 | + $node = $this->stack[ $leng - 1 - $n ]; |
|
| 4483 | 4483 | |
| 4484 | 4484 | if ($node->tagName === $el) { |
| 4485 | 4485 | /* 2. If node is the target node, terminate in a match state. */ |
@@ -4555,7 +4555,7 @@ discard block |
||
| 4555 | 4555 | /* 5. Let entry be the entry one earlier than entry in the list of |
| 4556 | 4556 | active formatting elements. */ |
| 4557 | 4557 | $a--; |
| 4558 | - $entry = $this->a_formatting[$a]; |
|
| 4558 | + $entry = $this->a_formatting[ $a ]; |
|
| 4559 | 4559 | |
| 4560 | 4560 | /* 6. If entry is neither a marker nor an element that is also in |
| 4561 | 4561 | thetack of open elements, go to step 4. */ |
@@ -4569,7 +4569,7 @@ discard block |
||
| 4569 | 4569 | active formatting elements. */ |
| 4570 | 4570 | if (isset($step_seven) && $step_seven === true) { |
| 4571 | 4571 | $a++; |
| 4572 | - $entry = $this->a_formatting[$a]; |
|
| 4572 | + $entry = $this->a_formatting[ $a ]; |
|
| 4573 | 4573 | } |
| 4574 | 4574 | |
| 4575 | 4575 | /* 8. Perform a shallow clone of the element entry to obtain clone. */ |
@@ -4578,11 +4578,11 @@ discard block |
||
| 4578 | 4578 | /* 9. Append clone to the current node and push it onto the stack |
| 4579 | 4579 | of open elements so that it is the new current node. */ |
| 4580 | 4580 | end($this->stack)->appendChild($clone); |
| 4581 | - $this->stack[] = $clone; |
|
| 4581 | + $this->stack[ ] = $clone; |
|
| 4582 | 4582 | |
| 4583 | 4583 | /* 10. Replace the entry for entry in the list with an entry for |
| 4584 | 4584 | clone. */ |
| 4585 | - $this->a_formatting[$a] = $clone; |
|
| 4585 | + $this->a_formatting[ $a ] = $clone; |
|
| 4586 | 4586 | |
| 4587 | 4587 | /* 11. If the entry for clone in the list of active formatting |
| 4588 | 4588 | elements is not the last entry in the list, return to step 7. */ |
@@ -4671,13 +4671,13 @@ discard block |
||
| 4671 | 4671 | |
| 4672 | 4672 | for ($n = $leng - 1; $n >= 0; $n--) { |
| 4673 | 4673 | /* 2. Let node be the last node in the stack of open elements. */ |
| 4674 | - $node = $this->stack[$n]; |
|
| 4674 | + $node = $this->stack[ $n ]; |
|
| 4675 | 4675 | |
| 4676 | 4676 | /* 3. If node is the first node in the stack of open elements, then |
| 4677 | 4677 | set last to true. If the element whose innerHTML attribute is being |
| 4678 | 4678 | set is neither a td element nor a th element, then set node to the |
| 4679 | 4679 | element whose innerHTML attribute is being set. (innerHTML case) */ |
| 4680 | - if ($this->stack[0]->isSameNode($node)) { |
|
| 4680 | + if ($this->stack[ 0 ]->isSameNode($node)) { |
|
| 4681 | 4681 | $last = true; |
| 4682 | 4682 | } |
| 4683 | 4683 | |
@@ -108,7 +108,7 @@ |
||
| 108 | 108 | /** |
| 109 | 109 | * Prints a simple key/value row in a table. |
| 110 | 110 | * @param string $name Key |
| 111 | - * @param mixed $value Value |
|
| 111 | + * @param string $value Value |
|
| 112 | 112 | * @return string |
| 113 | 113 | */ |
| 114 | 114 | protected function row($name, $value) |
@@ -77,8 +77,8 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | protected function element($tag, $contents, $attr = array(), $escape = true) |
| 79 | 79 | { |
| 80 | - return $this->start($tag, $attr) . |
|
| 81 | - ($escape ? $this->escape($contents) : $contents) . |
|
| 80 | + return $this->start($tag, $attr). |
|
| 81 | + ($escape ? $this->escape($contents) : $contents). |
|
| 82 | 82 | $this->end($tag); |
| 83 | 83 | } |
| 84 | 84 | |
@@ -117,9 +117,9 @@ discard block |
||
| 117 | 117 | $value = $value ? 'On' : 'Off'; |
| 118 | 118 | } |
| 119 | 119 | return |
| 120 | - $this->start('tr') . "\n" . |
|
| 121 | - $this->element('th', $name) . "\n" . |
|
| 122 | - $this->element('td', $value) . "\n" . |
|
| 120 | + $this->start('tr')."\n". |
|
| 121 | + $this->element('th', $name)."\n". |
|
| 122 | + $this->element('td', $value)."\n". |
|
| 123 | 123 | $this->end('tr'); |
| 124 | 124 | } |
| 125 | 125 | |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | if ($five === null) { |
| 174 | 174 | $five = version_compare(PHP_VERSION, '5', '>='); |
| 175 | 175 | } |
| 176 | - $prefix = 'HTMLPurifier_' . $sec_prefix; |
|
| 176 | + $prefix = 'HTMLPurifier_'.$sec_prefix; |
|
| 177 | 177 | if (!$five) { |
| 178 | 178 | $prefix = strtolower($prefix); |
| 179 | 179 | } |
@@ -184,23 +184,23 @@ discard block |
||
| 184 | 184 | case 'enum': |
| 185 | 185 | $values = array(); |
| 186 | 186 | foreach ($obj->valid_values as $value => $bool) { |
| 187 | - $values[] = $value; |
|
| 187 | + $values[ ] = $value; |
|
| 188 | 188 | } |
| 189 | 189 | $class .= implode(', ', $values); |
| 190 | 190 | break; |
| 191 | 191 | case 'css_composite': |
| 192 | 192 | $values = array(); |
| 193 | 193 | foreach ($obj->defs as $def) { |
| 194 | - $values[] = $this->getClass($def, $sec_prefix); |
|
| 194 | + $values[ ] = $this->getClass($def, $sec_prefix); |
|
| 195 | 195 | } |
| 196 | 196 | $class .= implode(', ', $values); |
| 197 | 197 | break; |
| 198 | 198 | case 'css_multiple': |
| 199 | - $class .= $this->getClass($obj->single, $sec_prefix) . ', '; |
|
| 199 | + $class .= $this->getClass($obj->single, $sec_prefix).', '; |
|
| 200 | 200 | $class .= $obj->max; |
| 201 | 201 | break; |
| 202 | 202 | case 'css_denyelementdecorator': |
| 203 | - $class .= $this->getClass($obj->def, $sec_prefix) . ', '; |
|
| 203 | + $class .= $this->getClass($obj->def, $sec_prefix).', '; |
|
| 204 | 204 | $class .= $obj->element; |
| 205 | 205 | break; |
| 206 | 206 | case 'css_importantdecorator': |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | 55 | * Sets default column and row size for textareas in sub-printers |
| 56 | - * @param $cols Integer columns of textarea, null to use default |
|
| 57 | - * @param $rows Integer rows of textarea, null to use default |
|
| 56 | + * @param integer $cols Integer columns of textarea, null to use default |
|
| 57 | + * @param integer $rows Integer rows of textarea, null to use default |
|
| 58 | 58 | */ |
| 59 | 59 | public function setTextareaDimensions($cols = null, $rows = null) |
| 60 | 60 | { |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | /** |
| 86 | 86 | * Returns HTML output for a configuration form |
| 87 | - * @param HTMLPurifier_Config|array $config Configuration object of current form state, or an array |
|
| 87 | + * @param HTMLPurifier_Config $config Configuration object of current form state, or an array |
|
| 88 | 88 | * where [0] has an HTML namespace and [1] is being rendered. |
| 89 | 89 | * @param array|bool $allowed Optional namespace(s) and directives to restrict form to. |
| 90 | 90 | * @param bool $render_controls |
@@ -47,8 +47,8 @@ discard block |
||
| 47 | 47 | $this->name = $name; |
| 48 | 48 | $this->compress = $compress; |
| 49 | 49 | // initialize sub-printers |
| 50 | - $this->fields[0] = new HTMLPurifier_Printer_ConfigForm_default(); |
|
| 51 | - $this->fields[HTMLPurifier_VarParser::BOOL] = new HTMLPurifier_Printer_ConfigForm_bool(); |
|
| 50 | + $this->fields[ 0 ] = new HTMLPurifier_Printer_ConfigForm_default(); |
|
| 51 | + $this->fields[ HTMLPurifier_VarParser::BOOL ] = new HTMLPurifier_Printer_ConfigForm_bool(); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | public function setTextareaDimensions($cols = null, $rows = null) |
| 60 | 60 | { |
| 61 | 61 | if ($cols) { |
| 62 | - $this->fields['default']->cols = $cols; |
|
| 62 | + $this->fields[ 'default' ]->cols = $cols; |
|
| 63 | 63 | } |
| 64 | 64 | if ($rows) { |
| 65 | - $this->fields['default']->rows = $rows; |
|
| 65 | + $this->fields[ 'default' ]->rows = $rows; |
|
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public static function getCSS() |
| 73 | 73 | { |
| 74 | - return file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/Printer/ConfigForm.css'); |
|
| 74 | + return file_get_contents(HTMLPURIFIER_PREFIX.'/HTMLPurifier/Printer/ConfigForm.css'); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | public static function getJavaScript() |
| 81 | 81 | { |
| 82 | - return file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/Printer/ConfigForm.js'); |
|
| 82 | + return file_get_contents(HTMLPURIFIER_PREFIX.'/HTMLPurifier/Printer/ConfigForm.js'); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -92,9 +92,9 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | public function render($config, $allowed = true, $render_controls = true) |
| 94 | 94 | { |
| 95 | - if (is_array($config) && isset($config[0])) { |
|
| 96 | - $gen_config = $config[0]; |
|
| 97 | - $config = $config[1]; |
|
| 95 | + if (is_array($config) && isset($config[ 0 ])) { |
|
| 96 | + $gen_config = $config[ 0 ]; |
|
| 97 | + $config = $config[ 1 ]; |
|
| 98 | 98 | } else { |
| 99 | 99 | $gen_config = $config; |
| 100 | 100 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | $all = array(); |
| 108 | 108 | foreach ($allowed as $key) { |
| 109 | 109 | list($ns, $directive) = $key; |
| 110 | - $all[$ns][$directive] = $config->get($ns . '.' . $directive); |
|
| 110 | + $all[ $ns ][ $directive ] = $config->get($ns.'.'.$directive); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | $ret = ''; |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | if (!$this->compress || (strlen($directive) < $this->compress)) { |
| 164 | 164 | $directive_disp = $directive; |
| 165 | 165 | } else { |
| 166 | - $directive_disp = substr($directive, 0, $this->compress - 2) . '...'; |
|
| 167 | - $attr['title'] = $directive; |
|
| 166 | + $directive_disp = substr($directive, 0, $this->compress - 2).'...'; |
|
| 167 | + $attr[ 'title' ] = $directive; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | $ret .= $this->element( |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | $ret .= $this->end('th'); |
| 180 | 180 | |
| 181 | 181 | $ret .= $this->start('td'); |
| 182 | - $def = $this->config->def->info["$ns.$directive"]; |
|
| 182 | + $def = $this->config->def->info[ "$ns.$directive" ]; |
|
| 183 | 183 | if (is_int($def)) { |
| 184 | 184 | $allow_null = $def < 0; |
| 185 | 185 | $type = abs($def); |
@@ -187,10 +187,10 @@ discard block |
||
| 187 | 187 | $type = $def->type; |
| 188 | 188 | $allow_null = isset($def->allow_null); |
| 189 | 189 | } |
| 190 | - if (!isset($this->fields[$type])) { |
|
| 190 | + if (!isset($this->fields[ $type ])) { |
|
| 191 | 191 | $type = 0; |
| 192 | 192 | } // default |
| 193 | - $type_obj = $this->fields[$type]; |
|
| 193 | + $type_obj = $this->fields[ $type ]; |
|
| 194 | 194 | if ($allow_null) { |
| 195 | 195 | $type_obj = new HTMLPurifier_Printer_ConfigForm_NullDecorator($type_obj); |
| 196 | 196 | } |
@@ -234,9 +234,9 @@ discard block |
||
| 234 | 234 | */ |
| 235 | 235 | public function render($ns, $directive, $value, $name, $config) |
| 236 | 236 | { |
| 237 | - if (is_array($config) && isset($config[0])) { |
|
| 238 | - $gen_config = $config[0]; |
|
| 239 | - $config = $config[1]; |
|
| 237 | + if (is_array($config) && isset($config[ 0 ])) { |
|
| 238 | + $gen_config = $config[ 0 ]; |
|
| 239 | + $config = $config[ 1 ]; |
|
| 240 | 240 | } else { |
| 241 | 241 | $gen_config = $config; |
| 242 | 242 | } |
@@ -251,18 +251,18 @@ discard block |
||
| 251 | 251 | 'type' => 'checkbox', |
| 252 | 252 | 'value' => '1', |
| 253 | 253 | 'class' => 'null-toggle', |
| 254 | - 'name' => "$name" . "[Null_$ns.$directive]", |
|
| 254 | + 'name' => "$name"."[Null_$ns.$directive]", |
|
| 255 | 255 | 'id' => "$name:Null_$ns.$directive", |
| 256 | 256 | 'onclick' => "toggleWriteability('$name:$ns.$directive',checked)" // INLINE JAVASCRIPT!!!! |
| 257 | 257 | ); |
| 258 | 258 | if ($this->obj instanceof HTMLPurifier_Printer_ConfigForm_bool) { |
| 259 | 259 | // modify inline javascript slightly |
| 260 | - $attr['onclick'] = |
|
| 261 | - "toggleWriteability('$name:Yes_$ns.$directive',checked);" . |
|
| 260 | + $attr[ 'onclick' ] = |
|
| 261 | + "toggleWriteability('$name:Yes_$ns.$directive',checked);". |
|
| 262 | 262 | "toggleWriteability('$name:No_$ns.$directive',checked)"; |
| 263 | 263 | } |
| 264 | 264 | if ($value === null) { |
| 265 | - $attr['checked'] = 'checked'; |
|
| 265 | + $attr[ 'checked' ] = 'checked'; |
|
| 266 | 266 | } |
| 267 | 267 | $ret .= $this->elementEmpty('input', $attr); |
| 268 | 268 | $ret .= $this->text(' or '); |
@@ -297,16 +297,16 @@ discard block |
||
| 297 | 297 | */ |
| 298 | 298 | public function render($ns, $directive, $value, $name, $config) |
| 299 | 299 | { |
| 300 | - if (is_array($config) && isset($config[0])) { |
|
| 301 | - $gen_config = $config[0]; |
|
| 302 | - $config = $config[1]; |
|
| 300 | + if (is_array($config) && isset($config[ 0 ])) { |
|
| 301 | + $gen_config = $config[ 0 ]; |
|
| 302 | + $config = $config[ 1 ]; |
|
| 303 | 303 | } else { |
| 304 | 304 | $gen_config = $config; |
| 305 | 305 | } |
| 306 | 306 | $this->prepareGenerator($gen_config); |
| 307 | 307 | // this should probably be split up a little |
| 308 | 308 | $ret = ''; |
| 309 | - $def = $config->def->info["$ns.$directive"]; |
|
| 309 | + $def = $config->def->info[ "$ns.$directive" ]; |
|
| 310 | 310 | if (is_int($def)) { |
| 311 | 311 | $type = abs($def); |
| 312 | 312 | } else { |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | $array = $value; |
| 319 | 319 | $value = array(); |
| 320 | 320 | foreach ($array as $val => $b) { |
| 321 | - $value[] = $val; |
|
| 321 | + $value[ ] = $val; |
|
| 322 | 322 | } |
| 323 | 323 | //TODO does this need a break? |
| 324 | 324 | case HTMLPurifier_VarParser::ALIST: |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | case HTMLPurifier_VarParser::HASH: |
| 328 | 328 | $nvalue = ''; |
| 329 | 329 | foreach ($value as $i => $v) { |
| 330 | - $nvalue .= "$i:$v" . PHP_EOL; |
|
| 330 | + $nvalue .= "$i:$v".PHP_EOL; |
|
| 331 | 331 | } |
| 332 | 332 | $value = $nvalue; |
| 333 | 333 | break; |
@@ -340,18 +340,18 @@ discard block |
||
| 340 | 340 | $value = serialize($value); |
| 341 | 341 | } |
| 342 | 342 | $attr = array( |
| 343 | - 'name' => "$name" . "[$ns.$directive]", |
|
| 343 | + 'name' => "$name"."[$ns.$directive]", |
|
| 344 | 344 | 'id' => "$name:$ns.$directive" |
| 345 | 345 | ); |
| 346 | 346 | if ($value === null) { |
| 347 | - $attr['disabled'] = 'disabled'; |
|
| 347 | + $attr[ 'disabled' ] = 'disabled'; |
|
| 348 | 348 | } |
| 349 | 349 | if (isset($def->allowed)) { |
| 350 | 350 | $ret .= $this->start('select', $attr); |
| 351 | 351 | foreach ($def->allowed as $val => $b) { |
| 352 | 352 | $attr = array(); |
| 353 | 353 | if ($value == $val) { |
| 354 | - $attr['selected'] = 'selected'; |
|
| 354 | + $attr[ 'selected' ] = 'selected'; |
|
| 355 | 355 | } |
| 356 | 356 | $ret .= $this->element('option', $val, $attr); |
| 357 | 357 | } |
@@ -361,14 +361,14 @@ discard block |
||
| 361 | 361 | $type === HTMLPurifier_VarParser::ALIST || |
| 362 | 362 | $type === HTMLPurifier_VarParser::HASH || |
| 363 | 363 | $type === HTMLPurifier_VarParser::LOOKUP) { |
| 364 | - $attr['cols'] = $this->cols; |
|
| 365 | - $attr['rows'] = $this->rows; |
|
| 364 | + $attr[ 'cols' ] = $this->cols; |
|
| 365 | + $attr[ 'rows' ] = $this->rows; |
|
| 366 | 366 | $ret .= $this->start('textarea', $attr); |
| 367 | 367 | $ret .= $this->text($value); |
| 368 | 368 | $ret .= $this->end('textarea'); |
| 369 | 369 | } else { |
| 370 | - $attr['value'] = $value; |
|
| 371 | - $attr['type'] = 'text'; |
|
| 370 | + $attr[ 'value' ] = $value; |
|
| 371 | + $attr[ 'type' ] = 'text'; |
|
| 372 | 372 | $ret .= $this->elementEmpty('input', $attr); |
| 373 | 373 | } |
| 374 | 374 | return $ret; |
@@ -390,9 +390,9 @@ discard block |
||
| 390 | 390 | */ |
| 391 | 391 | public function render($ns, $directive, $value, $name, $config) |
| 392 | 392 | { |
| 393 | - if (is_array($config) && isset($config[0])) { |
|
| 394 | - $gen_config = $config[0]; |
|
| 395 | - $config = $config[1]; |
|
| 393 | + if (is_array($config) && isset($config[ 0 ])) { |
|
| 394 | + $gen_config = $config[ 0 ]; |
|
| 395 | + $config = $config[ 1 ]; |
|
| 396 | 396 | } else { |
| 397 | 397 | $gen_config = $config; |
| 398 | 398 | } |
@@ -407,15 +407,15 @@ discard block |
||
| 407 | 407 | |
| 408 | 408 | $attr = array( |
| 409 | 409 | 'type' => 'radio', |
| 410 | - 'name' => "$name" . "[$ns.$directive]", |
|
| 410 | + 'name' => "$name"."[$ns.$directive]", |
|
| 411 | 411 | 'id' => "$name:Yes_$ns.$directive", |
| 412 | 412 | 'value' => '1' |
| 413 | 413 | ); |
| 414 | 414 | if ($value === true) { |
| 415 | - $attr['checked'] = 'checked'; |
|
| 415 | + $attr[ 'checked' ] = 'checked'; |
|
| 416 | 416 | } |
| 417 | 417 | if ($value === null) { |
| 418 | - $attr['disabled'] = 'disabled'; |
|
| 418 | + $attr[ 'disabled' ] = 'disabled'; |
|
| 419 | 419 | } |
| 420 | 420 | $ret .= $this->elementEmpty('input', $attr); |
| 421 | 421 | |
@@ -426,15 +426,15 @@ discard block |
||
| 426 | 426 | |
| 427 | 427 | $attr = array( |
| 428 | 428 | 'type' => 'radio', |
| 429 | - 'name' => "$name" . "[$ns.$directive]", |
|
| 429 | + 'name' => "$name"."[$ns.$directive]", |
|
| 430 | 430 | 'id' => "$name:No_$ns.$directive", |
| 431 | 431 | 'value' => '0' |
| 432 | 432 | ); |
| 433 | 433 | if ($value === false) { |
| 434 | - $attr['checked'] = 'checked'; |
|
| 434 | + $attr[ 'checked' ] = 'checked'; |
|
| 435 | 435 | } |
| 436 | 436 | if ($value === null) { |
| 437 | - $attr['disabled'] = 'disabled'; |
|
| 437 | + $attr[ 'disabled' ] = 'disabled'; |
|
| 438 | 438 | } |
| 439 | 439 | $ret .= $this->elementEmpty('input', $attr); |
| 440 | 440 | |
@@ -528,9 +528,10 @@ discard block |
||
| 528 | 528 | * being the current one) will be deleted. |
| 529 | 529 | * |
| 530 | 530 | * @param HTMLPurifier_Token|array|int|bool $token Token substitution value |
| 531 | - * @param HTMLPurifier_Injector|int $injector Injector that performed the substitution; default is if |
|
| 531 | + * @param integer $injector Injector that performed the substitution; default is if |
|
| 532 | 532 | * this is not an injector related operation. |
| 533 | 533 | * @throws HTMLPurifier_Exception |
| 534 | + * @return HTMLPurifier_Token |
|
| 534 | 535 | */ |
| 535 | 536 | protected function processToken($token, $injector = -1) |
| 536 | 537 | { |
@@ -577,6 +578,7 @@ discard block |
||
| 577 | 578 | * Inserts a token before the current token. Cursor now points to |
| 578 | 579 | * this token. You must reprocess after this. |
| 579 | 580 | * @param HTMLPurifier_Token $token |
| 581 | + * @return HTMLPurifier_Token |
|
| 580 | 582 | */ |
| 581 | 583 | private function insertBefore($token) |
| 582 | 584 | { |
@@ -151,8 +151,8 @@ |
||
| 151 | 151 | |
| 152 | 152 | // isset is in loop because $tokens size changes during loop exec |
| 153 | 153 | for (;; |
| 154 | - // only increment if we don't need to reprocess |
|
| 155 | - $reprocess ? $reprocess = false : $token = $zipper->next($token)) { |
|
| 154 | + // only increment if we don't need to reprocess |
|
| 155 | + $reprocess ? $reprocess = false : $token = $zipper->next($token)) { |
|
| 156 | 156 | |
| 157 | 157 | // check for a rewind |
| 158 | 158 | if (is_int($i)) { |
@@ -82,10 +82,10 @@ discard block |
||
| 82 | 82 | $stack = array(); |
| 83 | 83 | |
| 84 | 84 | // member variables |
| 85 | - $this->stack =& $stack; |
|
| 86 | - $this->tokens =& $tokens; |
|
| 87 | - $this->token =& $token; |
|
| 88 | - $this->zipper =& $zipper; |
|
| 85 | + $this->stack = & $stack; |
|
| 86 | + $this->tokens = & $tokens; |
|
| 87 | + $this->token = & $token; |
|
| 88 | + $this->zipper = & $zipper; |
|
| 89 | 89 | $this->config = $config; |
| 90 | 90 | $this->context = $context; |
| 91 | 91 | |
@@ -100,8 +100,8 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | $injectors = $config->getBatch('AutoFormat'); |
| 102 | 102 | $def_injectors = $definition->info_injector; |
| 103 | - $custom_injectors = $injectors['Custom']; |
|
| 104 | - unset($injectors['Custom']); // special case |
|
| 103 | + $custom_injectors = $injectors[ 'Custom' ]; |
|
| 104 | + unset($injectors[ 'Custom' ]); // special case |
|
| 105 | 105 | foreach ($injectors as $injector => $b) { |
| 106 | 106 | // XXX: Fix with a legitimate lookup table of enabled filters |
| 107 | 107 | if (strpos($injector, '.') !== false) { |
@@ -111,11 +111,11 @@ discard block |
||
| 111 | 111 | if (!$b) { |
| 112 | 112 | continue; |
| 113 | 113 | } |
| 114 | - $this->injectors[] = new $injector; |
|
| 114 | + $this->injectors[ ] = new $injector; |
|
| 115 | 115 | } |
| 116 | 116 | foreach ($def_injectors as $injector) { |
| 117 | 117 | // assumed to be objects |
| 118 | - $this->injectors[] = $injector; |
|
| 118 | + $this->injectors[ ] = $injector; |
|
| 119 | 119 | } |
| 120 | 120 | foreach ($custom_injectors as $injector) { |
| 121 | 121 | if (!$injector) { |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | $injector = "HTMLPurifier_Injector_$injector"; |
| 126 | 126 | $injector = new $injector; |
| 127 | 127 | } |
| 128 | - $this->injectors[] = $injector; |
|
| 128 | + $this->injectors[ ] = $injector; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // give the injectors references to the definition and context |
@@ -159,19 +159,19 @@ discard block |
||
| 159 | 159 | // possibility: disable rewinding if the current token has a |
| 160 | 160 | // rewind set on it already. This would offer protection from |
| 161 | 161 | // infinite loop, but might hinder some advanced rewinding. |
| 162 | - $rewind_offset = $this->injectors[$i]->getRewindOffset(); |
|
| 162 | + $rewind_offset = $this->injectors[ $i ]->getRewindOffset(); |
|
| 163 | 163 | if (is_int($rewind_offset)) { |
| 164 | 164 | for ($j = 0; $j < $rewind_offset; $j++) { |
| 165 | 165 | if (empty($zipper->front)) break; |
| 166 | 166 | $token = $zipper->prev($token); |
| 167 | 167 | // indicate that other injectors should not process this token, |
| 168 | 168 | // but we need to reprocess it |
| 169 | - unset($token->skip[$i]); |
|
| 169 | + unset($token->skip[ $i ]); |
|
| 170 | 170 | $token->rewind = $i; |
| 171 | 171 | if ($token instanceof HTMLPurifier_Token_Start) { |
| 172 | 172 | array_pop($this->stack); |
| 173 | 173 | } elseif ($token instanceof HTMLPurifier_Token_End) { |
| 174 | - $this->stack[] = $token->start; |
|
| 174 | + $this->stack[ ] = $token->start; |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | } |
@@ -187,10 +187,10 @@ discard block |
||
| 187 | 187 | |
| 188 | 188 | // peek |
| 189 | 189 | $top_nesting = array_pop($this->stack); |
| 190 | - $this->stack[] = $top_nesting; |
|
| 190 | + $this->stack[ ] = $top_nesting; |
|
| 191 | 191 | |
| 192 | 192 | // send error [TagClosedSuppress] |
| 193 | - if ($e && !isset($top_nesting->armor['MakeWellFormed_TagClosedError'])) { |
|
| 193 | + if ($e && !isset($top_nesting->armor[ 'MakeWellFormed_TagClosedError' ])) { |
|
| 194 | 194 | $e->send(E_NOTICE, 'Strategy_MakeWellFormed: Tag closed by document end', $top_nesting); |
| 195 | 195 | } |
| 196 | 196 | |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | if (empty($token->is_tag)) { |
| 210 | 210 | if ($token instanceof HTMLPurifier_Token_Text) { |
| 211 | 211 | foreach ($this->injectors as $i => $injector) { |
| 212 | - if (isset($token->skip[$i])) { |
|
| 212 | + if (isset($token->skip[ $i ])) { |
|
| 213 | 213 | continue; |
| 214 | 214 | } |
| 215 | 215 | if ($token->rewind !== null && $token->rewind !== $i) { |
@@ -227,8 +227,8 @@ discard block |
||
| 227 | 227 | continue; |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - if (isset($definition->info[$token->name])) { |
|
| 231 | - $type = $definition->info[$token->name]->child->type; |
|
| 230 | + if (isset($definition->info[ $token->name ])) { |
|
| 231 | + $type = $definition->info[ $token->name ]->child->type; |
|
| 232 | 232 | } else { |
| 233 | 233 | $type = false; // Type is unknown, treat accordingly |
| 234 | 234 | } |
@@ -279,25 +279,25 @@ discard block |
||
| 279 | 279 | // of "easy") |
| 280 | 280 | |
| 281 | 281 | $parent = array_pop($this->stack); |
| 282 | - $this->stack[] = $parent; |
|
| 282 | + $this->stack[ ] = $parent; |
|
| 283 | 283 | |
| 284 | 284 | $parent_def = null; |
| 285 | 285 | $parent_elements = null; |
| 286 | 286 | $autoclose = false; |
| 287 | - if (isset($definition->info[$parent->name])) { |
|
| 288 | - $parent_def = $definition->info[$parent->name]; |
|
| 287 | + if (isset($definition->info[ $parent->name ])) { |
|
| 288 | + $parent_def = $definition->info[ $parent->name ]; |
|
| 289 | 289 | $parent_elements = $parent_def->child->getAllowedElements($config); |
| 290 | - $autoclose = !isset($parent_elements[$token->name]); |
|
| 290 | + $autoclose = !isset($parent_elements[ $token->name ]); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - if ($autoclose && $definition->info[$token->name]->wrap) { |
|
| 293 | + if ($autoclose && $definition->info[ $token->name ]->wrap) { |
|
| 294 | 294 | // Check if an element can be wrapped by another |
| 295 | 295 | // element to make it valid in a context (for |
| 296 | 296 | // example, <ul><ul> needs a <li> in between) |
| 297 | - $wrapname = $definition->info[$token->name]->wrap; |
|
| 298 | - $wrapdef = $definition->info[$wrapname]; |
|
| 297 | + $wrapname = $definition->info[ $token->name ]->wrap; |
|
| 298 | + $wrapdef = $definition->info[ $wrapname ]; |
|
| 299 | 299 | $elements = $wrapdef->child->getAllowedElements($config); |
| 300 | - if (isset($elements[$token->name]) && isset($parent_elements[$wrapname])) { |
|
| 300 | + if (isset($elements[ $token->name ]) && isset($parent_elements[ $wrapname ])) { |
|
| 301 | 301 | $newtoken = new HTMLPurifier_Token_Start($wrapname); |
| 302 | 302 | $token = $this->insertBefore($newtoken); |
| 303 | 303 | $reprocess = true; |
@@ -313,19 +313,19 @@ discard block |
||
| 313 | 313 | if ($autoclose) { |
| 314 | 314 | // check if this autoclose is doomed to fail |
| 315 | 315 | // (this rechecks $parent, which his harmless) |
| 316 | - $autoclose_ok = isset($global_parent_allowed_elements[$token->name]); |
|
| 316 | + $autoclose_ok = isset($global_parent_allowed_elements[ $token->name ]); |
|
| 317 | 317 | if (!$autoclose_ok) { |
| 318 | 318 | foreach ($this->stack as $ancestor) { |
| 319 | - $elements = $definition->info[$ancestor->name]->child->getAllowedElements($config); |
|
| 320 | - if (isset($elements[$token->name])) { |
|
| 319 | + $elements = $definition->info[ $ancestor->name ]->child->getAllowedElements($config); |
|
| 320 | + if (isset($elements[ $token->name ])) { |
|
| 321 | 321 | $autoclose_ok = true; |
| 322 | 322 | break; |
| 323 | 323 | } |
| 324 | - if ($definition->info[$token->name]->wrap) { |
|
| 325 | - $wrapname = $definition->info[$token->name]->wrap; |
|
| 326 | - $wrapdef = $definition->info[$wrapname]; |
|
| 324 | + if ($definition->info[ $token->name ]->wrap) { |
|
| 325 | + $wrapname = $definition->info[ $token->name ]->wrap; |
|
| 326 | + $wrapdef = $definition->info[ $wrapname ]; |
|
| 327 | 327 | $wrap_elements = $wrapdef->child->getAllowedElements($config); |
| 328 | - if (isset($wrap_elements[$token->name]) && isset($elements[$wrapname])) { |
|
| 328 | + if (isset($wrap_elements[ $token->name ]) && isset($elements[ $wrapname ])) { |
|
| 329 | 329 | $autoclose_ok = true; |
| 330 | 330 | break; |
| 331 | 331 | } |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | $new_token = new HTMLPurifier_Token_End($parent->name); |
| 338 | 338 | $new_token->start = $parent; |
| 339 | 339 | // [TagClosedSuppress] |
| 340 | - if ($e && !isset($parent->armor['MakeWellFormed_TagClosedError'])) { |
|
| 340 | + if ($e && !isset($parent->armor[ 'MakeWellFormed_TagClosedError' ])) { |
|
| 341 | 341 | if (!$carryover) { |
| 342 | 342 | $e->send(E_NOTICE, 'Strategy_MakeWellFormed: Tag auto closed', $parent); |
| 343 | 343 | } else { |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | if ($carryover) { |
| 348 | 348 | $element = clone $parent; |
| 349 | 349 | // [TagClosedAuto] |
| 350 | - $element->armor['MakeWellFormed_TagClosedError'] = true; |
|
| 350 | + $element->armor[ 'MakeWellFormed_TagClosedError' ] = true; |
|
| 351 | 351 | $element->carryover = true; |
| 352 | 352 | $token = $this->processToken(array($new_token, $token, $element)); |
| 353 | 353 | } else { |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | |
| 367 | 367 | if ($ok) { |
| 368 | 368 | foreach ($this->injectors as $i => $injector) { |
| 369 | - if (isset($token->skip[$i])) { |
|
| 369 | + if (isset($token->skip[ $i ])) { |
|
| 370 | 370 | continue; |
| 371 | 371 | } |
| 372 | 372 | if ($token->rewind !== null && $token->rewind !== $i) { |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | if (!$reprocess) { |
| 382 | 382 | // ah, nothing interesting happened; do normal processing |
| 383 | 383 | if ($token instanceof HTMLPurifier_Token_Start) { |
| 384 | - $this->stack[] = $token; |
|
| 384 | + $this->stack[ ] = $token; |
|
| 385 | 385 | } elseif ($token instanceof HTMLPurifier_Token_End) { |
| 386 | 386 | throw new HTMLPurifier_Exception( |
| 387 | 387 | 'Improper handling of end tag in start code; possible error in MakeWellFormed' |
@@ -421,7 +421,7 @@ discard block |
||
| 421 | 421 | if ($current_parent->name == $token->name) { |
| 422 | 422 | $token->start = $current_parent; |
| 423 | 423 | foreach ($this->injectors as $i => $injector) { |
| 424 | - if (isset($token->skip[$i])) { |
|
| 424 | + if (isset($token->skip[ $i ])) { |
|
| 425 | 425 | continue; |
| 426 | 426 | } |
| 427 | 427 | if ($token->rewind !== null && $token->rewind !== $i) { |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | $r = $token; |
| 431 | 431 | $injector->handleEnd($r); |
| 432 | 432 | $token = $this->processToken($r, $i); |
| 433 | - $this->stack[] = $current_parent; |
|
| 433 | + $this->stack[ ] = $current_parent; |
|
| 434 | 434 | $reprocess = true; |
| 435 | 435 | break; |
| 436 | 436 | } |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | // okay, so we're trying to close the wrong tag |
| 441 | 441 | |
| 442 | 442 | // undo the pop previous pop |
| 443 | - $this->stack[] = $current_parent; |
|
| 443 | + $this->stack[ ] = $current_parent; |
|
| 444 | 444 | |
| 445 | 445 | // scroll back the entire nest, trying to find our tag. |
| 446 | 446 | // (feature could be to specify how far you'd like to go) |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | // -2 because -1 is the last element, but we already checked that |
| 449 | 449 | $skipped_tags = false; |
| 450 | 450 | for ($j = $size - 2; $j >= 0; $j--) { |
| 451 | - if ($this->stack[$j]->name == $token->name) { |
|
| 451 | + if ($this->stack[ $j ]->name == $token->name) { |
|
| 452 | 452 | $skipped_tags = array_slice($this->stack, $j); |
| 453 | 453 | break; |
| 454 | 454 | } |
@@ -477,8 +477,8 @@ discard block |
||
| 477 | 477 | for ($j = $c - 1; $j > 0; $j--) { |
| 478 | 478 | // notice we exclude $j == 0, i.e. the current ending tag, from |
| 479 | 479 | // the errors... [TagClosedSuppress] |
| 480 | - if (!isset($skipped_tags[$j]->armor['MakeWellFormed_TagClosedError'])) { |
|
| 481 | - $e->send(E_NOTICE, 'Strategy_MakeWellFormed: Tag closed by element end', $skipped_tags[$j]); |
|
| 480 | + if (!isset($skipped_tags[ $j ]->armor[ 'MakeWellFormed_TagClosedError' ])) { |
|
| 481 | + $e->send(E_NOTICE, 'Strategy_MakeWellFormed: Tag closed by element end', $skipped_tags[ $j ]); |
|
| 482 | 482 | } |
| 483 | 483 | } |
| 484 | 484 | } |
@@ -487,15 +487,15 @@ discard block |
||
| 487 | 487 | $replace = array($token); |
| 488 | 488 | for ($j = 1; $j < $c; $j++) { |
| 489 | 489 | // ...as well as from the insertions |
| 490 | - $new_token = new HTMLPurifier_Token_End($skipped_tags[$j]->name); |
|
| 491 | - $new_token->start = $skipped_tags[$j]; |
|
| 490 | + $new_token = new HTMLPurifier_Token_End($skipped_tags[ $j ]->name); |
|
| 491 | + $new_token->start = $skipped_tags[ $j ]; |
|
| 492 | 492 | array_unshift($replace, $new_token); |
| 493 | - if (isset($definition->info[$new_token->name]) && $definition->info[$new_token->name]->formatting) { |
|
| 493 | + if (isset($definition->info[ $new_token->name ]) && $definition->info[ $new_token->name ]->formatting) { |
|
| 494 | 494 | // [TagClosedAuto] |
| 495 | - $element = clone $skipped_tags[$j]; |
|
| 495 | + $element = clone $skipped_tags[ $j ]; |
|
| 496 | 496 | $element->carryover = true; |
| 497 | - $element->armor['MakeWellFormed_TagClosedError'] = true; |
|
| 498 | - $replace[] = $element; |
|
| 497 | + $element->armor[ 'MakeWellFormed_TagClosedError' ] = true; |
|
| 498 | + $replace[ ] = $element; |
|
| 499 | 499 | } |
| 500 | 500 | } |
| 501 | 501 | $token = $this->processToken($replace); |
@@ -547,10 +547,10 @@ discard block |
||
| 547 | 547 | if (!is_array($token)) { |
| 548 | 548 | throw new HTMLPurifier_Exception('Invalid token type from injector'); |
| 549 | 549 | } |
| 550 | - if (!is_int($token[0])) { |
|
| 550 | + if (!is_int($token[ 0 ])) { |
|
| 551 | 551 | array_unshift($token, 1); |
| 552 | 552 | } |
| 553 | - if ($token[0] === 0) { |
|
| 553 | + if ($token[ 0 ] === 0) { |
|
| 554 | 554 | throw new HTMLPurifier_Exception('Deleting zero tokens is not valid'); |
| 555 | 555 | } |
| 556 | 556 | |
@@ -562,10 +562,10 @@ discard block |
||
| 562 | 562 | |
| 563 | 563 | if ($injector > -1) { |
| 564 | 564 | // determine appropriate skips |
| 565 | - $oldskip = isset($old[0]) ? $old[0]->skip : array(); |
|
| 565 | + $oldskip = isset($old[ 0 ]) ? $old[ 0 ]->skip : array(); |
|
| 566 | 566 | foreach ($token as $object) { |
| 567 | 567 | $object->skip = $oldskip; |
| 568 | - $object->skip[$injector] = true; |
|
| 568 | + $object->skip[ $injector ] = true; |
|
| 569 | 569 | } |
| 570 | 570 | } |
| 571 | 571 | |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | // differences |
| 585 | 585 | $splice = $this->zipper->splice($this->token, 0, array($token)); |
| 586 | 586 | |
| 587 | - return $splice[1]; |
|
| 587 | + return $splice[ 1 ]; |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | /** |
@@ -162,7 +162,9 @@ |
||
| 162 | 162 | $rewind_offset = $this->injectors[$i]->getRewindOffset(); |
| 163 | 163 | if (is_int($rewind_offset)) { |
| 164 | 164 | for ($j = 0; $j < $rewind_offset; $j++) { |
| 165 | - if (empty($zipper->front)) break; |
|
| 165 | + if (empty($zipper->front)) { |
|
| 166 | + break; |
|
| 167 | + } |
|
| 166 | 168 | $token = $zipper->prev($token); |
| 167 | 169 | // indicate that other injectors should not process this token, |
| 168 | 170 | // but we need to reprocess it |
@@ -25,6 +25,9 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | ### Simple Function Interface ### |
| 27 | 27 | |
| 28 | + /** |
|
| 29 | + * @param string $text |
|
| 30 | + */ |
|
| 28 | 31 | public static function defaultTransform($text) { |
| 29 | 32 | # |
| 30 | 33 | # Initialize the parser and return the result of its transform method. |
@@ -931,6 +934,10 @@ discard block |
||
| 931 | 934 | |
| 932 | 935 | protected $list_level = 0; |
| 933 | 936 | |
| 937 | + /** |
|
| 938 | + * @param string $list_str |
|
| 939 | + * @param string $marker_any_re |
|
| 940 | + */ |
|
| 934 | 941 | protected function processListItems($list_str, $marker_any_re) { |
| 935 | 942 | # |
| 936 | 943 | # Process the contents of a single ordered or unordered list, splitting it |
@@ -1034,6 +1041,9 @@ discard block |
||
| 1034 | 1041 | } |
| 1035 | 1042 | |
| 1036 | 1043 | |
| 1044 | + /** |
|
| 1045 | + * @param string $code |
|
| 1046 | + */ |
|
| 1037 | 1047 | protected function makeCodeSpan($code) { |
| 1038 | 1048 | # |
| 1039 | 1049 | # Create a code span markup for $code. Called from handleSpanToken. |
@@ -1311,6 +1321,9 @@ discard block |
||
| 1311 | 1321 | } |
| 1312 | 1322 | |
| 1313 | 1323 | |
| 1324 | + /** |
|
| 1325 | + * @return string |
|
| 1326 | + */ |
|
| 1314 | 1327 | protected function encodeAttribute($text) { |
| 1315 | 1328 | # |
| 1316 | 1329 | # Encode text for a double-quoted HTML attribute. This function |
@@ -1551,6 +1564,9 @@ discard block |
||
| 1551 | 1564 | # hanlde UTF-8 if the default function does not exist. |
| 1552 | 1565 | protected $utf8_strlen = 'mb_strlen'; |
| 1553 | 1566 | |
| 1567 | + /** |
|
| 1568 | + * @param string $text |
|
| 1569 | + */ |
|
| 1554 | 1570 | protected function detab($text) { |
| 1555 | 1571 | # |
| 1556 | 1572 | # Replace tabs with the appropriate amount of space. |
@@ -19,193 +19,193 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | class Markdown implements MarkdownInterface { |
| 21 | 21 | |
| 22 | - ### Version ### |
|
| 22 | + ### Version ### |
|
| 23 | 23 | |
| 24 | - const MARKDOWNLIB_VERSION = "1.5.0"; |
|
| 24 | + const MARKDOWNLIB_VERSION = "1.5.0"; |
|
| 25 | 25 | |
| 26 | - ### Simple Function Interface ### |
|
| 26 | + ### Simple Function Interface ### |
|
| 27 | 27 | |
| 28 | - public static function defaultTransform($text) { |
|
| 29 | - # |
|
| 30 | - # Initialize the parser and return the result of its transform method. |
|
| 31 | - # This will work fine for derived classes too. |
|
| 32 | - # |
|
| 33 | - # Take parser class on which this function was called. |
|
| 34 | - $parser_class = \get_called_class(); |
|
| 28 | + public static function defaultTransform($text) { |
|
| 29 | + # |
|
| 30 | + # Initialize the parser and return the result of its transform method. |
|
| 31 | + # This will work fine for derived classes too. |
|
| 32 | + # |
|
| 33 | + # Take parser class on which this function was called. |
|
| 34 | + $parser_class = \get_called_class(); |
|
| 35 | 35 | |
| 36 | - # try to take parser from the static parser list |
|
| 37 | - static $parser_list; |
|
| 38 | - $parser =& $parser_list[$parser_class]; |
|
| 36 | + # try to take parser from the static parser list |
|
| 37 | + static $parser_list; |
|
| 38 | + $parser =& $parser_list[$parser_class]; |
|
| 39 | 39 | |
| 40 | - # create the parser it not already set |
|
| 41 | - if (!$parser) |
|
| 42 | - $parser = new $parser_class; |
|
| 40 | + # create the parser it not already set |
|
| 41 | + if (!$parser) |
|
| 42 | + $parser = new $parser_class; |
|
| 43 | 43 | |
| 44 | - # Transform text using parser. |
|
| 45 | - return $parser->transform($text); |
|
| 46 | - } |
|
| 44 | + # Transform text using parser. |
|
| 45 | + return $parser->transform($text); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - ### Configuration Variables ### |
|
| 48 | + ### Configuration Variables ### |
|
| 49 | 49 | |
| 50 | - # Change to ">" for HTML output. |
|
| 51 | - public $empty_element_suffix = " />"; |
|
| 52 | - public $tab_width = 4; |
|
| 50 | + # Change to ">" for HTML output. |
|
| 51 | + public $empty_element_suffix = " />"; |
|
| 52 | + public $tab_width = 4; |
|
| 53 | 53 | |
| 54 | - # Change to `true` to disallow markup or entities. |
|
| 55 | - public $no_markup = false; |
|
| 56 | - public $no_entities = false; |
|
| 54 | + # Change to `true` to disallow markup or entities. |
|
| 55 | + public $no_markup = false; |
|
| 56 | + public $no_entities = false; |
|
| 57 | 57 | |
| 58 | - # Predefined urls and titles for reference links and images. |
|
| 59 | - public $predef_urls = array(); |
|
| 60 | - public $predef_titles = array(); |
|
| 61 | - |
|
| 62 | - # Optional filter function for URLs |
|
| 63 | - public $url_filter_func = null; |
|
| 64 | - |
|
| 65 | - # Optional header id="" generation callback function. |
|
| 66 | - public $header_id_func = null; |
|
| 67 | - |
|
| 68 | - # Class attribute to toggle "enhanced ordered list" behaviour |
|
| 69 | - # setting this to true will allow ordered lists to start from the index |
|
| 70 | - # number that is defined first. For example: |
|
| 71 | - # 2. List item two |
|
| 72 | - # 3. List item three |
|
| 73 | - # |
|
| 74 | - # becomes |
|
| 75 | - # <ol start="2"> |
|
| 76 | - # <li>List item two</li> |
|
| 77 | - # <li>List item three</li> |
|
| 78 | - # </ol> |
|
| 79 | - public $enhanced_ordered_list = false; |
|
| 80 | - |
|
| 81 | - ### Parser Implementation ### |
|
| 82 | - |
|
| 83 | - # Regex to match balanced [brackets]. |
|
| 84 | - # Needed to insert a maximum bracked depth while converting to PHP. |
|
| 85 | - protected $nested_brackets_depth = 6; |
|
| 86 | - protected $nested_brackets_re; |
|
| 58 | + # Predefined urls and titles for reference links and images. |
|
| 59 | + public $predef_urls = array(); |
|
| 60 | + public $predef_titles = array(); |
|
| 61 | + |
|
| 62 | + # Optional filter function for URLs |
|
| 63 | + public $url_filter_func = null; |
|
| 64 | + |
|
| 65 | + # Optional header id="" generation callback function. |
|
| 66 | + public $header_id_func = null; |
|
| 67 | + |
|
| 68 | + # Class attribute to toggle "enhanced ordered list" behaviour |
|
| 69 | + # setting this to true will allow ordered lists to start from the index |
|
| 70 | + # number that is defined first. For example: |
|
| 71 | + # 2. List item two |
|
| 72 | + # 3. List item three |
|
| 73 | + # |
|
| 74 | + # becomes |
|
| 75 | + # <ol start="2"> |
|
| 76 | + # <li>List item two</li> |
|
| 77 | + # <li>List item three</li> |
|
| 78 | + # </ol> |
|
| 79 | + public $enhanced_ordered_list = false; |
|
| 80 | + |
|
| 81 | + ### Parser Implementation ### |
|
| 82 | + |
|
| 83 | + # Regex to match balanced [brackets]. |
|
| 84 | + # Needed to insert a maximum bracked depth while converting to PHP. |
|
| 85 | + protected $nested_brackets_depth = 6; |
|
| 86 | + protected $nested_brackets_re; |
|
| 87 | 87 | |
| 88 | - protected $nested_url_parenthesis_depth = 4; |
|
| 89 | - protected $nested_url_parenthesis_re; |
|
| 88 | + protected $nested_url_parenthesis_depth = 4; |
|
| 89 | + protected $nested_url_parenthesis_re; |
|
| 90 | 90 | |
| 91 | - # Table of hash values for escaped characters: |
|
| 92 | - protected $escape_chars = '\`*_{}[]()>#+-.!'; |
|
| 93 | - protected $escape_chars_re; |
|
| 91 | + # Table of hash values for escaped characters: |
|
| 92 | + protected $escape_chars = '\`*_{}[]()>#+-.!'; |
|
| 93 | + protected $escape_chars_re; |
|
| 94 | 94 | |
| 95 | 95 | |
| 96 | - public function __construct() { |
|
| 97 | - # |
|
| 98 | - # Constructor function. Initialize appropriate member variables. |
|
| 99 | - # |
|
| 100 | - $this->_initDetab(); |
|
| 101 | - $this->prepareItalicsAndBold(); |
|
| 96 | + public function __construct() { |
|
| 97 | + # |
|
| 98 | + # Constructor function. Initialize appropriate member variables. |
|
| 99 | + # |
|
| 100 | + $this->_initDetab(); |
|
| 101 | + $this->prepareItalicsAndBold(); |
|
| 102 | 102 | |
| 103 | - $this->nested_brackets_re = |
|
| 104 | - str_repeat('(?>[^\[\]]+|\[', $this->nested_brackets_depth). |
|
| 105 | - str_repeat('\])*', $this->nested_brackets_depth); |
|
| 103 | + $this->nested_brackets_re = |
|
| 104 | + str_repeat('(?>[^\[\]]+|\[', $this->nested_brackets_depth). |
|
| 105 | + str_repeat('\])*', $this->nested_brackets_depth); |
|
| 106 | 106 | |
| 107 | - $this->nested_url_parenthesis_re = |
|
| 108 | - str_repeat('(?>[^()\s]+|\(', $this->nested_url_parenthesis_depth). |
|
| 109 | - str_repeat('(?>\)))*', $this->nested_url_parenthesis_depth); |
|
| 107 | + $this->nested_url_parenthesis_re = |
|
| 108 | + str_repeat('(?>[^()\s]+|\(', $this->nested_url_parenthesis_depth). |
|
| 109 | + str_repeat('(?>\)))*', $this->nested_url_parenthesis_depth); |
|
| 110 | 110 | |
| 111 | - $this->escape_chars_re = '['.preg_quote($this->escape_chars).']'; |
|
| 111 | + $this->escape_chars_re = '['.preg_quote($this->escape_chars).']'; |
|
| 112 | 112 | |
| 113 | - # Sort document, block, and span gamut in ascendent priority order. |
|
| 114 | - asort($this->document_gamut); |
|
| 115 | - asort($this->block_gamut); |
|
| 116 | - asort($this->span_gamut); |
|
| 117 | - } |
|
| 113 | + # Sort document, block, and span gamut in ascendent priority order. |
|
| 114 | + asort($this->document_gamut); |
|
| 115 | + asort($this->block_gamut); |
|
| 116 | + asort($this->span_gamut); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | |
| 120 | - # Internal hashes used during transformation. |
|
| 121 | - protected $urls = array(); |
|
| 122 | - protected $titles = array(); |
|
| 123 | - protected $html_hashes = array(); |
|
| 120 | + # Internal hashes used during transformation. |
|
| 121 | + protected $urls = array(); |
|
| 122 | + protected $titles = array(); |
|
| 123 | + protected $html_hashes = array(); |
|
| 124 | 124 | |
| 125 | - # Status flag to avoid invalid nesting. |
|
| 126 | - protected $in_anchor = false; |
|
| 125 | + # Status flag to avoid invalid nesting. |
|
| 126 | + protected $in_anchor = false; |
|
| 127 | 127 | |
| 128 | 128 | |
| 129 | - protected function setup() { |
|
| 130 | - # |
|
| 131 | - # Called before the transformation process starts to setup parser |
|
| 132 | - # states. |
|
| 133 | - # |
|
| 134 | - # Clear global hashes. |
|
| 135 | - $this->urls = $this->predef_urls; |
|
| 136 | - $this->titles = $this->predef_titles; |
|
| 137 | - $this->html_hashes = array(); |
|
| 129 | + protected function setup() { |
|
| 130 | + # |
|
| 131 | + # Called before the transformation process starts to setup parser |
|
| 132 | + # states. |
|
| 133 | + # |
|
| 134 | + # Clear global hashes. |
|
| 135 | + $this->urls = $this->predef_urls; |
|
| 136 | + $this->titles = $this->predef_titles; |
|
| 137 | + $this->html_hashes = array(); |
|
| 138 | 138 | |
| 139 | - $this->in_anchor = false; |
|
| 140 | - } |
|
| 139 | + $this->in_anchor = false; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - protected function teardown() { |
|
| 143 | - # |
|
| 144 | - # Called after the transformation process to clear any variable |
|
| 145 | - # which may be taking up memory unnecessarly. |
|
| 146 | - # |
|
| 147 | - $this->urls = array(); |
|
| 148 | - $this->titles = array(); |
|
| 149 | - $this->html_hashes = array(); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - public function transform($text) { |
|
| 154 | - # |
|
| 155 | - # Main function. Performs some preprocessing on the input text |
|
| 156 | - # and pass it through the document gamut. |
|
| 157 | - # |
|
| 158 | - $this->setup(); |
|
| 142 | + protected function teardown() { |
|
| 143 | + # |
|
| 144 | + # Called after the transformation process to clear any variable |
|
| 145 | + # which may be taking up memory unnecessarly. |
|
| 146 | + # |
|
| 147 | + $this->urls = array(); |
|
| 148 | + $this->titles = array(); |
|
| 149 | + $this->html_hashes = array(); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + public function transform($text) { |
|
| 154 | + # |
|
| 155 | + # Main function. Performs some preprocessing on the input text |
|
| 156 | + # and pass it through the document gamut. |
|
| 157 | + # |
|
| 158 | + $this->setup(); |
|
| 159 | 159 | |
| 160 | - # Remove UTF-8 BOM and marker character in input, if present. |
|
| 161 | - $text = preg_replace('{^\xEF\xBB\xBF|\x1A}', '', $text); |
|
| 160 | + # Remove UTF-8 BOM and marker character in input, if present. |
|
| 161 | + $text = preg_replace('{^\xEF\xBB\xBF|\x1A}', '', $text); |
|
| 162 | 162 | |
| 163 | - # Standardize line endings: |
|
| 164 | - # DOS to Unix and Mac to Unix |
|
| 165 | - $text = preg_replace('{\r\n?}', "\n", $text); |
|
| 163 | + # Standardize line endings: |
|
| 164 | + # DOS to Unix and Mac to Unix |
|
| 165 | + $text = preg_replace('{\r\n?}', "\n", $text); |
|
| 166 | 166 | |
| 167 | - # Make sure $text ends with a couple of newlines: |
|
| 168 | - $text .= "\n\n"; |
|
| 167 | + # Make sure $text ends with a couple of newlines: |
|
| 168 | + $text .= "\n\n"; |
|
| 169 | 169 | |
| 170 | - # Convert all tabs to spaces. |
|
| 171 | - $text = $this->detab($text); |
|
| 170 | + # Convert all tabs to spaces. |
|
| 171 | + $text = $this->detab($text); |
|
| 172 | 172 | |
| 173 | - # Turn block-level HTML blocks into hash entries |
|
| 174 | - $text = $this->hashHTMLBlocks($text); |
|
| 173 | + # Turn block-level HTML blocks into hash entries |
|
| 174 | + $text = $this->hashHTMLBlocks($text); |
|
| 175 | 175 | |
| 176 | - # Strip any lines consisting only of spaces and tabs. |
|
| 177 | - # This makes subsequent regexen easier to write, because we can |
|
| 178 | - # match consecutive blank lines with /\n+/ instead of something |
|
| 179 | - # contorted like /[ ]*\n+/ . |
|
| 180 | - $text = preg_replace('/^[ ]+$/m', '', $text); |
|
| 176 | + # Strip any lines consisting only of spaces and tabs. |
|
| 177 | + # This makes subsequent regexen easier to write, because we can |
|
| 178 | + # match consecutive blank lines with /\n+/ instead of something |
|
| 179 | + # contorted like /[ ]*\n+/ . |
|
| 180 | + $text = preg_replace('/^[ ]+$/m', '', $text); |
|
| 181 | 181 | |
| 182 | - # Run document gamut methods. |
|
| 183 | - foreach ($this->document_gamut as $method => $priority) { |
|
| 184 | - $text = $this->$method($text); |
|
| 185 | - } |
|
| 182 | + # Run document gamut methods. |
|
| 183 | + foreach ($this->document_gamut as $method => $priority) { |
|
| 184 | + $text = $this->$method($text); |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - $this->teardown(); |
|
| 187 | + $this->teardown(); |
|
| 188 | 188 | |
| 189 | - return $text . "\n"; |
|
| 190 | - } |
|
| 189 | + return $text . "\n"; |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - protected $document_gamut = array( |
|
| 193 | - # Strip link definitions, store in hashes. |
|
| 194 | - "stripLinkDefinitions" => 20, |
|
| 192 | + protected $document_gamut = array( |
|
| 193 | + # Strip link definitions, store in hashes. |
|
| 194 | + "stripLinkDefinitions" => 20, |
|
| 195 | 195 | |
| 196 | - "runBasicBlockGamut" => 30, |
|
| 197 | - ); |
|
| 196 | + "runBasicBlockGamut" => 30, |
|
| 197 | + ); |
|
| 198 | 198 | |
| 199 | 199 | |
| 200 | - protected function stripLinkDefinitions($text) { |
|
| 201 | - # |
|
| 202 | - # Strips link definitions from text, stores the URLs and titles in |
|
| 203 | - # hash references. |
|
| 204 | - # |
|
| 205 | - $less_than_tab = $this->tab_width - 1; |
|
| 200 | + protected function stripLinkDefinitions($text) { |
|
| 201 | + # |
|
| 202 | + # Strips link definitions from text, stores the URLs and titles in |
|
| 203 | + # hash references. |
|
| 204 | + # |
|
| 205 | + $less_than_tab = $this->tab_width - 1; |
|
| 206 | 206 | |
| 207 | - # Link defs are in the form: ^[id]: url "optional title" |
|
| 208 | - $text = preg_replace_callback('{ |
|
| 207 | + # Link defs are in the form: ^[id]: url "optional title" |
|
| 208 | + $text = preg_replace_callback('{ |
|
| 209 | 209 | ^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?: # id = $1 |
| 210 | 210 | [ ]* |
| 211 | 211 | \n? # maybe *one* newline |
@@ -227,46 +227,46 @@ discard block |
||
| 227 | 227 | )? # title is optional |
| 228 | 228 | (?:\n+|\Z) |
| 229 | 229 | }xm', |
| 230 | - array($this, '_stripLinkDefinitions_callback'), |
|
| 231 | - $text); |
|
| 232 | - return $text; |
|
| 233 | - } |
|
| 234 | - protected function _stripLinkDefinitions_callback($matches) { |
|
| 235 | - $link_id = strtolower($matches[1]); |
|
| 236 | - $url = $matches[2] == '' ? $matches[3] : $matches[2]; |
|
| 237 | - $this->urls[$link_id] = $url; |
|
| 238 | - $this->titles[$link_id] =& $matches[4]; |
|
| 239 | - return ''; # String that will replace the block |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - protected function hashHTMLBlocks($text) { |
|
| 244 | - if ($this->no_markup) return $text; |
|
| 245 | - |
|
| 246 | - $less_than_tab = $this->tab_width - 1; |
|
| 247 | - |
|
| 248 | - # Hashify HTML blocks: |
|
| 249 | - # We only want to do this for block-level HTML tags, such as headers, |
|
| 250 | - # lists, and tables. That's because we still want to wrap <p>s around |
|
| 251 | - # "paragraphs" that are wrapped in non-block-level tags, such as anchors, |
|
| 252 | - # phrase emphasis, and spans. The list of tags we're looking for is |
|
| 253 | - # hard-coded: |
|
| 254 | - # |
|
| 255 | - # * List "a" is made of tags which can be both inline or block-level. |
|
| 256 | - # These will be treated block-level when the start tag is alone on |
|
| 257 | - # its line, otherwise they're not matched here and will be taken as |
|
| 258 | - # inline later. |
|
| 259 | - # * List "b" is made of tags which are always block-level; |
|
| 260 | - # |
|
| 261 | - $block_tags_a_re = 'ins|del'; |
|
| 262 | - $block_tags_b_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|'. |
|
| 263 | - 'script|noscript|style|form|fieldset|iframe|math|svg|'. |
|
| 264 | - 'article|section|nav|aside|hgroup|header|footer|'. |
|
| 265 | - 'figure'; |
|
| 266 | - |
|
| 267 | - # Regular expression for the content of a block tag. |
|
| 268 | - $nested_tags_level = 4; |
|
| 269 | - $attr = ' |
|
| 230 | + array($this, '_stripLinkDefinitions_callback'), |
|
| 231 | + $text); |
|
| 232 | + return $text; |
|
| 233 | + } |
|
| 234 | + protected function _stripLinkDefinitions_callback($matches) { |
|
| 235 | + $link_id = strtolower($matches[1]); |
|
| 236 | + $url = $matches[2] == '' ? $matches[3] : $matches[2]; |
|
| 237 | + $this->urls[$link_id] = $url; |
|
| 238 | + $this->titles[$link_id] =& $matches[4]; |
|
| 239 | + return ''; # String that will replace the block |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + protected function hashHTMLBlocks($text) { |
|
| 244 | + if ($this->no_markup) return $text; |
|
| 245 | + |
|
| 246 | + $less_than_tab = $this->tab_width - 1; |
|
| 247 | + |
|
| 248 | + # Hashify HTML blocks: |
|
| 249 | + # We only want to do this for block-level HTML tags, such as headers, |
|
| 250 | + # lists, and tables. That's because we still want to wrap <p>s around |
|
| 251 | + # "paragraphs" that are wrapped in non-block-level tags, such as anchors, |
|
| 252 | + # phrase emphasis, and spans. The list of tags we're looking for is |
|
| 253 | + # hard-coded: |
|
| 254 | + # |
|
| 255 | + # * List "a" is made of tags which can be both inline or block-level. |
|
| 256 | + # These will be treated block-level when the start tag is alone on |
|
| 257 | + # its line, otherwise they're not matched here and will be taken as |
|
| 258 | + # inline later. |
|
| 259 | + # * List "b" is made of tags which are always block-level; |
|
| 260 | + # |
|
| 261 | + $block_tags_a_re = 'ins|del'; |
|
| 262 | + $block_tags_b_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|'. |
|
| 263 | + 'script|noscript|style|form|fieldset|iframe|math|svg|'. |
|
| 264 | + 'article|section|nav|aside|hgroup|header|footer|'. |
|
| 265 | + 'figure'; |
|
| 266 | + |
|
| 267 | + # Regular expression for the content of a block tag. |
|
| 268 | + $nested_tags_level = 4; |
|
| 269 | + $attr = ' |
|
| 270 | 270 | (?> # optional tag attributes |
| 271 | 271 | \s # starts with whitespace |
| 272 | 272 | (?> |
@@ -280,8 +280,8 @@ discard block |
||
| 280 | 280 | )* |
| 281 | 281 | )? |
| 282 | 282 | '; |
| 283 | - $content = |
|
| 284 | - str_repeat(' |
|
| 283 | + $content = |
|
| 284 | + str_repeat(' |
|
| 285 | 285 | (?> |
| 286 | 286 | [^<]+ # content without tag |
| 287 | 287 | | |
@@ -291,29 +291,29 @@ discard block |
||
| 291 | 291 | /> |
| 292 | 292 | | |
| 293 | 293 | >', $nested_tags_level). # end of opening tag |
| 294 | - '.*?'. # last level nested tag content |
|
| 295 | - str_repeat(' |
|
| 294 | + '.*?'. # last level nested tag content |
|
| 295 | + str_repeat(' |
|
| 296 | 296 | </\2\s*> # closing nested tag |
| 297 | 297 | ) |
| 298 | 298 | | |
| 299 | 299 | <(?!/\2\s*> # other tags with a different name |
| 300 | 300 | ) |
| 301 | 301 | )*', |
| 302 | - $nested_tags_level); |
|
| 303 | - $content2 = str_replace('\2', '\3', $content); |
|
| 304 | - |
|
| 305 | - # First, look for nested blocks, e.g.: |
|
| 306 | - # <div> |
|
| 307 | - # <div> |
|
| 308 | - # tags for inner block must be indented. |
|
| 309 | - # </div> |
|
| 310 | - # </div> |
|
| 311 | - # |
|
| 312 | - # The outermost tags must start at the left margin for this to match, and |
|
| 313 | - # the inner nested divs must be indented. |
|
| 314 | - # We need to do this before the next, more liberal match, because the next |
|
| 315 | - # match will start at the first `<div>` and stop at the first `</div>`. |
|
| 316 | - $text = preg_replace_callback('{(?> |
|
| 302 | + $nested_tags_level); |
|
| 303 | + $content2 = str_replace('\2', '\3', $content); |
|
| 304 | + |
|
| 305 | + # First, look for nested blocks, e.g.: |
|
| 306 | + # <div> |
|
| 307 | + # <div> |
|
| 308 | + # tags for inner block must be indented. |
|
| 309 | + # </div> |
|
| 310 | + # </div> |
|
| 311 | + # |
|
| 312 | + # The outermost tags must start at the left margin for this to match, and |
|
| 313 | + # the inner nested divs must be indented. |
|
| 314 | + # We need to do this before the next, more liberal match, because the next |
|
| 315 | + # match will start at the first `<div>` and stop at the first `</div>`. |
|
| 316 | + $text = preg_replace_callback('{(?> |
|
| 317 | 317 | (?> |
| 318 | 318 | (?<=\n) # Starting on its own line |
| 319 | 319 | | # or |
@@ -374,97 +374,97 @@ discard block |
||
| 374 | 374 | |
| 375 | 375 | ) |
| 376 | 376 | )}Sxmi', |
| 377 | - array($this, '_hashHTMLBlocks_callback'), |
|
| 378 | - $text); |
|
| 379 | - |
|
| 380 | - return $text; |
|
| 381 | - } |
|
| 382 | - protected function _hashHTMLBlocks_callback($matches) { |
|
| 383 | - $text = $matches[1]; |
|
| 384 | - $key = $this->hashBlock($text); |
|
| 385 | - return "\n\n$key\n\n"; |
|
| 386 | - } |
|
| 377 | + array($this, '_hashHTMLBlocks_callback'), |
|
| 378 | + $text); |
|
| 379 | + |
|
| 380 | + return $text; |
|
| 381 | + } |
|
| 382 | + protected function _hashHTMLBlocks_callback($matches) { |
|
| 383 | + $text = $matches[1]; |
|
| 384 | + $key = $this->hashBlock($text); |
|
| 385 | + return "\n\n$key\n\n"; |
|
| 386 | + } |
|
| 387 | 387 | |
| 388 | 388 | |
| 389 | - protected function hashPart($text, $boundary = 'X') { |
|
| 390 | - # |
|
| 391 | - # Called whenever a tag must be hashed when a function insert an atomic |
|
| 392 | - # element in the text stream. Passing $text to through this function gives |
|
| 393 | - # a unique text-token which will be reverted back when calling unhash. |
|
| 394 | - # |
|
| 395 | - # The $boundary argument specify what character should be used to surround |
|
| 396 | - # the token. By convension, "B" is used for block elements that needs not |
|
| 397 | - # to be wrapped into paragraph tags at the end, ":" is used for elements |
|
| 398 | - # that are word separators and "X" is used in the general case. |
|
| 399 | - # |
|
| 400 | - # Swap back any tag hash found in $text so we do not have to `unhash` |
|
| 401 | - # multiple times at the end. |
|
| 402 | - $text = $this->unhash($text); |
|
| 389 | + protected function hashPart($text, $boundary = 'X') { |
|
| 390 | + # |
|
| 391 | + # Called whenever a tag must be hashed when a function insert an atomic |
|
| 392 | + # element in the text stream. Passing $text to through this function gives |
|
| 393 | + # a unique text-token which will be reverted back when calling unhash. |
|
| 394 | + # |
|
| 395 | + # The $boundary argument specify what character should be used to surround |
|
| 396 | + # the token. By convension, "B" is used for block elements that needs not |
|
| 397 | + # to be wrapped into paragraph tags at the end, ":" is used for elements |
|
| 398 | + # that are word separators and "X" is used in the general case. |
|
| 399 | + # |
|
| 400 | + # Swap back any tag hash found in $text so we do not have to `unhash` |
|
| 401 | + # multiple times at the end. |
|
| 402 | + $text = $this->unhash($text); |
|
| 403 | 403 | |
| 404 | - # Then hash the block. |
|
| 405 | - static $i = 0; |
|
| 406 | - $key = "$boundary\x1A" . ++$i . $boundary; |
|
| 407 | - $this->html_hashes[$key] = $text; |
|
| 408 | - return $key; # String that will replace the tag. |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - |
|
| 412 | - protected function hashBlock($text) { |
|
| 413 | - # |
|
| 414 | - # Shortcut function for hashPart with block-level boundaries. |
|
| 415 | - # |
|
| 416 | - return $this->hashPart($text, 'B'); |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - protected $block_gamut = array( |
|
| 421 | - # |
|
| 422 | - # These are all the transformations that form block-level |
|
| 423 | - # tags like paragraphs, headers, and list items. |
|
| 424 | - # |
|
| 425 | - "doHeaders" => 10, |
|
| 426 | - "doHorizontalRules" => 20, |
|
| 404 | + # Then hash the block. |
|
| 405 | + static $i = 0; |
|
| 406 | + $key = "$boundary\x1A" . ++$i . $boundary; |
|
| 407 | + $this->html_hashes[$key] = $text; |
|
| 408 | + return $key; # String that will replace the tag. |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + |
|
| 412 | + protected function hashBlock($text) { |
|
| 413 | + # |
|
| 414 | + # Shortcut function for hashPart with block-level boundaries. |
|
| 415 | + # |
|
| 416 | + return $this->hashPart($text, 'B'); |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + protected $block_gamut = array( |
|
| 421 | + # |
|
| 422 | + # These are all the transformations that form block-level |
|
| 423 | + # tags like paragraphs, headers, and list items. |
|
| 424 | + # |
|
| 425 | + "doHeaders" => 10, |
|
| 426 | + "doHorizontalRules" => 20, |
|
| 427 | 427 | |
| 428 | - "doLists" => 40, |
|
| 429 | - "doCodeBlocks" => 50, |
|
| 430 | - "doBlockQuotes" => 60, |
|
| 431 | - ); |
|
| 432 | - |
|
| 433 | - protected function runBlockGamut($text) { |
|
| 434 | - # |
|
| 435 | - # Run block gamut tranformations. |
|
| 436 | - # |
|
| 437 | - # We need to escape raw HTML in Markdown source before doing anything |
|
| 438 | - # else. This need to be done for each block, and not only at the |
|
| 439 | - # begining in the Markdown function since hashed blocks can be part of |
|
| 440 | - # list items and could have been indented. Indented blocks would have |
|
| 441 | - # been seen as a code block in a previous pass of hashHTMLBlocks. |
|
| 442 | - $text = $this->hashHTMLBlocks($text); |
|
| 428 | + "doLists" => 40, |
|
| 429 | + "doCodeBlocks" => 50, |
|
| 430 | + "doBlockQuotes" => 60, |
|
| 431 | + ); |
|
| 432 | + |
|
| 433 | + protected function runBlockGamut($text) { |
|
| 434 | + # |
|
| 435 | + # Run block gamut tranformations. |
|
| 436 | + # |
|
| 437 | + # We need to escape raw HTML in Markdown source before doing anything |
|
| 438 | + # else. This need to be done for each block, and not only at the |
|
| 439 | + # begining in the Markdown function since hashed blocks can be part of |
|
| 440 | + # list items and could have been indented. Indented blocks would have |
|
| 441 | + # been seen as a code block in a previous pass of hashHTMLBlocks. |
|
| 442 | + $text = $this->hashHTMLBlocks($text); |
|
| 443 | 443 | |
| 444 | - return $this->runBasicBlockGamut($text); |
|
| 445 | - } |
|
| 444 | + return $this->runBasicBlockGamut($text); |
|
| 445 | + } |
|
| 446 | 446 | |
| 447 | - protected function runBasicBlockGamut($text) { |
|
| 448 | - # |
|
| 449 | - # Run block gamut tranformations, without hashing HTML blocks. This is |
|
| 450 | - # useful when HTML blocks are known to be already hashed, like in the first |
|
| 451 | - # whole-document pass. |
|
| 452 | - # |
|
| 453 | - foreach ($this->block_gamut as $method => $priority) { |
|
| 454 | - $text = $this->$method($text); |
|
| 455 | - } |
|
| 447 | + protected function runBasicBlockGamut($text) { |
|
| 448 | + # |
|
| 449 | + # Run block gamut tranformations, without hashing HTML blocks. This is |
|
| 450 | + # useful when HTML blocks are known to be already hashed, like in the first |
|
| 451 | + # whole-document pass. |
|
| 452 | + # |
|
| 453 | + foreach ($this->block_gamut as $method => $priority) { |
|
| 454 | + $text = $this->$method($text); |
|
| 455 | + } |
|
| 456 | 456 | |
| 457 | - # Finally form paragraph and restore hashed blocks. |
|
| 458 | - $text = $this->formParagraphs($text); |
|
| 457 | + # Finally form paragraph and restore hashed blocks. |
|
| 458 | + $text = $this->formParagraphs($text); |
|
| 459 | 459 | |
| 460 | - return $text; |
|
| 461 | - } |
|
| 460 | + return $text; |
|
| 461 | + } |
|
| 462 | 462 | |
| 463 | 463 | |
| 464 | - protected function doHorizontalRules($text) { |
|
| 465 | - # Do Horizontal Rules: |
|
| 466 | - return preg_replace( |
|
| 467 | - '{ |
|
| 464 | + protected function doHorizontalRules($text) { |
|
| 465 | + # Do Horizontal Rules: |
|
| 466 | + return preg_replace( |
|
| 467 | + '{ |
|
| 468 | 468 | ^[ ]{0,3} # Leading space |
| 469 | 469 | ([-*_]) # $1: First marker |
| 470 | 470 | (?> # Repeated marker group |
@@ -474,68 +474,68 @@ discard block |
||
| 474 | 474 | [ ]* # Tailing spaces |
| 475 | 475 | $ # End of line. |
| 476 | 476 | }mx', |
| 477 | - "\n".$this->hashBlock("<hr$this->empty_element_suffix")."\n", |
|
| 478 | - $text); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - protected $span_gamut = array( |
|
| 483 | - # |
|
| 484 | - # These are all the transformations that occur *within* block-level |
|
| 485 | - # tags like paragraphs, headers, and list items. |
|
| 486 | - # |
|
| 487 | - # Process character escapes, code spans, and inline HTML |
|
| 488 | - # in one shot. |
|
| 489 | - "parseSpan" => -30, |
|
| 490 | - |
|
| 491 | - # Process anchor and image tags. Images must come first, |
|
| 492 | - # because ![foo][f] looks like an anchor. |
|
| 493 | - "doImages" => 10, |
|
| 494 | - "doAnchors" => 20, |
|
| 477 | + "\n".$this->hashBlock("<hr$this->empty_element_suffix")."\n", |
|
| 478 | + $text); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + protected $span_gamut = array( |
|
| 483 | + # |
|
| 484 | + # These are all the transformations that occur *within* block-level |
|
| 485 | + # tags like paragraphs, headers, and list items. |
|
| 486 | + # |
|
| 487 | + # Process character escapes, code spans, and inline HTML |
|
| 488 | + # in one shot. |
|
| 489 | + "parseSpan" => -30, |
|
| 490 | + |
|
| 491 | + # Process anchor and image tags. Images must come first, |
|
| 492 | + # because ![foo][f] looks like an anchor. |
|
| 493 | + "doImages" => 10, |
|
| 494 | + "doAnchors" => 20, |
|
| 495 | 495 | |
| 496 | - # Make links out of things like `<http://example.com/>` |
|
| 497 | - # Must come after doAnchors, because you can use < and > |
|
| 498 | - # delimiters in inline links like [this](<url>). |
|
| 499 | - "doAutoLinks" => 30, |
|
| 500 | - "encodeAmpsAndAngles" => 40, |
|
| 501 | - |
|
| 502 | - "doItalicsAndBold" => 50, |
|
| 503 | - "doHardBreaks" => 60, |
|
| 504 | - ); |
|
| 505 | - |
|
| 506 | - protected function runSpanGamut($text) { |
|
| 507 | - # |
|
| 508 | - # Run span gamut tranformations. |
|
| 509 | - # |
|
| 510 | - foreach ($this->span_gamut as $method => $priority) { |
|
| 511 | - $text = $this->$method($text); |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - return $text; |
|
| 515 | - } |
|
| 496 | + # Make links out of things like `<http://example.com/>` |
|
| 497 | + # Must come after doAnchors, because you can use < and > |
|
| 498 | + # delimiters in inline links like [this](<url>). |
|
| 499 | + "doAutoLinks" => 30, |
|
| 500 | + "encodeAmpsAndAngles" => 40, |
|
| 501 | + |
|
| 502 | + "doItalicsAndBold" => 50, |
|
| 503 | + "doHardBreaks" => 60, |
|
| 504 | + ); |
|
| 505 | + |
|
| 506 | + protected function runSpanGamut($text) { |
|
| 507 | + # |
|
| 508 | + # Run span gamut tranformations. |
|
| 509 | + # |
|
| 510 | + foreach ($this->span_gamut as $method => $priority) { |
|
| 511 | + $text = $this->$method($text); |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + return $text; |
|
| 515 | + } |
|
| 516 | 516 | |
| 517 | 517 | |
| 518 | - protected function doHardBreaks($text) { |
|
| 519 | - # Do hard breaks: |
|
| 520 | - return preg_replace_callback('/ {2,}\n/', |
|
| 521 | - array($this, '_doHardBreaks_callback'), $text); |
|
| 522 | - } |
|
| 523 | - protected function _doHardBreaks_callback($matches) { |
|
| 524 | - return $this->hashPart("<br$this->empty_element_suffix\n"); |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - protected function doAnchors($text) { |
|
| 529 | - # |
|
| 530 | - # Turn Markdown link shortcuts into XHTML <a> tags. |
|
| 531 | - # |
|
| 532 | - if ($this->in_anchor) return $text; |
|
| 533 | - $this->in_anchor = true; |
|
| 518 | + protected function doHardBreaks($text) { |
|
| 519 | + # Do hard breaks: |
|
| 520 | + return preg_replace_callback('/ {2,}\n/', |
|
| 521 | + array($this, '_doHardBreaks_callback'), $text); |
|
| 522 | + } |
|
| 523 | + protected function _doHardBreaks_callback($matches) { |
|
| 524 | + return $this->hashPart("<br$this->empty_element_suffix\n"); |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + protected function doAnchors($text) { |
|
| 529 | + # |
|
| 530 | + # Turn Markdown link shortcuts into XHTML <a> tags. |
|
| 531 | + # |
|
| 532 | + if ($this->in_anchor) return $text; |
|
| 533 | + $this->in_anchor = true; |
|
| 534 | 534 | |
| 535 | - # |
|
| 536 | - # First, handle reference-style links: [link text] [id] |
|
| 537 | - # |
|
| 538 | - $text = preg_replace_callback('{ |
|
| 535 | + # |
|
| 536 | + # First, handle reference-style links: [link text] [id] |
|
| 537 | + # |
|
| 538 | + $text = preg_replace_callback('{ |
|
| 539 | 539 | ( # wrap whole match in $1 |
| 540 | 540 | \[ |
| 541 | 541 | ('.$this->nested_brackets_re.') # link text = $2 |
@@ -549,12 +549,12 @@ discard block |
||
| 549 | 549 | \] |
| 550 | 550 | ) |
| 551 | 551 | }xs', |
| 552 | - array($this, '_doAnchors_reference_callback'), $text); |
|
| 552 | + array($this, '_doAnchors_reference_callback'), $text); |
|
| 553 | 553 | |
| 554 | - # |
|
| 555 | - # Next, inline-style links: [link text](url "optional title") |
|
| 556 | - # |
|
| 557 | - $text = preg_replace_callback('{ |
|
| 554 | + # |
|
| 555 | + # Next, inline-style links: [link text](url "optional title") |
|
| 556 | + # |
|
| 557 | + $text = preg_replace_callback('{ |
|
| 558 | 558 | ( # wrap whole match in $1 |
| 559 | 559 | \[ |
| 560 | 560 | ('.$this->nested_brackets_re.') # link text = $2 |
@@ -576,94 +576,94 @@ discard block |
||
| 576 | 576 | \) |
| 577 | 577 | ) |
| 578 | 578 | }xs', |
| 579 | - array($this, '_doAnchors_inline_callback'), $text); |
|
| 580 | - |
|
| 581 | - # |
|
| 582 | - # Last, handle reference-style shortcuts: [link text] |
|
| 583 | - # These must come last in case you've also got [link text][1] |
|
| 584 | - # or [link text](/foo) |
|
| 585 | - # |
|
| 586 | - $text = preg_replace_callback('{ |
|
| 579 | + array($this, '_doAnchors_inline_callback'), $text); |
|
| 580 | + |
|
| 581 | + # |
|
| 582 | + # Last, handle reference-style shortcuts: [link text] |
|
| 583 | + # These must come last in case you've also got [link text][1] |
|
| 584 | + # or [link text](/foo) |
|
| 585 | + # |
|
| 586 | + $text = preg_replace_callback('{ |
|
| 587 | 587 | ( # wrap whole match in $1 |
| 588 | 588 | \[ |
| 589 | 589 | ([^\[\]]+) # link text = $2; can\'t contain [ or ] |
| 590 | 590 | \] |
| 591 | 591 | ) |
| 592 | 592 | }xs', |
| 593 | - array($this, '_doAnchors_reference_callback'), $text); |
|
| 594 | - |
|
| 595 | - $this->in_anchor = false; |
|
| 596 | - return $text; |
|
| 597 | - } |
|
| 598 | - protected function _doAnchors_reference_callback($matches) { |
|
| 599 | - $whole_match = $matches[1]; |
|
| 600 | - $link_text = $matches[2]; |
|
| 601 | - $link_id =& $matches[3]; |
|
| 602 | - |
|
| 603 | - if ($link_id == "") { |
|
| 604 | - # for shortcut links like [this][] or [this]. |
|
| 605 | - $link_id = $link_text; |
|
| 606 | - } |
|
| 593 | + array($this, '_doAnchors_reference_callback'), $text); |
|
| 594 | + |
|
| 595 | + $this->in_anchor = false; |
|
| 596 | + return $text; |
|
| 597 | + } |
|
| 598 | + protected function _doAnchors_reference_callback($matches) { |
|
| 599 | + $whole_match = $matches[1]; |
|
| 600 | + $link_text = $matches[2]; |
|
| 601 | + $link_id =& $matches[3]; |
|
| 602 | + |
|
| 603 | + if ($link_id == "") { |
|
| 604 | + # for shortcut links like [this][] or [this]. |
|
| 605 | + $link_id = $link_text; |
|
| 606 | + } |
|
| 607 | 607 | |
| 608 | - # lower-case and turn embedded newlines into spaces |
|
| 609 | - $link_id = strtolower($link_id); |
|
| 610 | - $link_id = preg_replace('{[ ]?\n}', ' ', $link_id); |
|
| 608 | + # lower-case and turn embedded newlines into spaces |
|
| 609 | + $link_id = strtolower($link_id); |
|
| 610 | + $link_id = preg_replace('{[ ]?\n}', ' ', $link_id); |
|
| 611 | 611 | |
| 612 | - if (isset($this->urls[$link_id])) { |
|
| 613 | - $url = $this->urls[$link_id]; |
|
| 614 | - $url = $this->encodeURLAttribute($url); |
|
| 612 | + if (isset($this->urls[$link_id])) { |
|
| 613 | + $url = $this->urls[$link_id]; |
|
| 614 | + $url = $this->encodeURLAttribute($url); |
|
| 615 | 615 | |
| 616 | - $result = "<a href=\"$url\""; |
|
| 617 | - if ( isset( $this->titles[$link_id] ) ) { |
|
| 618 | - $title = $this->titles[$link_id]; |
|
| 619 | - $title = $this->encodeAttribute($title); |
|
| 620 | - $result .= " title=\"$title\""; |
|
| 621 | - } |
|
| 616 | + $result = "<a href=\"$url\""; |
|
| 617 | + if ( isset( $this->titles[$link_id] ) ) { |
|
| 618 | + $title = $this->titles[$link_id]; |
|
| 619 | + $title = $this->encodeAttribute($title); |
|
| 620 | + $result .= " title=\"$title\""; |
|
| 621 | + } |
|
| 622 | 622 | |
| 623 | - $link_text = $this->runSpanGamut($link_text); |
|
| 624 | - $result .= ">$link_text</a>"; |
|
| 625 | - $result = $this->hashPart($result); |
|
| 626 | - } |
|
| 627 | - else { |
|
| 628 | - $result = $whole_match; |
|
| 629 | - } |
|
| 630 | - return $result; |
|
| 631 | - } |
|
| 632 | - protected function _doAnchors_inline_callback($matches) { |
|
| 633 | - $whole_match = $matches[1]; |
|
| 634 | - $link_text = $this->runSpanGamut($matches[2]); |
|
| 635 | - $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 636 | - $title =& $matches[7]; |
|
| 637 | - |
|
| 638 | - // if the URL was of the form <s p a c e s> it got caught by the HTML |
|
| 639 | - // tag parser and hashed. Need to reverse the process before using the URL. |
|
| 640 | - $unhashed = $this->unhash($url); |
|
| 641 | - if ($unhashed != $url) |
|
| 642 | - $url = preg_replace('/^<(.*)>$/', '\1', $unhashed); |
|
| 643 | - |
|
| 644 | - $url = $this->encodeURLAttribute($url); |
|
| 645 | - |
|
| 646 | - $result = "<a href=\"$url\""; |
|
| 647 | - if (isset($title)) { |
|
| 648 | - $title = $this->encodeAttribute($title); |
|
| 649 | - $result .= " title=\"$title\""; |
|
| 650 | - } |
|
| 623 | + $link_text = $this->runSpanGamut($link_text); |
|
| 624 | + $result .= ">$link_text</a>"; |
|
| 625 | + $result = $this->hashPart($result); |
|
| 626 | + } |
|
| 627 | + else { |
|
| 628 | + $result = $whole_match; |
|
| 629 | + } |
|
| 630 | + return $result; |
|
| 631 | + } |
|
| 632 | + protected function _doAnchors_inline_callback($matches) { |
|
| 633 | + $whole_match = $matches[1]; |
|
| 634 | + $link_text = $this->runSpanGamut($matches[2]); |
|
| 635 | + $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 636 | + $title =& $matches[7]; |
|
| 637 | + |
|
| 638 | + // if the URL was of the form <s p a c e s> it got caught by the HTML |
|
| 639 | + // tag parser and hashed. Need to reverse the process before using the URL. |
|
| 640 | + $unhashed = $this->unhash($url); |
|
| 641 | + if ($unhashed != $url) |
|
| 642 | + $url = preg_replace('/^<(.*)>$/', '\1', $unhashed); |
|
| 643 | + |
|
| 644 | + $url = $this->encodeURLAttribute($url); |
|
| 645 | + |
|
| 646 | + $result = "<a href=\"$url\""; |
|
| 647 | + if (isset($title)) { |
|
| 648 | + $title = $this->encodeAttribute($title); |
|
| 649 | + $result .= " title=\"$title\""; |
|
| 650 | + } |
|
| 651 | 651 | |
| 652 | - $link_text = $this->runSpanGamut($link_text); |
|
| 653 | - $result .= ">$link_text</a>"; |
|
| 652 | + $link_text = $this->runSpanGamut($link_text); |
|
| 653 | + $result .= ">$link_text</a>"; |
|
| 654 | 654 | |
| 655 | - return $this->hashPart($result); |
|
| 656 | - } |
|
| 655 | + return $this->hashPart($result); |
|
| 656 | + } |
|
| 657 | 657 | |
| 658 | 658 | |
| 659 | - protected function doImages($text) { |
|
| 660 | - # |
|
| 661 | - # Turn Markdown image shortcuts into <img> tags. |
|
| 662 | - # |
|
| 663 | - # |
|
| 664 | - # First, handle reference-style labeled images: ![alt text][id] |
|
| 665 | - # |
|
| 666 | - $text = preg_replace_callback('{ |
|
| 659 | + protected function doImages($text) { |
|
| 660 | + # |
|
| 661 | + # Turn Markdown image shortcuts into <img> tags. |
|
| 662 | + # |
|
| 663 | + # |
|
| 664 | + # First, handle reference-style labeled images: ![alt text][id] |
|
| 665 | + # |
|
| 666 | + $text = preg_replace_callback('{ |
|
| 667 | 667 | ( # wrap whole match in $1 |
| 668 | 668 | !\[ |
| 669 | 669 | ('.$this->nested_brackets_re.') # alt text = $2 |
@@ -678,13 +678,13 @@ discard block |
||
| 678 | 678 | |
| 679 | 679 | ) |
| 680 | 680 | }xs', |
| 681 | - array($this, '_doImages_reference_callback'), $text); |
|
| 681 | + array($this, '_doImages_reference_callback'), $text); |
|
| 682 | 682 | |
| 683 | - # |
|
| 684 | - # Next, handle inline images:  |
|
| 685 | - # Don't forget: encode * and _ |
|
| 686 | - # |
|
| 687 | - $text = preg_replace_callback('{ |
|
| 683 | + # |
|
| 684 | + # Next, handle inline images:  |
|
| 685 | + # Don't forget: encode * and _ |
|
| 686 | + # |
|
| 687 | + $text = preg_replace_callback('{ |
|
| 688 | 688 | ( # wrap whole match in $1 |
| 689 | 689 | !\[ |
| 690 | 690 | ('.$this->nested_brackets_re.') # alt text = $2 |
@@ -707,76 +707,76 @@ discard block |
||
| 707 | 707 | \) |
| 708 | 708 | ) |
| 709 | 709 | }xs', |
| 710 | - array($this, '_doImages_inline_callback'), $text); |
|
| 711 | - |
|
| 712 | - return $text; |
|
| 713 | - } |
|
| 714 | - protected function _doImages_reference_callback($matches) { |
|
| 715 | - $whole_match = $matches[1]; |
|
| 716 | - $alt_text = $matches[2]; |
|
| 717 | - $link_id = strtolower($matches[3]); |
|
| 718 | - |
|
| 719 | - if ($link_id == "") { |
|
| 720 | - $link_id = strtolower($alt_text); # for shortcut links like ![this][]. |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - $alt_text = $this->encodeAttribute($alt_text); |
|
| 724 | - if (isset($this->urls[$link_id])) { |
|
| 725 | - $url = $this->encodeURLAttribute($this->urls[$link_id]); |
|
| 726 | - $result = "<img src=\"$url\" alt=\"$alt_text\""; |
|
| 727 | - if (isset($this->titles[$link_id])) { |
|
| 728 | - $title = $this->titles[$link_id]; |
|
| 729 | - $title = $this->encodeAttribute($title); |
|
| 730 | - $result .= " title=\"$title\""; |
|
| 731 | - } |
|
| 732 | - $result .= $this->empty_element_suffix; |
|
| 733 | - $result = $this->hashPart($result); |
|
| 734 | - } |
|
| 735 | - else { |
|
| 736 | - # If there's no such link ID, leave intact: |
|
| 737 | - $result = $whole_match; |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - return $result; |
|
| 741 | - } |
|
| 742 | - protected function _doImages_inline_callback($matches) { |
|
| 743 | - $whole_match = $matches[1]; |
|
| 744 | - $alt_text = $matches[2]; |
|
| 745 | - $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 746 | - $title =& $matches[7]; |
|
| 747 | - |
|
| 748 | - $alt_text = $this->encodeAttribute($alt_text); |
|
| 749 | - $url = $this->encodeURLAttribute($url); |
|
| 750 | - $result = "<img src=\"$url\" alt=\"$alt_text\""; |
|
| 751 | - if (isset($title)) { |
|
| 752 | - $title = $this->encodeAttribute($title); |
|
| 753 | - $result .= " title=\"$title\""; # $title already quoted |
|
| 754 | - } |
|
| 755 | - $result .= $this->empty_element_suffix; |
|
| 756 | - |
|
| 757 | - return $this->hashPart($result); |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - |
|
| 761 | - protected function doHeaders($text) { |
|
| 762 | - # Setext-style headers: |
|
| 763 | - # Header 1 |
|
| 764 | - # ======== |
|
| 765 | - # |
|
| 766 | - # Header 2 |
|
| 767 | - # -------- |
|
| 768 | - # |
|
| 769 | - $text = preg_replace_callback('{ ^(.+?)[ ]*\n(=+|-+)[ ]*\n+ }mx', |
|
| 770 | - array($this, '_doHeaders_callback_setext'), $text); |
|
| 771 | - |
|
| 772 | - # atx-style headers: |
|
| 773 | - # # Header 1 |
|
| 774 | - # ## Header 2 |
|
| 775 | - # ## Header 2 with closing hashes ## |
|
| 776 | - # ... |
|
| 777 | - # ###### Header 6 |
|
| 778 | - # |
|
| 779 | - $text = preg_replace_callback('{ |
|
| 710 | + array($this, '_doImages_inline_callback'), $text); |
|
| 711 | + |
|
| 712 | + return $text; |
|
| 713 | + } |
|
| 714 | + protected function _doImages_reference_callback($matches) { |
|
| 715 | + $whole_match = $matches[1]; |
|
| 716 | + $alt_text = $matches[2]; |
|
| 717 | + $link_id = strtolower($matches[3]); |
|
| 718 | + |
|
| 719 | + if ($link_id == "") { |
|
| 720 | + $link_id = strtolower($alt_text); # for shortcut links like ![this][]. |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + $alt_text = $this->encodeAttribute($alt_text); |
|
| 724 | + if (isset($this->urls[$link_id])) { |
|
| 725 | + $url = $this->encodeURLAttribute($this->urls[$link_id]); |
|
| 726 | + $result = "<img src=\"$url\" alt=\"$alt_text\""; |
|
| 727 | + if (isset($this->titles[$link_id])) { |
|
| 728 | + $title = $this->titles[$link_id]; |
|
| 729 | + $title = $this->encodeAttribute($title); |
|
| 730 | + $result .= " title=\"$title\""; |
|
| 731 | + } |
|
| 732 | + $result .= $this->empty_element_suffix; |
|
| 733 | + $result = $this->hashPart($result); |
|
| 734 | + } |
|
| 735 | + else { |
|
| 736 | + # If there's no such link ID, leave intact: |
|
| 737 | + $result = $whole_match; |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + return $result; |
|
| 741 | + } |
|
| 742 | + protected function _doImages_inline_callback($matches) { |
|
| 743 | + $whole_match = $matches[1]; |
|
| 744 | + $alt_text = $matches[2]; |
|
| 745 | + $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 746 | + $title =& $matches[7]; |
|
| 747 | + |
|
| 748 | + $alt_text = $this->encodeAttribute($alt_text); |
|
| 749 | + $url = $this->encodeURLAttribute($url); |
|
| 750 | + $result = "<img src=\"$url\" alt=\"$alt_text\""; |
|
| 751 | + if (isset($title)) { |
|
| 752 | + $title = $this->encodeAttribute($title); |
|
| 753 | + $result .= " title=\"$title\""; # $title already quoted |
|
| 754 | + } |
|
| 755 | + $result .= $this->empty_element_suffix; |
|
| 756 | + |
|
| 757 | + return $this->hashPart($result); |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + |
|
| 761 | + protected function doHeaders($text) { |
|
| 762 | + # Setext-style headers: |
|
| 763 | + # Header 1 |
|
| 764 | + # ======== |
|
| 765 | + # |
|
| 766 | + # Header 2 |
|
| 767 | + # -------- |
|
| 768 | + # |
|
| 769 | + $text = preg_replace_callback('{ ^(.+?)[ ]*\n(=+|-+)[ ]*\n+ }mx', |
|
| 770 | + array($this, '_doHeaders_callback_setext'), $text); |
|
| 771 | + |
|
| 772 | + # atx-style headers: |
|
| 773 | + # # Header 1 |
|
| 774 | + # ## Header 2 |
|
| 775 | + # ## Header 2 with closing hashes ## |
|
| 776 | + # ... |
|
| 777 | + # ###### Header 6 |
|
| 778 | + # |
|
| 779 | + $text = preg_replace_callback('{ |
|
| 780 | 780 | ^(\#{1,6}) # $1 = string of #\'s |
| 781 | 781 | [ ]* |
| 782 | 782 | (.+?) # $2 = Header text |
@@ -784,69 +784,69 @@ discard block |
||
| 784 | 784 | \#* # optional closing #\'s (not counted) |
| 785 | 785 | \n+ |
| 786 | 786 | }xm', |
| 787 | - array($this, '_doHeaders_callback_atx'), $text); |
|
| 787 | + array($this, '_doHeaders_callback_atx'), $text); |
|
| 788 | 788 | |
| 789 | - return $text; |
|
| 790 | - } |
|
| 789 | + return $text; |
|
| 790 | + } |
|
| 791 | 791 | |
| 792 | - protected function _doHeaders_callback_setext($matches) { |
|
| 793 | - # Terrible hack to check we haven't found an empty list item. |
|
| 794 | - if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) |
|
| 795 | - return $matches[0]; |
|
| 792 | + protected function _doHeaders_callback_setext($matches) { |
|
| 793 | + # Terrible hack to check we haven't found an empty list item. |
|
| 794 | + if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) |
|
| 795 | + return $matches[0]; |
|
| 796 | 796 | |
| 797 | - $level = $matches[2]{0} == '=' ? 1 : 2; |
|
| 798 | - |
|
| 799 | - # id attribute generation |
|
| 800 | - $idAtt = $this->_generateIdFromHeaderValue($matches[1]); |
|
| 801 | - |
|
| 802 | - $block = "<h$level$idAtt>".$this->runSpanGamut($matches[1])."</h$level>"; |
|
| 803 | - return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 804 | - } |
|
| 805 | - protected function _doHeaders_callback_atx($matches) { |
|
| 806 | - |
|
| 807 | - # id attribute generation |
|
| 808 | - $idAtt = $this->_generateIdFromHeaderValue($matches[2]); |
|
| 809 | - |
|
| 810 | - $level = strlen($matches[1]); |
|
| 811 | - $block = "<h$level$idAtt>".$this->runSpanGamut($matches[2])."</h$level>"; |
|
| 812 | - return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - protected function _generateIdFromHeaderValue($headerValue) { |
|
| 816 | - |
|
| 817 | - # if a header_id_func property is set, we can use it to automatically |
|
| 818 | - # generate an id attribute. |
|
| 819 | - # |
|
| 820 | - # This method returns a string in the form id="foo", or an empty string |
|
| 821 | - # otherwise. |
|
| 822 | - if (!is_callable($this->header_id_func)) { |
|
| 823 | - return ""; |
|
| 824 | - } |
|
| 825 | - $idValue = call_user_func($this->header_id_func, $headerValue); |
|
| 826 | - if (!$idValue) return ""; |
|
| 827 | - |
|
| 828 | - return ' id="' . $this->encodeAttribute($idValue) . '"'; |
|
| 829 | - |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - protected function doLists($text) { |
|
| 833 | - # |
|
| 834 | - # Form HTML ordered (numbered) and unordered (bulleted) lists. |
|
| 835 | - # |
|
| 836 | - $less_than_tab = $this->tab_width - 1; |
|
| 837 | - |
|
| 838 | - # Re-usable patterns to match list item bullets and number markers: |
|
| 839 | - $marker_ul_re = '[*+-]'; |
|
| 840 | - $marker_ol_re = '\d+[\.]'; |
|
| 841 | - |
|
| 842 | - $markers_relist = array( |
|
| 843 | - $marker_ul_re => $marker_ol_re, |
|
| 844 | - $marker_ol_re => $marker_ul_re, |
|
| 845 | - ); |
|
| 846 | - |
|
| 847 | - foreach ($markers_relist as $marker_re => $other_marker_re) { |
|
| 848 | - # Re-usable pattern to match any entirel ul or ol list: |
|
| 849 | - $whole_list_re = ' |
|
| 797 | + $level = $matches[2]{0} == '=' ? 1 : 2; |
|
| 798 | + |
|
| 799 | + # id attribute generation |
|
| 800 | + $idAtt = $this->_generateIdFromHeaderValue($matches[1]); |
|
| 801 | + |
|
| 802 | + $block = "<h$level$idAtt>".$this->runSpanGamut($matches[1])."</h$level>"; |
|
| 803 | + return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 804 | + } |
|
| 805 | + protected function _doHeaders_callback_atx($matches) { |
|
| 806 | + |
|
| 807 | + # id attribute generation |
|
| 808 | + $idAtt = $this->_generateIdFromHeaderValue($matches[2]); |
|
| 809 | + |
|
| 810 | + $level = strlen($matches[1]); |
|
| 811 | + $block = "<h$level$idAtt>".$this->runSpanGamut($matches[2])."</h$level>"; |
|
| 812 | + return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + protected function _generateIdFromHeaderValue($headerValue) { |
|
| 816 | + |
|
| 817 | + # if a header_id_func property is set, we can use it to automatically |
|
| 818 | + # generate an id attribute. |
|
| 819 | + # |
|
| 820 | + # This method returns a string in the form id="foo", or an empty string |
|
| 821 | + # otherwise. |
|
| 822 | + if (!is_callable($this->header_id_func)) { |
|
| 823 | + return ""; |
|
| 824 | + } |
|
| 825 | + $idValue = call_user_func($this->header_id_func, $headerValue); |
|
| 826 | + if (!$idValue) return ""; |
|
| 827 | + |
|
| 828 | + return ' id="' . $this->encodeAttribute($idValue) . '"'; |
|
| 829 | + |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + protected function doLists($text) { |
|
| 833 | + # |
|
| 834 | + # Form HTML ordered (numbered) and unordered (bulleted) lists. |
|
| 835 | + # |
|
| 836 | + $less_than_tab = $this->tab_width - 1; |
|
| 837 | + |
|
| 838 | + # Re-usable patterns to match list item bullets and number markers: |
|
| 839 | + $marker_ul_re = '[*+-]'; |
|
| 840 | + $marker_ol_re = '\d+[\.]'; |
|
| 841 | + |
|
| 842 | + $markers_relist = array( |
|
| 843 | + $marker_ul_re => $marker_ol_re, |
|
| 844 | + $marker_ol_re => $marker_ul_re, |
|
| 845 | + ); |
|
| 846 | + |
|
| 847 | + foreach ($markers_relist as $marker_re => $other_marker_re) { |
|
| 848 | + # Re-usable pattern to match any entirel ul or ol list: |
|
| 849 | + $whole_list_re = ' |
|
| 850 | 850 | ( # $1 = whole list |
| 851 | 851 | ( # $2 |
| 852 | 852 | ([ ]{0,'.$less_than_tab.'}) # $3 = number of spaces |
@@ -873,96 +873,96 @@ discard block |
||
| 873 | 873 | ) |
| 874 | 874 | '; // mx |
| 875 | 875 | |
| 876 | - # We use a different prefix before nested lists than top-level lists. |
|
| 877 | - # See extended comment in _ProcessListItems(). |
|
| 876 | + # We use a different prefix before nested lists than top-level lists. |
|
| 877 | + # See extended comment in _ProcessListItems(). |
|
| 878 | 878 | |
| 879 | - if ($this->list_level) { |
|
| 880 | - $text = preg_replace_callback('{ |
|
| 879 | + if ($this->list_level) { |
|
| 880 | + $text = preg_replace_callback('{ |
|
| 881 | 881 | ^ |
| 882 | 882 | '.$whole_list_re.' |
| 883 | 883 | }mx', |
| 884 | - array($this, '_doLists_callback'), $text); |
|
| 885 | - } |
|
| 886 | - else { |
|
| 887 | - $text = preg_replace_callback('{ |
|
| 884 | + array($this, '_doLists_callback'), $text); |
|
| 885 | + } |
|
| 886 | + else { |
|
| 887 | + $text = preg_replace_callback('{ |
|
| 888 | 888 | (?:(?<=\n)\n|\A\n?) # Must eat the newline |
| 889 | 889 | '.$whole_list_re.' |
| 890 | 890 | }mx', |
| 891 | - array($this, '_doLists_callback'), $text); |
|
| 892 | - } |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - return $text; |
|
| 896 | - } |
|
| 897 | - protected function _doLists_callback($matches) { |
|
| 898 | - # Re-usable patterns to match list item bullets and number markers: |
|
| 899 | - $marker_ul_re = '[*+-]'; |
|
| 900 | - $marker_ol_re = '\d+[\.]'; |
|
| 901 | - $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; |
|
| 902 | - $marker_ol_start_re = '[0-9]+'; |
|
| 903 | - |
|
| 904 | - $list = $matches[1]; |
|
| 905 | - $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol"; |
|
| 906 | - |
|
| 907 | - $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re ); |
|
| 908 | - |
|
| 909 | - $list .= "\n"; |
|
| 910 | - $result = $this->processListItems($list, $marker_any_re); |
|
| 911 | - |
|
| 912 | - $ol_start = 1; |
|
| 913 | - if ($this->enhanced_ordered_list) { |
|
| 914 | - # Get the start number for ordered list. |
|
| 915 | - if ($list_type == 'ol') { |
|
| 916 | - $ol_start_array = array(); |
|
| 917 | - $ol_start_check = preg_match("/$marker_ol_start_re/", $matches[4], $ol_start_array); |
|
| 918 | - if ($ol_start_check){ |
|
| 919 | - $ol_start = $ol_start_array[0]; |
|
| 920 | - } |
|
| 921 | - } |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - if ($ol_start > 1 && $list_type == 'ol'){ |
|
| 925 | - $result = $this->hashBlock("<$list_type start=\"$ol_start\">\n" . $result . "</$list_type>"); |
|
| 926 | - } else { |
|
| 927 | - $result = $this->hashBlock("<$list_type>\n" . $result . "</$list_type>"); |
|
| 928 | - } |
|
| 929 | - return "\n". $result ."\n\n"; |
|
| 930 | - } |
|
| 931 | - |
|
| 932 | - protected $list_level = 0; |
|
| 933 | - |
|
| 934 | - protected function processListItems($list_str, $marker_any_re) { |
|
| 935 | - # |
|
| 936 | - # Process the contents of a single ordered or unordered list, splitting it |
|
| 937 | - # into individual list items. |
|
| 938 | - # |
|
| 939 | - # The $this->list_level global keeps track of when we're inside a list. |
|
| 940 | - # Each time we enter a list, we increment it; when we leave a list, |
|
| 941 | - # we decrement. If it's zero, we're not in a list anymore. |
|
| 942 | - # |
|
| 943 | - # We do this because when we're not inside a list, we want to treat |
|
| 944 | - # something like this: |
|
| 945 | - # |
|
| 946 | - # I recommend upgrading to version |
|
| 947 | - # 8. Oops, now this line is treated |
|
| 948 | - # as a sub-list. |
|
| 949 | - # |
|
| 950 | - # As a single paragraph, despite the fact that the second line starts |
|
| 951 | - # with a digit-period-space sequence. |
|
| 952 | - # |
|
| 953 | - # Whereas when we're inside a list (or sub-list), that line will be |
|
| 954 | - # treated as the start of a sub-list. What a kludge, huh? This is |
|
| 955 | - # an aspect of Markdown's syntax that's hard to parse perfectly |
|
| 956 | - # without resorting to mind-reading. Perhaps the solution is to |
|
| 957 | - # change the syntax rules such that sub-lists must start with a |
|
| 958 | - # starting cardinal number; e.g. "1." or "a.". |
|
| 891 | + array($this, '_doLists_callback'), $text); |
|
| 892 | + } |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + return $text; |
|
| 896 | + } |
|
| 897 | + protected function _doLists_callback($matches) { |
|
| 898 | + # Re-usable patterns to match list item bullets and number markers: |
|
| 899 | + $marker_ul_re = '[*+-]'; |
|
| 900 | + $marker_ol_re = '\d+[\.]'; |
|
| 901 | + $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; |
|
| 902 | + $marker_ol_start_re = '[0-9]+'; |
|
| 903 | + |
|
| 904 | + $list = $matches[1]; |
|
| 905 | + $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol"; |
|
| 906 | + |
|
| 907 | + $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re ); |
|
| 908 | + |
|
| 909 | + $list .= "\n"; |
|
| 910 | + $result = $this->processListItems($list, $marker_any_re); |
|
| 911 | + |
|
| 912 | + $ol_start = 1; |
|
| 913 | + if ($this->enhanced_ordered_list) { |
|
| 914 | + # Get the start number for ordered list. |
|
| 915 | + if ($list_type == 'ol') { |
|
| 916 | + $ol_start_array = array(); |
|
| 917 | + $ol_start_check = preg_match("/$marker_ol_start_re/", $matches[4], $ol_start_array); |
|
| 918 | + if ($ol_start_check){ |
|
| 919 | + $ol_start = $ol_start_array[0]; |
|
| 920 | + } |
|
| 921 | + } |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + if ($ol_start > 1 && $list_type == 'ol'){ |
|
| 925 | + $result = $this->hashBlock("<$list_type start=\"$ol_start\">\n" . $result . "</$list_type>"); |
|
| 926 | + } else { |
|
| 927 | + $result = $this->hashBlock("<$list_type>\n" . $result . "</$list_type>"); |
|
| 928 | + } |
|
| 929 | + return "\n". $result ."\n\n"; |
|
| 930 | + } |
|
| 931 | + |
|
| 932 | + protected $list_level = 0; |
|
| 933 | + |
|
| 934 | + protected function processListItems($list_str, $marker_any_re) { |
|
| 935 | + # |
|
| 936 | + # Process the contents of a single ordered or unordered list, splitting it |
|
| 937 | + # into individual list items. |
|
| 938 | + # |
|
| 939 | + # The $this->list_level global keeps track of when we're inside a list. |
|
| 940 | + # Each time we enter a list, we increment it; when we leave a list, |
|
| 941 | + # we decrement. If it's zero, we're not in a list anymore. |
|
| 942 | + # |
|
| 943 | + # We do this because when we're not inside a list, we want to treat |
|
| 944 | + # something like this: |
|
| 945 | + # |
|
| 946 | + # I recommend upgrading to version |
|
| 947 | + # 8. Oops, now this line is treated |
|
| 948 | + # as a sub-list. |
|
| 949 | + # |
|
| 950 | + # As a single paragraph, despite the fact that the second line starts |
|
| 951 | + # with a digit-period-space sequence. |
|
| 952 | + # |
|
| 953 | + # Whereas when we're inside a list (or sub-list), that line will be |
|
| 954 | + # treated as the start of a sub-list. What a kludge, huh? This is |
|
| 955 | + # an aspect of Markdown's syntax that's hard to parse perfectly |
|
| 956 | + # without resorting to mind-reading. Perhaps the solution is to |
|
| 957 | + # change the syntax rules such that sub-lists must start with a |
|
| 958 | + # starting cardinal number; e.g. "1." or "a.". |
|
| 959 | 959 | |
| 960 | - $this->list_level++; |
|
| 960 | + $this->list_level++; |
|
| 961 | 961 | |
| 962 | - # trim trailing blank lines: |
|
| 963 | - $list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str); |
|
| 962 | + # trim trailing blank lines: |
|
| 963 | + $list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str); |
|
| 964 | 964 | |
| 965 | - $list_str = preg_replace_callback('{ |
|
| 965 | + $list_str = preg_replace_callback('{ |
|
| 966 | 966 | (\n)? # leading line = $1 |
| 967 | 967 | (^[ ]*) # leading whitespace = $2 |
| 968 | 968 | ('.$marker_any_re.' # list marker and space = $3 |
@@ -972,41 +972,41 @@ discard block |
||
| 972 | 972 | (?:(\n+(?=\n))|\n) # tailing blank line = $5 |
| 973 | 973 | (?= \n* (\z | \2 ('.$marker_any_re.') (?:[ ]+|(?=\n)))) |
| 974 | 974 | }xm', |
| 975 | - array($this, '_processListItems_callback'), $list_str); |
|
| 976 | - |
|
| 977 | - $this->list_level--; |
|
| 978 | - return $list_str; |
|
| 979 | - } |
|
| 980 | - protected function _processListItems_callback($matches) { |
|
| 981 | - $item = $matches[4]; |
|
| 982 | - $leading_line =& $matches[1]; |
|
| 983 | - $leading_space =& $matches[2]; |
|
| 984 | - $marker_space = $matches[3]; |
|
| 985 | - $tailing_blank_line =& $matches[5]; |
|
| 986 | - |
|
| 987 | - if ($leading_line || $tailing_blank_line || |
|
| 988 | - preg_match('/\n{2,}/', $item)) |
|
| 989 | - { |
|
| 990 | - # Replace marker with the appropriate whitespace indentation |
|
| 991 | - $item = $leading_space . str_repeat(' ', strlen($marker_space)) . $item; |
|
| 992 | - $item = $this->runBlockGamut($this->outdent($item)."\n"); |
|
| 993 | - } |
|
| 994 | - else { |
|
| 995 | - # Recursion for sub-lists: |
|
| 996 | - $item = $this->doLists($this->outdent($item)); |
|
| 997 | - $item = preg_replace('/\n+$/', '', $item); |
|
| 998 | - $item = $this->runSpanGamut($item); |
|
| 999 | - } |
|
| 1000 | - |
|
| 1001 | - return "<li>" . $item . "</li>\n"; |
|
| 1002 | - } |
|
| 1003 | - |
|
| 1004 | - |
|
| 1005 | - protected function doCodeBlocks($text) { |
|
| 1006 | - # |
|
| 1007 | - # Process Markdown `<pre><code>` blocks. |
|
| 1008 | - # |
|
| 1009 | - $text = preg_replace_callback('{ |
|
| 975 | + array($this, '_processListItems_callback'), $list_str); |
|
| 976 | + |
|
| 977 | + $this->list_level--; |
|
| 978 | + return $list_str; |
|
| 979 | + } |
|
| 980 | + protected function _processListItems_callback($matches) { |
|
| 981 | + $item = $matches[4]; |
|
| 982 | + $leading_line =& $matches[1]; |
|
| 983 | + $leading_space =& $matches[2]; |
|
| 984 | + $marker_space = $matches[3]; |
|
| 985 | + $tailing_blank_line =& $matches[5]; |
|
| 986 | + |
|
| 987 | + if ($leading_line || $tailing_blank_line || |
|
| 988 | + preg_match('/\n{2,}/', $item)) |
|
| 989 | + { |
|
| 990 | + # Replace marker with the appropriate whitespace indentation |
|
| 991 | + $item = $leading_space . str_repeat(' ', strlen($marker_space)) . $item; |
|
| 992 | + $item = $this->runBlockGamut($this->outdent($item)."\n"); |
|
| 993 | + } |
|
| 994 | + else { |
|
| 995 | + # Recursion for sub-lists: |
|
| 996 | + $item = $this->doLists($this->outdent($item)); |
|
| 997 | + $item = preg_replace('/\n+$/', '', $item); |
|
| 998 | + $item = $this->runSpanGamut($item); |
|
| 999 | + } |
|
| 1000 | + |
|
| 1001 | + return "<li>" . $item . "</li>\n"; |
|
| 1002 | + } |
|
| 1003 | + |
|
| 1004 | + |
|
| 1005 | + protected function doCodeBlocks($text) { |
|
| 1006 | + # |
|
| 1007 | + # Process Markdown `<pre><code>` blocks. |
|
| 1008 | + # |
|
| 1009 | + $text = preg_replace_callback('{ |
|
| 1010 | 1010 | (?:\n\n|\A\n?) |
| 1011 | 1011 | ( # $1 = the code block -- one or more lines, starting with a space/tab |
| 1012 | 1012 | (?> |
@@ -1016,197 +1016,197 @@ discard block |
||
| 1016 | 1016 | ) |
| 1017 | 1017 | ((?=^[ ]{0,'.$this->tab_width.'}\S)|\Z) # Lookahead for non-space at line-start, or end of doc |
| 1018 | 1018 | }xm', |
| 1019 | - array($this, '_doCodeBlocks_callback'), $text); |
|
| 1020 | - |
|
| 1021 | - return $text; |
|
| 1022 | - } |
|
| 1023 | - protected function _doCodeBlocks_callback($matches) { |
|
| 1024 | - $codeblock = $matches[1]; |
|
| 1025 | - |
|
| 1026 | - $codeblock = $this->outdent($codeblock); |
|
| 1027 | - $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); |
|
| 1028 | - |
|
| 1029 | - # trim leading newlines and trailing newlines |
|
| 1030 | - $codeblock = preg_replace('/\A\n+|\n+\z/', '', $codeblock); |
|
| 1031 | - |
|
| 1032 | - $codeblock = "<pre><code>$codeblock\n</code></pre>"; |
|
| 1033 | - return "\n\n".$this->hashBlock($codeblock)."\n\n"; |
|
| 1034 | - } |
|
| 1035 | - |
|
| 1036 | - |
|
| 1037 | - protected function makeCodeSpan($code) { |
|
| 1038 | - # |
|
| 1039 | - # Create a code span markup for $code. Called from handleSpanToken. |
|
| 1040 | - # |
|
| 1041 | - $code = htmlspecialchars(trim($code), ENT_NOQUOTES); |
|
| 1042 | - return $this->hashPart("<code>$code</code>"); |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - |
|
| 1046 | - protected $em_relist = array( |
|
| 1047 | - '' => '(?:(?<!\*)\*(?!\*)|(?<!_)_(?!_))(?![\.,:;]?\s)', |
|
| 1048 | - '*' => '(?<![\s*])\*(?!\*)', |
|
| 1049 | - '_' => '(?<![\s_])_(?!_)', |
|
| 1050 | - ); |
|
| 1051 | - protected $strong_relist = array( |
|
| 1052 | - '' => '(?:(?<!\*)\*\*(?!\*)|(?<!_)__(?!_))(?![\.,:;]?\s)', |
|
| 1053 | - '**' => '(?<![\s*])\*\*(?!\*)', |
|
| 1054 | - '__' => '(?<![\s_])__(?!_)', |
|
| 1055 | - ); |
|
| 1056 | - protected $em_strong_relist = array( |
|
| 1057 | - '' => '(?:(?<!\*)\*\*\*(?!\*)|(?<!_)___(?!_))(?![\.,:;]?\s)', |
|
| 1058 | - '***' => '(?<![\s*])\*\*\*(?!\*)', |
|
| 1059 | - '___' => '(?<![\s_])___(?!_)', |
|
| 1060 | - ); |
|
| 1061 | - protected $em_strong_prepared_relist; |
|
| 1019 | + array($this, '_doCodeBlocks_callback'), $text); |
|
| 1020 | + |
|
| 1021 | + return $text; |
|
| 1022 | + } |
|
| 1023 | + protected function _doCodeBlocks_callback($matches) { |
|
| 1024 | + $codeblock = $matches[1]; |
|
| 1025 | + |
|
| 1026 | + $codeblock = $this->outdent($codeblock); |
|
| 1027 | + $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); |
|
| 1028 | + |
|
| 1029 | + # trim leading newlines and trailing newlines |
|
| 1030 | + $codeblock = preg_replace('/\A\n+|\n+\z/', '', $codeblock); |
|
| 1031 | + |
|
| 1032 | + $codeblock = "<pre><code>$codeblock\n</code></pre>"; |
|
| 1033 | + return "\n\n".$this->hashBlock($codeblock)."\n\n"; |
|
| 1034 | + } |
|
| 1035 | + |
|
| 1036 | + |
|
| 1037 | + protected function makeCodeSpan($code) { |
|
| 1038 | + # |
|
| 1039 | + # Create a code span markup for $code. Called from handleSpanToken. |
|
| 1040 | + # |
|
| 1041 | + $code = htmlspecialchars(trim($code), ENT_NOQUOTES); |
|
| 1042 | + return $this->hashPart("<code>$code</code>"); |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + |
|
| 1046 | + protected $em_relist = array( |
|
| 1047 | + '' => '(?:(?<!\*)\*(?!\*)|(?<!_)_(?!_))(?![\.,:;]?\s)', |
|
| 1048 | + '*' => '(?<![\s*])\*(?!\*)', |
|
| 1049 | + '_' => '(?<![\s_])_(?!_)', |
|
| 1050 | + ); |
|
| 1051 | + protected $strong_relist = array( |
|
| 1052 | + '' => '(?:(?<!\*)\*\*(?!\*)|(?<!_)__(?!_))(?![\.,:;]?\s)', |
|
| 1053 | + '**' => '(?<![\s*])\*\*(?!\*)', |
|
| 1054 | + '__' => '(?<![\s_])__(?!_)', |
|
| 1055 | + ); |
|
| 1056 | + protected $em_strong_relist = array( |
|
| 1057 | + '' => '(?:(?<!\*)\*\*\*(?!\*)|(?<!_)___(?!_))(?![\.,:;]?\s)', |
|
| 1058 | + '***' => '(?<![\s*])\*\*\*(?!\*)', |
|
| 1059 | + '___' => '(?<![\s_])___(?!_)', |
|
| 1060 | + ); |
|
| 1061 | + protected $em_strong_prepared_relist; |
|
| 1062 | 1062 | |
| 1063 | - protected function prepareItalicsAndBold() { |
|
| 1064 | - # |
|
| 1065 | - # Prepare regular expressions for searching emphasis tokens in any |
|
| 1066 | - # context. |
|
| 1067 | - # |
|
| 1068 | - foreach ($this->em_relist as $em => $em_re) { |
|
| 1069 | - foreach ($this->strong_relist as $strong => $strong_re) { |
|
| 1070 | - # Construct list of allowed token expressions. |
|
| 1071 | - $token_relist = array(); |
|
| 1072 | - if (isset($this->em_strong_relist["$em$strong"])) { |
|
| 1073 | - $token_relist[] = $this->em_strong_relist["$em$strong"]; |
|
| 1074 | - } |
|
| 1075 | - $token_relist[] = $em_re; |
|
| 1076 | - $token_relist[] = $strong_re; |
|
| 1063 | + protected function prepareItalicsAndBold() { |
|
| 1064 | + # |
|
| 1065 | + # Prepare regular expressions for searching emphasis tokens in any |
|
| 1066 | + # context. |
|
| 1067 | + # |
|
| 1068 | + foreach ($this->em_relist as $em => $em_re) { |
|
| 1069 | + foreach ($this->strong_relist as $strong => $strong_re) { |
|
| 1070 | + # Construct list of allowed token expressions. |
|
| 1071 | + $token_relist = array(); |
|
| 1072 | + if (isset($this->em_strong_relist["$em$strong"])) { |
|
| 1073 | + $token_relist[] = $this->em_strong_relist["$em$strong"]; |
|
| 1074 | + } |
|
| 1075 | + $token_relist[] = $em_re; |
|
| 1076 | + $token_relist[] = $strong_re; |
|
| 1077 | 1077 | |
| 1078 | - # Construct master expression from list. |
|
| 1079 | - $token_re = '{('. implode('|', $token_relist) .')}'; |
|
| 1080 | - $this->em_strong_prepared_relist["$em$strong"] = $token_re; |
|
| 1081 | - } |
|
| 1082 | - } |
|
| 1083 | - } |
|
| 1078 | + # Construct master expression from list. |
|
| 1079 | + $token_re = '{('. implode('|', $token_relist) .')}'; |
|
| 1080 | + $this->em_strong_prepared_relist["$em$strong"] = $token_re; |
|
| 1081 | + } |
|
| 1082 | + } |
|
| 1083 | + } |
|
| 1084 | 1084 | |
| 1085 | - protected function doItalicsAndBold($text) { |
|
| 1086 | - $token_stack = array(''); |
|
| 1087 | - $text_stack = array(''); |
|
| 1088 | - $em = ''; |
|
| 1089 | - $strong = ''; |
|
| 1090 | - $tree_char_em = false; |
|
| 1085 | + protected function doItalicsAndBold($text) { |
|
| 1086 | + $token_stack = array(''); |
|
| 1087 | + $text_stack = array(''); |
|
| 1088 | + $em = ''; |
|
| 1089 | + $strong = ''; |
|
| 1090 | + $tree_char_em = false; |
|
| 1091 | 1091 | |
| 1092 | - while (1) { |
|
| 1093 | - # |
|
| 1094 | - # Get prepared regular expression for seraching emphasis tokens |
|
| 1095 | - # in current context. |
|
| 1096 | - # |
|
| 1097 | - $token_re = $this->em_strong_prepared_relist["$em$strong"]; |
|
| 1092 | + while (1) { |
|
| 1093 | + # |
|
| 1094 | + # Get prepared regular expression for seraching emphasis tokens |
|
| 1095 | + # in current context. |
|
| 1096 | + # |
|
| 1097 | + $token_re = $this->em_strong_prepared_relist["$em$strong"]; |
|
| 1098 | 1098 | |
| 1099 | - # |
|
| 1100 | - # Each loop iteration search for the next emphasis token. |
|
| 1101 | - # Each token is then passed to handleSpanToken. |
|
| 1102 | - # |
|
| 1103 | - $parts = preg_split($token_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 1104 | - $text_stack[0] .= $parts[0]; |
|
| 1105 | - $token =& $parts[1]; |
|
| 1106 | - $text =& $parts[2]; |
|
| 1099 | + # |
|
| 1100 | + # Each loop iteration search for the next emphasis token. |
|
| 1101 | + # Each token is then passed to handleSpanToken. |
|
| 1102 | + # |
|
| 1103 | + $parts = preg_split($token_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 1104 | + $text_stack[0] .= $parts[0]; |
|
| 1105 | + $token =& $parts[1]; |
|
| 1106 | + $text =& $parts[2]; |
|
| 1107 | 1107 | |
| 1108 | - if (empty($token)) { |
|
| 1109 | - # Reached end of text span: empty stack without emitting. |
|
| 1110 | - # any more emphasis. |
|
| 1111 | - while ($token_stack[0]) { |
|
| 1112 | - $text_stack[1] .= array_shift($token_stack); |
|
| 1113 | - $text_stack[0] .= array_shift($text_stack); |
|
| 1114 | - } |
|
| 1115 | - break; |
|
| 1116 | - } |
|
| 1108 | + if (empty($token)) { |
|
| 1109 | + # Reached end of text span: empty stack without emitting. |
|
| 1110 | + # any more emphasis. |
|
| 1111 | + while ($token_stack[0]) { |
|
| 1112 | + $text_stack[1] .= array_shift($token_stack); |
|
| 1113 | + $text_stack[0] .= array_shift($text_stack); |
|
| 1114 | + } |
|
| 1115 | + break; |
|
| 1116 | + } |
|
| 1117 | 1117 | |
| 1118 | - $token_len = strlen($token); |
|
| 1119 | - if ($tree_char_em) { |
|
| 1120 | - # Reached closing marker while inside a three-char emphasis. |
|
| 1121 | - if ($token_len == 3) { |
|
| 1122 | - # Three-char closing marker, close em and strong. |
|
| 1123 | - array_shift($token_stack); |
|
| 1124 | - $span = array_shift($text_stack); |
|
| 1125 | - $span = $this->runSpanGamut($span); |
|
| 1126 | - $span = "<strong><em>$span</em></strong>"; |
|
| 1127 | - $text_stack[0] .= $this->hashPart($span); |
|
| 1128 | - $em = ''; |
|
| 1129 | - $strong = ''; |
|
| 1130 | - } else { |
|
| 1131 | - # Other closing marker: close one em or strong and |
|
| 1132 | - # change current token state to match the other |
|
| 1133 | - $token_stack[0] = str_repeat($token{0}, 3-$token_len); |
|
| 1134 | - $tag = $token_len == 2 ? "strong" : "em"; |
|
| 1135 | - $span = $text_stack[0]; |
|
| 1136 | - $span = $this->runSpanGamut($span); |
|
| 1137 | - $span = "<$tag>$span</$tag>"; |
|
| 1138 | - $text_stack[0] = $this->hashPart($span); |
|
| 1139 | - $$tag = ''; # $$tag stands for $em or $strong |
|
| 1140 | - } |
|
| 1141 | - $tree_char_em = false; |
|
| 1142 | - } else if ($token_len == 3) { |
|
| 1143 | - if ($em) { |
|
| 1144 | - # Reached closing marker for both em and strong. |
|
| 1145 | - # Closing strong marker: |
|
| 1146 | - for ($i = 0; $i < 2; ++$i) { |
|
| 1147 | - $shifted_token = array_shift($token_stack); |
|
| 1148 | - $tag = strlen($shifted_token) == 2 ? "strong" : "em"; |
|
| 1149 | - $span = array_shift($text_stack); |
|
| 1150 | - $span = $this->runSpanGamut($span); |
|
| 1151 | - $span = "<$tag>$span</$tag>"; |
|
| 1152 | - $text_stack[0] .= $this->hashPart($span); |
|
| 1153 | - $$tag = ''; # $$tag stands for $em or $strong |
|
| 1154 | - } |
|
| 1155 | - } else { |
|
| 1156 | - # Reached opening three-char emphasis marker. Push on token |
|
| 1157 | - # stack; will be handled by the special condition above. |
|
| 1158 | - $em = $token{0}; |
|
| 1159 | - $strong = "$em$em"; |
|
| 1160 | - array_unshift($token_stack, $token); |
|
| 1161 | - array_unshift($text_stack, ''); |
|
| 1162 | - $tree_char_em = true; |
|
| 1163 | - } |
|
| 1164 | - } else if ($token_len == 2) { |
|
| 1165 | - if ($strong) { |
|
| 1166 | - # Unwind any dangling emphasis marker: |
|
| 1167 | - if (strlen($token_stack[0]) == 1) { |
|
| 1168 | - $text_stack[1] .= array_shift($token_stack); |
|
| 1169 | - $text_stack[0] .= array_shift($text_stack); |
|
| 1170 | - } |
|
| 1171 | - # Closing strong marker: |
|
| 1172 | - array_shift($token_stack); |
|
| 1173 | - $span = array_shift($text_stack); |
|
| 1174 | - $span = $this->runSpanGamut($span); |
|
| 1175 | - $span = "<strong>$span</strong>"; |
|
| 1176 | - $text_stack[0] .= $this->hashPart($span); |
|
| 1177 | - $strong = ''; |
|
| 1178 | - } else { |
|
| 1179 | - array_unshift($token_stack, $token); |
|
| 1180 | - array_unshift($text_stack, ''); |
|
| 1181 | - $strong = $token; |
|
| 1182 | - } |
|
| 1183 | - } else { |
|
| 1184 | - # Here $token_len == 1 |
|
| 1185 | - if ($em) { |
|
| 1186 | - if (strlen($token_stack[0]) == 1) { |
|
| 1187 | - # Closing emphasis marker: |
|
| 1188 | - array_shift($token_stack); |
|
| 1189 | - $span = array_shift($text_stack); |
|
| 1190 | - $span = $this->runSpanGamut($span); |
|
| 1191 | - $span = "<em>$span</em>"; |
|
| 1192 | - $text_stack[0] .= $this->hashPart($span); |
|
| 1193 | - $em = ''; |
|
| 1194 | - } else { |
|
| 1195 | - $text_stack[0] .= $token; |
|
| 1196 | - } |
|
| 1197 | - } else { |
|
| 1198 | - array_unshift($token_stack, $token); |
|
| 1199 | - array_unshift($text_stack, ''); |
|
| 1200 | - $em = $token; |
|
| 1201 | - } |
|
| 1202 | - } |
|
| 1203 | - } |
|
| 1204 | - return $text_stack[0]; |
|
| 1205 | - } |
|
| 1206 | - |
|
| 1207 | - |
|
| 1208 | - protected function doBlockQuotes($text) { |
|
| 1209 | - $text = preg_replace_callback('/ |
|
| 1118 | + $token_len = strlen($token); |
|
| 1119 | + if ($tree_char_em) { |
|
| 1120 | + # Reached closing marker while inside a three-char emphasis. |
|
| 1121 | + if ($token_len == 3) { |
|
| 1122 | + # Three-char closing marker, close em and strong. |
|
| 1123 | + array_shift($token_stack); |
|
| 1124 | + $span = array_shift($text_stack); |
|
| 1125 | + $span = $this->runSpanGamut($span); |
|
| 1126 | + $span = "<strong><em>$span</em></strong>"; |
|
| 1127 | + $text_stack[0] .= $this->hashPart($span); |
|
| 1128 | + $em = ''; |
|
| 1129 | + $strong = ''; |
|
| 1130 | + } else { |
|
| 1131 | + # Other closing marker: close one em or strong and |
|
| 1132 | + # change current token state to match the other |
|
| 1133 | + $token_stack[0] = str_repeat($token{0}, 3-$token_len); |
|
| 1134 | + $tag = $token_len == 2 ? "strong" : "em"; |
|
| 1135 | + $span = $text_stack[0]; |
|
| 1136 | + $span = $this->runSpanGamut($span); |
|
| 1137 | + $span = "<$tag>$span</$tag>"; |
|
| 1138 | + $text_stack[0] = $this->hashPart($span); |
|
| 1139 | + $$tag = ''; # $$tag stands for $em or $strong |
|
| 1140 | + } |
|
| 1141 | + $tree_char_em = false; |
|
| 1142 | + } else if ($token_len == 3) { |
|
| 1143 | + if ($em) { |
|
| 1144 | + # Reached closing marker for both em and strong. |
|
| 1145 | + # Closing strong marker: |
|
| 1146 | + for ($i = 0; $i < 2; ++$i) { |
|
| 1147 | + $shifted_token = array_shift($token_stack); |
|
| 1148 | + $tag = strlen($shifted_token) == 2 ? "strong" : "em"; |
|
| 1149 | + $span = array_shift($text_stack); |
|
| 1150 | + $span = $this->runSpanGamut($span); |
|
| 1151 | + $span = "<$tag>$span</$tag>"; |
|
| 1152 | + $text_stack[0] .= $this->hashPart($span); |
|
| 1153 | + $$tag = ''; # $$tag stands for $em or $strong |
|
| 1154 | + } |
|
| 1155 | + } else { |
|
| 1156 | + # Reached opening three-char emphasis marker. Push on token |
|
| 1157 | + # stack; will be handled by the special condition above. |
|
| 1158 | + $em = $token{0}; |
|
| 1159 | + $strong = "$em$em"; |
|
| 1160 | + array_unshift($token_stack, $token); |
|
| 1161 | + array_unshift($text_stack, ''); |
|
| 1162 | + $tree_char_em = true; |
|
| 1163 | + } |
|
| 1164 | + } else if ($token_len == 2) { |
|
| 1165 | + if ($strong) { |
|
| 1166 | + # Unwind any dangling emphasis marker: |
|
| 1167 | + if (strlen($token_stack[0]) == 1) { |
|
| 1168 | + $text_stack[1] .= array_shift($token_stack); |
|
| 1169 | + $text_stack[0] .= array_shift($text_stack); |
|
| 1170 | + } |
|
| 1171 | + # Closing strong marker: |
|
| 1172 | + array_shift($token_stack); |
|
| 1173 | + $span = array_shift($text_stack); |
|
| 1174 | + $span = $this->runSpanGamut($span); |
|
| 1175 | + $span = "<strong>$span</strong>"; |
|
| 1176 | + $text_stack[0] .= $this->hashPart($span); |
|
| 1177 | + $strong = ''; |
|
| 1178 | + } else { |
|
| 1179 | + array_unshift($token_stack, $token); |
|
| 1180 | + array_unshift($text_stack, ''); |
|
| 1181 | + $strong = $token; |
|
| 1182 | + } |
|
| 1183 | + } else { |
|
| 1184 | + # Here $token_len == 1 |
|
| 1185 | + if ($em) { |
|
| 1186 | + if (strlen($token_stack[0]) == 1) { |
|
| 1187 | + # Closing emphasis marker: |
|
| 1188 | + array_shift($token_stack); |
|
| 1189 | + $span = array_shift($text_stack); |
|
| 1190 | + $span = $this->runSpanGamut($span); |
|
| 1191 | + $span = "<em>$span</em>"; |
|
| 1192 | + $text_stack[0] .= $this->hashPart($span); |
|
| 1193 | + $em = ''; |
|
| 1194 | + } else { |
|
| 1195 | + $text_stack[0] .= $token; |
|
| 1196 | + } |
|
| 1197 | + } else { |
|
| 1198 | + array_unshift($token_stack, $token); |
|
| 1199 | + array_unshift($text_stack, ''); |
|
| 1200 | + $em = $token; |
|
| 1201 | + } |
|
| 1202 | + } |
|
| 1203 | + } |
|
| 1204 | + return $text_stack[0]; |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + |
|
| 1208 | + protected function doBlockQuotes($text) { |
|
| 1209 | + $text = preg_replace_callback('/ |
|
| 1210 | 1210 | ( # Wrap whole match in $1 |
| 1211 | 1211 | (?> |
| 1212 | 1212 | ^[ ]*>[ ]? # ">" at the start of a line |
@@ -1216,58 +1216,58 @@ discard block |
||
| 1216 | 1216 | )+ |
| 1217 | 1217 | ) |
| 1218 | 1218 | /xm', |
| 1219 | - array($this, '_doBlockQuotes_callback'), $text); |
|
| 1220 | - |
|
| 1221 | - return $text; |
|
| 1222 | - } |
|
| 1223 | - protected function _doBlockQuotes_callback($matches) { |
|
| 1224 | - $bq = $matches[1]; |
|
| 1225 | - # trim one level of quoting - trim whitespace-only lines |
|
| 1226 | - $bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq); |
|
| 1227 | - $bq = $this->runBlockGamut($bq); # recurse |
|
| 1228 | - |
|
| 1229 | - $bq = preg_replace('/^/m', " ", $bq); |
|
| 1230 | - # These leading spaces cause problem with <pre> content, |
|
| 1231 | - # so we need to fix that: |
|
| 1232 | - $bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx', |
|
| 1233 | - array($this, '_doBlockQuotes_callback2'), $bq); |
|
| 1234 | - |
|
| 1235 | - return "\n". $this->hashBlock("<blockquote>\n$bq\n</blockquote>")."\n\n"; |
|
| 1236 | - } |
|
| 1237 | - protected function _doBlockQuotes_callback2($matches) { |
|
| 1238 | - $pre = $matches[1]; |
|
| 1239 | - $pre = preg_replace('/^ /m', '', $pre); |
|
| 1240 | - return $pre; |
|
| 1241 | - } |
|
| 1242 | - |
|
| 1243 | - |
|
| 1244 | - protected function formParagraphs($text) { |
|
| 1245 | - # |
|
| 1246 | - # Params: |
|
| 1247 | - # $text - string to process with html <p> tags |
|
| 1248 | - # |
|
| 1249 | - # Strip leading and trailing lines: |
|
| 1250 | - $text = preg_replace('/\A\n+|\n+\z/', '', $text); |
|
| 1251 | - |
|
| 1252 | - $grafs = preg_split('/\n{2,}/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
| 1253 | - |
|
| 1254 | - # |
|
| 1255 | - # Wrap <p> tags and unhashify HTML blocks |
|
| 1256 | - # |
|
| 1257 | - foreach ($grafs as $key => $value) { |
|
| 1258 | - if (!preg_match('/^B\x1A[0-9]+B$/', $value)) { |
|
| 1259 | - # Is a paragraph. |
|
| 1260 | - $value = $this->runSpanGamut($value); |
|
| 1261 | - $value = preg_replace('/^([ ]*)/', "<p>", $value); |
|
| 1262 | - $value .= "</p>"; |
|
| 1263 | - $grafs[$key] = $this->unhash($value); |
|
| 1264 | - } |
|
| 1265 | - else { |
|
| 1266 | - # Is a block. |
|
| 1267 | - # Modify elements of @grafs in-place... |
|
| 1268 | - $graf = $value; |
|
| 1269 | - $block = $this->html_hashes[$graf]; |
|
| 1270 | - $graf = $block; |
|
| 1219 | + array($this, '_doBlockQuotes_callback'), $text); |
|
| 1220 | + |
|
| 1221 | + return $text; |
|
| 1222 | + } |
|
| 1223 | + protected function _doBlockQuotes_callback($matches) { |
|
| 1224 | + $bq = $matches[1]; |
|
| 1225 | + # trim one level of quoting - trim whitespace-only lines |
|
| 1226 | + $bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq); |
|
| 1227 | + $bq = $this->runBlockGamut($bq); # recurse |
|
| 1228 | + |
|
| 1229 | + $bq = preg_replace('/^/m', " ", $bq); |
|
| 1230 | + # These leading spaces cause problem with <pre> content, |
|
| 1231 | + # so we need to fix that: |
|
| 1232 | + $bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx', |
|
| 1233 | + array($this, '_doBlockQuotes_callback2'), $bq); |
|
| 1234 | + |
|
| 1235 | + return "\n". $this->hashBlock("<blockquote>\n$bq\n</blockquote>")."\n\n"; |
|
| 1236 | + } |
|
| 1237 | + protected function _doBlockQuotes_callback2($matches) { |
|
| 1238 | + $pre = $matches[1]; |
|
| 1239 | + $pre = preg_replace('/^ /m', '', $pre); |
|
| 1240 | + return $pre; |
|
| 1241 | + } |
|
| 1242 | + |
|
| 1243 | + |
|
| 1244 | + protected function formParagraphs($text) { |
|
| 1245 | + # |
|
| 1246 | + # Params: |
|
| 1247 | + # $text - string to process with html <p> tags |
|
| 1248 | + # |
|
| 1249 | + # Strip leading and trailing lines: |
|
| 1250 | + $text = preg_replace('/\A\n+|\n+\z/', '', $text); |
|
| 1251 | + |
|
| 1252 | + $grafs = preg_split('/\n{2,}/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
| 1253 | + |
|
| 1254 | + # |
|
| 1255 | + # Wrap <p> tags and unhashify HTML blocks |
|
| 1256 | + # |
|
| 1257 | + foreach ($grafs as $key => $value) { |
|
| 1258 | + if (!preg_match('/^B\x1A[0-9]+B$/', $value)) { |
|
| 1259 | + # Is a paragraph. |
|
| 1260 | + $value = $this->runSpanGamut($value); |
|
| 1261 | + $value = preg_replace('/^([ ]*)/', "<p>", $value); |
|
| 1262 | + $value .= "</p>"; |
|
| 1263 | + $grafs[$key] = $this->unhash($value); |
|
| 1264 | + } |
|
| 1265 | + else { |
|
| 1266 | + # Is a block. |
|
| 1267 | + # Modify elements of @grafs in-place... |
|
| 1268 | + $graf = $value; |
|
| 1269 | + $block = $this->html_hashes[$graf]; |
|
| 1270 | + $graf = $block; |
|
| 1271 | 1271 | // if (preg_match('{ |
| 1272 | 1272 | // \A |
| 1273 | 1273 | // ( # $1 = <div> tag |
@@ -1303,79 +1303,79 @@ discard block |
||
| 1303 | 1303 | // |
| 1304 | 1304 | // $graf = $div_open . "\n" . $div_content . "\n" . $div_close; |
| 1305 | 1305 | // } |
| 1306 | - $grafs[$key] = $graf; |
|
| 1307 | - } |
|
| 1308 | - } |
|
| 1309 | - |
|
| 1310 | - return implode("\n\n", $grafs); |
|
| 1311 | - } |
|
| 1312 | - |
|
| 1313 | - |
|
| 1314 | - protected function encodeAttribute($text) { |
|
| 1315 | - # |
|
| 1316 | - # Encode text for a double-quoted HTML attribute. This function |
|
| 1317 | - # is *not* suitable for attributes enclosed in single quotes. |
|
| 1318 | - # |
|
| 1319 | - $text = $this->encodeAmpsAndAngles($text); |
|
| 1320 | - $text = str_replace('"', '"', $text); |
|
| 1321 | - return $text; |
|
| 1322 | - } |
|
| 1323 | - |
|
| 1324 | - |
|
| 1325 | - protected function encodeURLAttribute($url, &$text = null) { |
|
| 1326 | - # |
|
| 1327 | - # Encode text for a double-quoted HTML attribute containing a URL, |
|
| 1328 | - # applying the URL filter if set. Also generates the textual |
|
| 1329 | - # representation for the URL (removing mailto: or tel:) storing it in $text. |
|
| 1330 | - # This function is *not* suitable for attributes enclosed in single quotes. |
|
| 1331 | - # |
|
| 1332 | - if ($this->url_filter_func) |
|
| 1333 | - $url = call_user_func($this->url_filter_func, $url); |
|
| 1334 | - |
|
| 1335 | - if (preg_match('{^mailto:}i', $url)) |
|
| 1336 | - $url = $this->encodeEntityObfuscatedAttribute($url, $text, 7); |
|
| 1337 | - else if (preg_match('{^tel:}i', $url)) |
|
| 1338 | - { |
|
| 1339 | - $url = $this->encodeAttribute($url); |
|
| 1340 | - $text = substr($url, 4); |
|
| 1341 | - } |
|
| 1342 | - else |
|
| 1343 | - { |
|
| 1344 | - $url = $this->encodeAttribute($url); |
|
| 1345 | - $text = $url; |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - return $url; |
|
| 1349 | - } |
|
| 1306 | + $grafs[$key] = $graf; |
|
| 1307 | + } |
|
| 1308 | + } |
|
| 1309 | + |
|
| 1310 | + return implode("\n\n", $grafs); |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + |
|
| 1314 | + protected function encodeAttribute($text) { |
|
| 1315 | + # |
|
| 1316 | + # Encode text for a double-quoted HTML attribute. This function |
|
| 1317 | + # is *not* suitable for attributes enclosed in single quotes. |
|
| 1318 | + # |
|
| 1319 | + $text = $this->encodeAmpsAndAngles($text); |
|
| 1320 | + $text = str_replace('"', '"', $text); |
|
| 1321 | + return $text; |
|
| 1322 | + } |
|
| 1323 | + |
|
| 1324 | + |
|
| 1325 | + protected function encodeURLAttribute($url, &$text = null) { |
|
| 1326 | + # |
|
| 1327 | + # Encode text for a double-quoted HTML attribute containing a URL, |
|
| 1328 | + # applying the URL filter if set. Also generates the textual |
|
| 1329 | + # representation for the URL (removing mailto: or tel:) storing it in $text. |
|
| 1330 | + # This function is *not* suitable for attributes enclosed in single quotes. |
|
| 1331 | + # |
|
| 1332 | + if ($this->url_filter_func) |
|
| 1333 | + $url = call_user_func($this->url_filter_func, $url); |
|
| 1334 | + |
|
| 1335 | + if (preg_match('{^mailto:}i', $url)) |
|
| 1336 | + $url = $this->encodeEntityObfuscatedAttribute($url, $text, 7); |
|
| 1337 | + else if (preg_match('{^tel:}i', $url)) |
|
| 1338 | + { |
|
| 1339 | + $url = $this->encodeAttribute($url); |
|
| 1340 | + $text = substr($url, 4); |
|
| 1341 | + } |
|
| 1342 | + else |
|
| 1343 | + { |
|
| 1344 | + $url = $this->encodeAttribute($url); |
|
| 1345 | + $text = $url; |
|
| 1346 | + } |
|
| 1347 | + |
|
| 1348 | + return $url; |
|
| 1349 | + } |
|
| 1350 | 1350 | |
| 1351 | 1351 | |
| 1352 | - protected function encodeAmpsAndAngles($text) { |
|
| 1353 | - # |
|
| 1354 | - # Smart processing for ampersands and angle brackets that need to |
|
| 1355 | - # be encoded. Valid character entities are left alone unless the |
|
| 1356 | - # no-entities mode is set. |
|
| 1357 | - # |
|
| 1358 | - if ($this->no_entities) { |
|
| 1359 | - $text = str_replace('&', '&', $text); |
|
| 1360 | - } else { |
|
| 1361 | - # Ampersand-encoding based entirely on Nat Irons's Amputator |
|
| 1362 | - # MT plugin: <http://bumppo.net/projects/amputator/> |
|
| 1363 | - $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/', |
|
| 1364 | - '&', $text); |
|
| 1365 | - } |
|
| 1366 | - # Encode remaining <'s |
|
| 1367 | - $text = str_replace('<', '<', $text); |
|
| 1368 | - |
|
| 1369 | - return $text; |
|
| 1370 | - } |
|
| 1371 | - |
|
| 1372 | - |
|
| 1373 | - protected function doAutoLinks($text) { |
|
| 1374 | - $text = preg_replace_callback('{<((https?|ftp|dict|tel):[^\'">\s]+)>}i', |
|
| 1375 | - array($this, '_doAutoLinks_url_callback'), $text); |
|
| 1376 | - |
|
| 1377 | - # Email addresses: <[email protected]> |
|
| 1378 | - $text = preg_replace_callback('{ |
|
| 1352 | + protected function encodeAmpsAndAngles($text) { |
|
| 1353 | + # |
|
| 1354 | + # Smart processing for ampersands and angle brackets that need to |
|
| 1355 | + # be encoded. Valid character entities are left alone unless the |
|
| 1356 | + # no-entities mode is set. |
|
| 1357 | + # |
|
| 1358 | + if ($this->no_entities) { |
|
| 1359 | + $text = str_replace('&', '&', $text); |
|
| 1360 | + } else { |
|
| 1361 | + # Ampersand-encoding based entirely on Nat Irons's Amputator |
|
| 1362 | + # MT plugin: <http://bumppo.net/projects/amputator/> |
|
| 1363 | + $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/', |
|
| 1364 | + '&', $text); |
|
| 1365 | + } |
|
| 1366 | + # Encode remaining <'s |
|
| 1367 | + $text = str_replace('<', '<', $text); |
|
| 1368 | + |
|
| 1369 | + return $text; |
|
| 1370 | + } |
|
| 1371 | + |
|
| 1372 | + |
|
| 1373 | + protected function doAutoLinks($text) { |
|
| 1374 | + $text = preg_replace_callback('{<((https?|ftp|dict|tel):[^\'">\s]+)>}i', |
|
| 1375 | + array($this, '_doAutoLinks_url_callback'), $text); |
|
| 1376 | + |
|
| 1377 | + # Email addresses: <[email protected]> |
|
| 1378 | + $text = preg_replace_callback('{ |
|
| 1379 | 1379 | < |
| 1380 | 1380 | (?:mailto:)? |
| 1381 | 1381 | ( |
@@ -1393,76 +1393,76 @@ discard block |
||
| 1393 | 1393 | ) |
| 1394 | 1394 | > |
| 1395 | 1395 | }xi', |
| 1396 | - array($this, '_doAutoLinks_email_callback'), $text); |
|
| 1397 | - |
|
| 1398 | - return $text; |
|
| 1399 | - } |
|
| 1400 | - protected function _doAutoLinks_url_callback($matches) { |
|
| 1401 | - $url = $this->encodeURLAttribute($matches[1], $text); |
|
| 1402 | - $link = "<a href=\"$url\">$text</a>"; |
|
| 1403 | - return $this->hashPart($link); |
|
| 1404 | - } |
|
| 1405 | - protected function _doAutoLinks_email_callback($matches) { |
|
| 1406 | - $addr = $matches[1]; |
|
| 1407 | - $url = $this->encodeURLAttribute("mailto:$addr", $text); |
|
| 1408 | - $link = "<a href=\"$url\">$text</a>"; |
|
| 1409 | - return $this->hashPart($link); |
|
| 1410 | - } |
|
| 1411 | - |
|
| 1412 | - |
|
| 1413 | - protected function encodeEntityObfuscatedAttribute($text, &$tail = null, $head_length = 0) { |
|
| 1414 | - # |
|
| 1415 | - # Input: some text to obfuscate, e.g. "mailto:[email protected]" |
|
| 1416 | - # |
|
| 1417 | - # Output: the same text but with most characters encoded as either a |
|
| 1418 | - # decimal or hex entity, in the hopes of foiling most address |
|
| 1419 | - # harvesting spam bots. E.g.: |
|
| 1420 | - # |
|
| 1421 | - # mailto:foo |
|
| 1422 | - # @example.co |
|
| 1423 | - # m |
|
| 1424 | - # |
|
| 1425 | - # Note: the additional output $tail is assigned the same value as the |
|
| 1426 | - # ouput, minus the number of characters specified by $head_length. |
|
| 1427 | - # |
|
| 1428 | - # Based by a filter by Matthew Wickline, posted to BBEdit-Talk. |
|
| 1429 | - # With some optimizations by Milian Wolff. Forced encoding of HTML |
|
| 1430 | - # attribute special characters by Allan Odgaard. |
|
| 1431 | - # |
|
| 1432 | - if ($text == "") return $tail = ""; |
|
| 1433 | - |
|
| 1434 | - $chars = preg_split('/(?<!^)(?!$)/', $text); |
|
| 1435 | - $seed = (int)abs(crc32($text) / strlen($text)); # Deterministic seed. |
|
| 1436 | - |
|
| 1437 | - foreach ($chars as $key => $char) { |
|
| 1438 | - $ord = ord($char); |
|
| 1439 | - # Ignore non-ascii chars. |
|
| 1440 | - if ($ord < 128) { |
|
| 1441 | - $r = ($seed * (1 + $key)) % 100; # Pseudo-random function. |
|
| 1442 | - # roughly 10% raw, 45% hex, 45% dec |
|
| 1443 | - # '@' *must* be encoded. I insist. |
|
| 1444 | - # '"' and '>' have to be encoded inside the attribute |
|
| 1445 | - if ($r > 90 && strpos('@"&>', $char) === false) /* do nothing */; |
|
| 1446 | - else if ($r < 45) $chars[$key] = '&#x'.dechex($ord).';'; |
|
| 1447 | - else $chars[$key] = '&#'.$ord.';'; |
|
| 1448 | - } |
|
| 1449 | - } |
|
| 1450 | - |
|
| 1451 | - $text = implode('', $chars); |
|
| 1452 | - $tail = $head_length ? implode('', array_slice($chars, $head_length)) : $text; |
|
| 1453 | - |
|
| 1454 | - return $text; |
|
| 1455 | - } |
|
| 1456 | - |
|
| 1457 | - |
|
| 1458 | - protected function parseSpan($str) { |
|
| 1459 | - # |
|
| 1460 | - # Take the string $str and parse it into tokens, hashing embeded HTML, |
|
| 1461 | - # escaped characters and handling code spans. |
|
| 1462 | - # |
|
| 1463 | - $output = ''; |
|
| 1396 | + array($this, '_doAutoLinks_email_callback'), $text); |
|
| 1397 | + |
|
| 1398 | + return $text; |
|
| 1399 | + } |
|
| 1400 | + protected function _doAutoLinks_url_callback($matches) { |
|
| 1401 | + $url = $this->encodeURLAttribute($matches[1], $text); |
|
| 1402 | + $link = "<a href=\"$url\">$text</a>"; |
|
| 1403 | + return $this->hashPart($link); |
|
| 1404 | + } |
|
| 1405 | + protected function _doAutoLinks_email_callback($matches) { |
|
| 1406 | + $addr = $matches[1]; |
|
| 1407 | + $url = $this->encodeURLAttribute("mailto:$addr", $text); |
|
| 1408 | + $link = "<a href=\"$url\">$text</a>"; |
|
| 1409 | + return $this->hashPart($link); |
|
| 1410 | + } |
|
| 1411 | + |
|
| 1412 | + |
|
| 1413 | + protected function encodeEntityObfuscatedAttribute($text, &$tail = null, $head_length = 0) { |
|
| 1414 | + # |
|
| 1415 | + # Input: some text to obfuscate, e.g. "mailto:[email protected]" |
|
| 1416 | + # |
|
| 1417 | + # Output: the same text but with most characters encoded as either a |
|
| 1418 | + # decimal or hex entity, in the hopes of foiling most address |
|
| 1419 | + # harvesting spam bots. E.g.: |
|
| 1420 | + # |
|
| 1421 | + # mailto:foo |
|
| 1422 | + # @example.co |
|
| 1423 | + # m |
|
| 1424 | + # |
|
| 1425 | + # Note: the additional output $tail is assigned the same value as the |
|
| 1426 | + # ouput, minus the number of characters specified by $head_length. |
|
| 1427 | + # |
|
| 1428 | + # Based by a filter by Matthew Wickline, posted to BBEdit-Talk. |
|
| 1429 | + # With some optimizations by Milian Wolff. Forced encoding of HTML |
|
| 1430 | + # attribute special characters by Allan Odgaard. |
|
| 1431 | + # |
|
| 1432 | + if ($text == "") return $tail = ""; |
|
| 1433 | + |
|
| 1434 | + $chars = preg_split('/(?<!^)(?!$)/', $text); |
|
| 1435 | + $seed = (int)abs(crc32($text) / strlen($text)); # Deterministic seed. |
|
| 1436 | + |
|
| 1437 | + foreach ($chars as $key => $char) { |
|
| 1438 | + $ord = ord($char); |
|
| 1439 | + # Ignore non-ascii chars. |
|
| 1440 | + if ($ord < 128) { |
|
| 1441 | + $r = ($seed * (1 + $key)) % 100; # Pseudo-random function. |
|
| 1442 | + # roughly 10% raw, 45% hex, 45% dec |
|
| 1443 | + # '@' *must* be encoded. I insist. |
|
| 1444 | + # '"' and '>' have to be encoded inside the attribute |
|
| 1445 | + if ($r > 90 && strpos('@"&>', $char) === false) /* do nothing */; |
|
| 1446 | + else if ($r < 45) $chars[$key] = '&#x'.dechex($ord).';'; |
|
| 1447 | + else $chars[$key] = '&#'.$ord.';'; |
|
| 1448 | + } |
|
| 1449 | + } |
|
| 1450 | + |
|
| 1451 | + $text = implode('', $chars); |
|
| 1452 | + $tail = $head_length ? implode('', array_slice($chars, $head_length)) : $text; |
|
| 1453 | + |
|
| 1454 | + return $text; |
|
| 1455 | + } |
|
| 1456 | + |
|
| 1457 | + |
|
| 1458 | + protected function parseSpan($str) { |
|
| 1459 | + # |
|
| 1460 | + # Take the string $str and parse it into tokens, hashing embeded HTML, |
|
| 1461 | + # escaped characters and handling code spans. |
|
| 1462 | + # |
|
| 1463 | + $output = ''; |
|
| 1464 | 1464 | |
| 1465 | - $span_re = '{ |
|
| 1465 | + $span_re = '{ |
|
| 1466 | 1466 | ( |
| 1467 | 1467 | \\\\'.$this->escape_chars_re.' |
| 1468 | 1468 | | |
@@ -1488,122 +1488,122 @@ discard block |
||
| 1488 | 1488 | ) |
| 1489 | 1489 | }xs'; |
| 1490 | 1490 | |
| 1491 | - while (1) { |
|
| 1492 | - # |
|
| 1493 | - # Each loop iteration seach for either the next tag, the next |
|
| 1494 | - # openning code span marker, or the next escaped character. |
|
| 1495 | - # Each token is then passed to handleSpanToken. |
|
| 1496 | - # |
|
| 1497 | - $parts = preg_split($span_re, $str, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 1491 | + while (1) { |
|
| 1492 | + # |
|
| 1493 | + # Each loop iteration seach for either the next tag, the next |
|
| 1494 | + # openning code span marker, or the next escaped character. |
|
| 1495 | + # Each token is then passed to handleSpanToken. |
|
| 1496 | + # |
|
| 1497 | + $parts = preg_split($span_re, $str, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 1498 | 1498 | |
| 1499 | - # Create token from text preceding tag. |
|
| 1500 | - if ($parts[0] != "") { |
|
| 1501 | - $output .= $parts[0]; |
|
| 1502 | - } |
|
| 1499 | + # Create token from text preceding tag. |
|
| 1500 | + if ($parts[0] != "") { |
|
| 1501 | + $output .= $parts[0]; |
|
| 1502 | + } |
|
| 1503 | 1503 | |
| 1504 | - # Check if we reach the end. |
|
| 1505 | - if (isset($parts[1])) { |
|
| 1506 | - $output .= $this->handleSpanToken($parts[1], $parts[2]); |
|
| 1507 | - $str = $parts[2]; |
|
| 1508 | - } |
|
| 1509 | - else { |
|
| 1510 | - break; |
|
| 1511 | - } |
|
| 1512 | - } |
|
| 1504 | + # Check if we reach the end. |
|
| 1505 | + if (isset($parts[1])) { |
|
| 1506 | + $output .= $this->handleSpanToken($parts[1], $parts[2]); |
|
| 1507 | + $str = $parts[2]; |
|
| 1508 | + } |
|
| 1509 | + else { |
|
| 1510 | + break; |
|
| 1511 | + } |
|
| 1512 | + } |
|
| 1513 | 1513 | |
| 1514 | - return $output; |
|
| 1515 | - } |
|
| 1514 | + return $output; |
|
| 1515 | + } |
|
| 1516 | 1516 | |
| 1517 | 1517 | |
| 1518 | - protected function handleSpanToken($token, &$str) { |
|
| 1519 | - # |
|
| 1520 | - # Handle $token provided by parseSpan by determining its nature and |
|
| 1521 | - # returning the corresponding value that should replace it. |
|
| 1522 | - # |
|
| 1523 | - switch ($token{0}) { |
|
| 1524 | - case "\\": |
|
| 1525 | - return $this->hashPart("&#". ord($token{1}). ";"); |
|
| 1526 | - case "`": |
|
| 1527 | - # Search for end marker in remaining text. |
|
| 1528 | - if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm', |
|
| 1529 | - $str, $matches)) |
|
| 1530 | - { |
|
| 1531 | - $str = $matches[2]; |
|
| 1532 | - $codespan = $this->makeCodeSpan($matches[1]); |
|
| 1533 | - return $this->hashPart($codespan); |
|
| 1534 | - } |
|
| 1535 | - return $token; // return as text since no ending marker found. |
|
| 1536 | - default: |
|
| 1537 | - return $this->hashPart($token); |
|
| 1538 | - } |
|
| 1539 | - } |
|
| 1540 | - |
|
| 1541 | - |
|
| 1542 | - protected function outdent($text) { |
|
| 1543 | - # |
|
| 1544 | - # Remove one level of line-leading tabs or spaces |
|
| 1545 | - # |
|
| 1546 | - return preg_replace('/^(\t|[ ]{1,'.$this->tab_width.'})/m', '', $text); |
|
| 1547 | - } |
|
| 1548 | - |
|
| 1549 | - |
|
| 1550 | - # String length function for detab. `_initDetab` will create a function to |
|
| 1551 | - # hanlde UTF-8 if the default function does not exist. |
|
| 1552 | - protected $utf8_strlen = 'mb_strlen'; |
|
| 1518 | + protected function handleSpanToken($token, &$str) { |
|
| 1519 | + # |
|
| 1520 | + # Handle $token provided by parseSpan by determining its nature and |
|
| 1521 | + # returning the corresponding value that should replace it. |
|
| 1522 | + # |
|
| 1523 | + switch ($token{0}) { |
|
| 1524 | + case "\\": |
|
| 1525 | + return $this->hashPart("&#". ord($token{1}). ";"); |
|
| 1526 | + case "`": |
|
| 1527 | + # Search for end marker in remaining text. |
|
| 1528 | + if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm', |
|
| 1529 | + $str, $matches)) |
|
| 1530 | + { |
|
| 1531 | + $str = $matches[2]; |
|
| 1532 | + $codespan = $this->makeCodeSpan($matches[1]); |
|
| 1533 | + return $this->hashPart($codespan); |
|
| 1534 | + } |
|
| 1535 | + return $token; // return as text since no ending marker found. |
|
| 1536 | + default: |
|
| 1537 | + return $this->hashPart($token); |
|
| 1538 | + } |
|
| 1539 | + } |
|
| 1540 | + |
|
| 1541 | + |
|
| 1542 | + protected function outdent($text) { |
|
| 1543 | + # |
|
| 1544 | + # Remove one level of line-leading tabs or spaces |
|
| 1545 | + # |
|
| 1546 | + return preg_replace('/^(\t|[ ]{1,'.$this->tab_width.'})/m', '', $text); |
|
| 1547 | + } |
|
| 1548 | + |
|
| 1549 | + |
|
| 1550 | + # String length function for detab. `_initDetab` will create a function to |
|
| 1551 | + # hanlde UTF-8 if the default function does not exist. |
|
| 1552 | + protected $utf8_strlen = 'mb_strlen'; |
|
| 1553 | 1553 | |
| 1554 | - protected function detab($text) { |
|
| 1555 | - # |
|
| 1556 | - # Replace tabs with the appropriate amount of space. |
|
| 1557 | - # |
|
| 1558 | - # For each line we separate the line in blocks delemited by |
|
| 1559 | - # tab characters. Then we reconstruct every line by adding the |
|
| 1560 | - # appropriate number of space between each blocks. |
|
| 1554 | + protected function detab($text) { |
|
| 1555 | + # |
|
| 1556 | + # Replace tabs with the appropriate amount of space. |
|
| 1557 | + # |
|
| 1558 | + # For each line we separate the line in blocks delemited by |
|
| 1559 | + # tab characters. Then we reconstruct every line by adding the |
|
| 1560 | + # appropriate number of space between each blocks. |
|
| 1561 | 1561 | |
| 1562 | - $text = preg_replace_callback('/^.*\t.*$/m', |
|
| 1563 | - array($this, '_detab_callback'), $text); |
|
| 1564 | - |
|
| 1565 | - return $text; |
|
| 1566 | - } |
|
| 1567 | - protected function _detab_callback($matches) { |
|
| 1568 | - $line = $matches[0]; |
|
| 1569 | - $strlen = $this->utf8_strlen; # strlen function for UTF-8. |
|
| 1562 | + $text = preg_replace_callback('/^.*\t.*$/m', |
|
| 1563 | + array($this, '_detab_callback'), $text); |
|
| 1564 | + |
|
| 1565 | + return $text; |
|
| 1566 | + } |
|
| 1567 | + protected function _detab_callback($matches) { |
|
| 1568 | + $line = $matches[0]; |
|
| 1569 | + $strlen = $this->utf8_strlen; # strlen function for UTF-8. |
|
| 1570 | 1570 | |
| 1571 | - # Split in blocks. |
|
| 1572 | - $blocks = explode("\t", $line); |
|
| 1573 | - # Add each blocks to the line. |
|
| 1574 | - $line = $blocks[0]; |
|
| 1575 | - unset($blocks[0]); # Do not add first block twice. |
|
| 1576 | - foreach ($blocks as $block) { |
|
| 1577 | - # Calculate amount of space, insert spaces, insert block. |
|
| 1578 | - $amount = $this->tab_width - |
|
| 1579 | - $strlen($line, 'UTF-8') % $this->tab_width; |
|
| 1580 | - $line .= str_repeat(" ", $amount) . $block; |
|
| 1581 | - } |
|
| 1582 | - return $line; |
|
| 1583 | - } |
|
| 1584 | - protected function _initDetab() { |
|
| 1585 | - # |
|
| 1586 | - # Check for the availability of the function in the `utf8_strlen` property |
|
| 1587 | - # (initially `mb_strlen`). If the function is not available, create a |
|
| 1588 | - # function that will loosely count the number of UTF-8 characters with a |
|
| 1589 | - # regular expression. |
|
| 1590 | - # |
|
| 1591 | - if (function_exists($this->utf8_strlen)) return; |
|
| 1592 | - $this->utf8_strlen = create_function('$text', 'return preg_match_all( |
|
| 1571 | + # Split in blocks. |
|
| 1572 | + $blocks = explode("\t", $line); |
|
| 1573 | + # Add each blocks to the line. |
|
| 1574 | + $line = $blocks[0]; |
|
| 1575 | + unset($blocks[0]); # Do not add first block twice. |
|
| 1576 | + foreach ($blocks as $block) { |
|
| 1577 | + # Calculate amount of space, insert spaces, insert block. |
|
| 1578 | + $amount = $this->tab_width - |
|
| 1579 | + $strlen($line, 'UTF-8') % $this->tab_width; |
|
| 1580 | + $line .= str_repeat(" ", $amount) . $block; |
|
| 1581 | + } |
|
| 1582 | + return $line; |
|
| 1583 | + } |
|
| 1584 | + protected function _initDetab() { |
|
| 1585 | + # |
|
| 1586 | + # Check for the availability of the function in the `utf8_strlen` property |
|
| 1587 | + # (initially `mb_strlen`). If the function is not available, create a |
|
| 1588 | + # function that will loosely count the number of UTF-8 characters with a |
|
| 1589 | + # regular expression. |
|
| 1590 | + # |
|
| 1591 | + if (function_exists($this->utf8_strlen)) return; |
|
| 1592 | + $this->utf8_strlen = create_function('$text', 'return preg_match_all( |
|
| 1593 | 1593 | "/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/", |
| 1594 | 1594 | $text, $m);'); |
| 1595 | - } |
|
| 1596 | - |
|
| 1597 | - |
|
| 1598 | - protected function unhash($text) { |
|
| 1599 | - # |
|
| 1600 | - # Swap back in all the tags hashed by _HashHTMLBlocks. |
|
| 1601 | - # |
|
| 1602 | - return preg_replace_callback('/(.)\x1A[0-9]+\1/', |
|
| 1603 | - array($this, '_unhash_callback'), $text); |
|
| 1604 | - } |
|
| 1605 | - protected function _unhash_callback($matches) { |
|
| 1606 | - return $this->html_hashes[$matches[0]]; |
|
| 1607 | - } |
|
| 1595 | + } |
|
| 1596 | + |
|
| 1597 | + |
|
| 1598 | + protected function unhash($text) { |
|
| 1599 | + # |
|
| 1600 | + # Swap back in all the tags hashed by _HashHTMLBlocks. |
|
| 1601 | + # |
|
| 1602 | + return preg_replace_callback('/(.)\x1A[0-9]+\1/', |
|
| 1603 | + array($this, '_unhash_callback'), $text); |
|
| 1604 | + } |
|
| 1605 | + protected function _unhash_callback($matches) { |
|
| 1606 | + return $this->html_hashes[$matches[0]]; |
|
| 1607 | + } |
|
| 1608 | 1608 | |
| 1609 | 1609 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | ### Version ### |
| 23 | 23 | |
| 24 | - const MARKDOWNLIB_VERSION = "1.5.0"; |
|
| 24 | + const MARKDOWNLIB_VERSION = "1.5.0"; |
|
| 25 | 25 | |
| 26 | 26 | ### Simple Function Interface ### |
| 27 | 27 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | # try to take parser from the static parser list |
| 37 | 37 | static $parser_list; |
| 38 | - $parser =& $parser_list[$parser_class]; |
|
| 38 | + $parser = & $parser_list[ $parser_class ]; |
|
| 39 | 39 | |
| 40 | 40 | # create the parser it not already set |
| 41 | 41 | if (!$parser) |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | |
| 187 | 187 | $this->teardown(); |
| 188 | 188 | |
| 189 | - return $text . "\n"; |
|
| 189 | + return $text."\n"; |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | protected $document_gamut = array( |
@@ -232,10 +232,10 @@ discard block |
||
| 232 | 232 | return $text; |
| 233 | 233 | } |
| 234 | 234 | protected function _stripLinkDefinitions_callback($matches) { |
| 235 | - $link_id = strtolower($matches[1]); |
|
| 236 | - $url = $matches[2] == '' ? $matches[3] : $matches[2]; |
|
| 237 | - $this->urls[$link_id] = $url; |
|
| 238 | - $this->titles[$link_id] =& $matches[4]; |
|
| 235 | + $link_id = strtolower($matches[ 1 ]); |
|
| 236 | + $url = $matches[ 2 ] == '' ? $matches[ 3 ] : $matches[ 2 ]; |
|
| 237 | + $this->urls[ $link_id ] = $url; |
|
| 238 | + $this->titles[ $link_id ] = & $matches[ 4 ]; |
|
| 239 | 239 | return ''; # String that will replace the block |
| 240 | 240 | } |
| 241 | 241 | |
@@ -290,8 +290,8 @@ discard block |
||
| 290 | 290 | (?> |
| 291 | 291 | /> |
| 292 | 292 | | |
| 293 | - >', $nested_tags_level). # end of opening tag |
|
| 294 | - '.*?'. # last level nested tag content |
|
| 293 | + >', $nested_tags_level).# end of opening tag |
|
| 294 | + '.*?'.# last level nested tag content |
|
| 295 | 295 | str_repeat(' |
| 296 | 296 | </\2\s*> # closing nested tag |
| 297 | 297 | ) |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | return $text; |
| 381 | 381 | } |
| 382 | 382 | protected function _hashHTMLBlocks_callback($matches) { |
| 383 | - $text = $matches[1]; |
|
| 383 | + $text = $matches[ 1 ]; |
|
| 384 | 384 | $key = $this->hashBlock($text); |
| 385 | 385 | return "\n\n$key\n\n"; |
| 386 | 386 | } |
@@ -403,8 +403,8 @@ discard block |
||
| 403 | 403 | |
| 404 | 404 | # Then hash the block. |
| 405 | 405 | static $i = 0; |
| 406 | - $key = "$boundary\x1A" . ++$i . $boundary; |
|
| 407 | - $this->html_hashes[$key] = $text; |
|
| 406 | + $key = "$boundary\x1A".++$i.$boundary; |
|
| 407 | + $this->html_hashes[ $key ] = $text; |
|
| 408 | 408 | return $key; # String that will replace the tag. |
| 409 | 409 | } |
| 410 | 410 | |
@@ -596,9 +596,9 @@ discard block |
||
| 596 | 596 | return $text; |
| 597 | 597 | } |
| 598 | 598 | protected function _doAnchors_reference_callback($matches) { |
| 599 | - $whole_match = $matches[1]; |
|
| 600 | - $link_text = $matches[2]; |
|
| 601 | - $link_id =& $matches[3]; |
|
| 599 | + $whole_match = $matches[ 1 ]; |
|
| 600 | + $link_text = $matches[ 2 ]; |
|
| 601 | + $link_id = & $matches[ 3 ]; |
|
| 602 | 602 | |
| 603 | 603 | if ($link_id == "") { |
| 604 | 604 | # for shortcut links like [this][] or [this]. |
@@ -609,15 +609,15 @@ discard block |
||
| 609 | 609 | $link_id = strtolower($link_id); |
| 610 | 610 | $link_id = preg_replace('{[ ]?\n}', ' ', $link_id); |
| 611 | 611 | |
| 612 | - if (isset($this->urls[$link_id])) { |
|
| 613 | - $url = $this->urls[$link_id]; |
|
| 612 | + if (isset($this->urls[ $link_id ])) { |
|
| 613 | + $url = $this->urls[ $link_id ]; |
|
| 614 | 614 | $url = $this->encodeURLAttribute($url); |
| 615 | 615 | |
| 616 | 616 | $result = "<a href=\"$url\""; |
| 617 | - if ( isset( $this->titles[$link_id] ) ) { |
|
| 618 | - $title = $this->titles[$link_id]; |
|
| 617 | + if (isset($this->titles[ $link_id ])) { |
|
| 618 | + $title = $this->titles[ $link_id ]; |
|
| 619 | 619 | $title = $this->encodeAttribute($title); |
| 620 | - $result .= " title=\"$title\""; |
|
| 620 | + $result .= " title=\"$title\""; |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | $link_text = $this->runSpanGamut($link_text); |
@@ -630,10 +630,10 @@ discard block |
||
| 630 | 630 | return $result; |
| 631 | 631 | } |
| 632 | 632 | protected function _doAnchors_inline_callback($matches) { |
| 633 | - $whole_match = $matches[1]; |
|
| 634 | - $link_text = $this->runSpanGamut($matches[2]); |
|
| 635 | - $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 636 | - $title =& $matches[7]; |
|
| 633 | + $whole_match = $matches[ 1 ]; |
|
| 634 | + $link_text = $this->runSpanGamut($matches[ 2 ]); |
|
| 635 | + $url = $matches[ 3 ] == '' ? $matches[ 4 ] : $matches[ 3 ]; |
|
| 636 | + $title = & $matches[ 7 ]; |
|
| 637 | 637 | |
| 638 | 638 | // if the URL was of the form <s p a c e s> it got caught by the HTML |
| 639 | 639 | // tag parser and hashed. Need to reverse the process before using the URL. |
@@ -646,7 +646,7 @@ discard block |
||
| 646 | 646 | $result = "<a href=\"$url\""; |
| 647 | 647 | if (isset($title)) { |
| 648 | 648 | $title = $this->encodeAttribute($title); |
| 649 | - $result .= " title=\"$title\""; |
|
| 649 | + $result .= " title=\"$title\""; |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | $link_text = $this->runSpanGamut($link_text); |
@@ -712,22 +712,22 @@ discard block |
||
| 712 | 712 | return $text; |
| 713 | 713 | } |
| 714 | 714 | protected function _doImages_reference_callback($matches) { |
| 715 | - $whole_match = $matches[1]; |
|
| 716 | - $alt_text = $matches[2]; |
|
| 717 | - $link_id = strtolower($matches[3]); |
|
| 715 | + $whole_match = $matches[ 1 ]; |
|
| 716 | + $alt_text = $matches[ 2 ]; |
|
| 717 | + $link_id = strtolower($matches[ 3 ]); |
|
| 718 | 718 | |
| 719 | 719 | if ($link_id == "") { |
| 720 | 720 | $link_id = strtolower($alt_text); # for shortcut links like ![this][]. |
| 721 | 721 | } |
| 722 | 722 | |
| 723 | 723 | $alt_text = $this->encodeAttribute($alt_text); |
| 724 | - if (isset($this->urls[$link_id])) { |
|
| 725 | - $url = $this->encodeURLAttribute($this->urls[$link_id]); |
|
| 724 | + if (isset($this->urls[ $link_id ])) { |
|
| 725 | + $url = $this->encodeURLAttribute($this->urls[ $link_id ]); |
|
| 726 | 726 | $result = "<img src=\"$url\" alt=\"$alt_text\""; |
| 727 | - if (isset($this->titles[$link_id])) { |
|
| 728 | - $title = $this->titles[$link_id]; |
|
| 727 | + if (isset($this->titles[ $link_id ])) { |
|
| 728 | + $title = $this->titles[ $link_id ]; |
|
| 729 | 729 | $title = $this->encodeAttribute($title); |
| 730 | - $result .= " title=\"$title\""; |
|
| 730 | + $result .= " title=\"$title\""; |
|
| 731 | 731 | } |
| 732 | 732 | $result .= $this->empty_element_suffix; |
| 733 | 733 | $result = $this->hashPart($result); |
@@ -740,17 +740,17 @@ discard block |
||
| 740 | 740 | return $result; |
| 741 | 741 | } |
| 742 | 742 | protected function _doImages_inline_callback($matches) { |
| 743 | - $whole_match = $matches[1]; |
|
| 744 | - $alt_text = $matches[2]; |
|
| 745 | - $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 746 | - $title =& $matches[7]; |
|
| 743 | + $whole_match = $matches[ 1 ]; |
|
| 744 | + $alt_text = $matches[ 2 ]; |
|
| 745 | + $url = $matches[ 3 ] == '' ? $matches[ 4 ] : $matches[ 3 ]; |
|
| 746 | + $title = & $matches[ 7 ]; |
|
| 747 | 747 | |
| 748 | 748 | $alt_text = $this->encodeAttribute($alt_text); |
| 749 | 749 | $url = $this->encodeURLAttribute($url); |
| 750 | 750 | $result = "<img src=\"$url\" alt=\"$alt_text\""; |
| 751 | 751 | if (isset($title)) { |
| 752 | 752 | $title = $this->encodeAttribute($title); |
| 753 | - $result .= " title=\"$title\""; # $title already quoted |
|
| 753 | + $result .= " title=\"$title\""; # $title already quoted |
|
| 754 | 754 | } |
| 755 | 755 | $result .= $this->empty_element_suffix; |
| 756 | 756 | |
@@ -791,25 +791,25 @@ discard block |
||
| 791 | 791 | |
| 792 | 792 | protected function _doHeaders_callback_setext($matches) { |
| 793 | 793 | # Terrible hack to check we haven't found an empty list item. |
| 794 | - if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) |
|
| 795 | - return $matches[0]; |
|
| 794 | + if ($matches[ 2 ] == '-' && preg_match('{^-(?: |$)}', $matches[ 1 ])) |
|
| 795 | + return $matches[ 0 ]; |
|
| 796 | 796 | |
| 797 | - $level = $matches[2]{0} == '=' ? 1 : 2; |
|
| 797 | + $level = $matches[ 2 ]{0} == '=' ? 1 : 2; |
|
| 798 | 798 | |
| 799 | 799 | # id attribute generation |
| 800 | - $idAtt = $this->_generateIdFromHeaderValue($matches[1]); |
|
| 800 | + $idAtt = $this->_generateIdFromHeaderValue($matches[ 1 ]); |
|
| 801 | 801 | |
| 802 | - $block = "<h$level$idAtt>".$this->runSpanGamut($matches[1])."</h$level>"; |
|
| 803 | - return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 802 | + $block = "<h$level$idAtt>".$this->runSpanGamut($matches[ 1 ])."</h$level>"; |
|
| 803 | + return "\n".$this->hashBlock($block)."\n\n"; |
|
| 804 | 804 | } |
| 805 | 805 | protected function _doHeaders_callback_atx($matches) { |
| 806 | 806 | |
| 807 | 807 | # id attribute generation |
| 808 | - $idAtt = $this->_generateIdFromHeaderValue($matches[2]); |
|
| 808 | + $idAtt = $this->_generateIdFromHeaderValue($matches[ 2 ]); |
|
| 809 | 809 | |
| 810 | - $level = strlen($matches[1]); |
|
| 811 | - $block = "<h$level$idAtt>".$this->runSpanGamut($matches[2])."</h$level>"; |
|
| 812 | - return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 810 | + $level = strlen($matches[ 1 ]); |
|
| 811 | + $block = "<h$level$idAtt>".$this->runSpanGamut($matches[ 2 ])."</h$level>"; |
|
| 812 | + return "\n".$this->hashBlock($block)."\n\n"; |
|
| 813 | 813 | } |
| 814 | 814 | |
| 815 | 815 | protected function _generateIdFromHeaderValue($headerValue) { |
@@ -825,7 +825,7 @@ discard block |
||
| 825 | 825 | $idValue = call_user_func($this->header_id_func, $headerValue); |
| 826 | 826 | if (!$idValue) return ""; |
| 827 | 827 | |
| 828 | - return ' id="' . $this->encodeAttribute($idValue) . '"'; |
|
| 828 | + return ' id="'.$this->encodeAttribute($idValue).'"'; |
|
| 829 | 829 | |
| 830 | 830 | } |
| 831 | 831 | |
@@ -901,10 +901,10 @@ discard block |
||
| 901 | 901 | $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; |
| 902 | 902 | $marker_ol_start_re = '[0-9]+'; |
| 903 | 903 | |
| 904 | - $list = $matches[1]; |
|
| 905 | - $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol"; |
|
| 904 | + $list = $matches[ 1 ]; |
|
| 905 | + $list_type = preg_match("/$marker_ul_re/", $matches[ 4 ]) ? "ul" : "ol"; |
|
| 906 | 906 | |
| 907 | - $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re ); |
|
| 907 | + $marker_any_re = ($list_type == "ul" ? $marker_ul_re : $marker_ol_re); |
|
| 908 | 908 | |
| 909 | 909 | $list .= "\n"; |
| 910 | 910 | $result = $this->processListItems($list, $marker_any_re); |
@@ -914,19 +914,19 @@ discard block |
||
| 914 | 914 | # Get the start number for ordered list. |
| 915 | 915 | if ($list_type == 'ol') { |
| 916 | 916 | $ol_start_array = array(); |
| 917 | - $ol_start_check = preg_match("/$marker_ol_start_re/", $matches[4], $ol_start_array); |
|
| 918 | - if ($ol_start_check){ |
|
| 919 | - $ol_start = $ol_start_array[0]; |
|
| 917 | + $ol_start_check = preg_match("/$marker_ol_start_re/", $matches[ 4 ], $ol_start_array); |
|
| 918 | + if ($ol_start_check) { |
|
| 919 | + $ol_start = $ol_start_array[ 0 ]; |
|
| 920 | 920 | } |
| 921 | 921 | } |
| 922 | 922 | } |
| 923 | 923 | |
| 924 | - if ($ol_start > 1 && $list_type == 'ol'){ |
|
| 925 | - $result = $this->hashBlock("<$list_type start=\"$ol_start\">\n" . $result . "</$list_type>"); |
|
| 924 | + if ($ol_start > 1 && $list_type == 'ol') { |
|
| 925 | + $result = $this->hashBlock("<$list_type start=\"$ol_start\">\n".$result."</$list_type>"); |
|
| 926 | 926 | } else { |
| 927 | - $result = $this->hashBlock("<$list_type>\n" . $result . "</$list_type>"); |
|
| 927 | + $result = $this->hashBlock("<$list_type>\n".$result."</$list_type>"); |
|
| 928 | 928 | } |
| 929 | - return "\n". $result ."\n\n"; |
|
| 929 | + return "\n".$result."\n\n"; |
|
| 930 | 930 | } |
| 931 | 931 | |
| 932 | 932 | protected $list_level = 0; |
@@ -978,17 +978,17 @@ discard block |
||
| 978 | 978 | return $list_str; |
| 979 | 979 | } |
| 980 | 980 | protected function _processListItems_callback($matches) { |
| 981 | - $item = $matches[4]; |
|
| 982 | - $leading_line =& $matches[1]; |
|
| 983 | - $leading_space =& $matches[2]; |
|
| 984 | - $marker_space = $matches[3]; |
|
| 985 | - $tailing_blank_line =& $matches[5]; |
|
| 981 | + $item = $matches[ 4 ]; |
|
| 982 | + $leading_line = & $matches[ 1 ]; |
|
| 983 | + $leading_space = & $matches[ 2 ]; |
|
| 984 | + $marker_space = $matches[ 3 ]; |
|
| 985 | + $tailing_blank_line = & $matches[ 5 ]; |
|
| 986 | 986 | |
| 987 | 987 | if ($leading_line || $tailing_blank_line || |
| 988 | 988 | preg_match('/\n{2,}/', $item)) |
| 989 | 989 | { |
| 990 | 990 | # Replace marker with the appropriate whitespace indentation |
| 991 | - $item = $leading_space . str_repeat(' ', strlen($marker_space)) . $item; |
|
| 991 | + $item = $leading_space.str_repeat(' ', strlen($marker_space)).$item; |
|
| 992 | 992 | $item = $this->runBlockGamut($this->outdent($item)."\n"); |
| 993 | 993 | } |
| 994 | 994 | else { |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | $item = $this->runSpanGamut($item); |
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | - return "<li>" . $item . "</li>\n"; |
|
| 1001 | + return "<li>".$item."</li>\n"; |
|
| 1002 | 1002 | } |
| 1003 | 1003 | |
| 1004 | 1004 | |
@@ -1021,7 +1021,7 @@ discard block |
||
| 1021 | 1021 | return $text; |
| 1022 | 1022 | } |
| 1023 | 1023 | protected function _doCodeBlocks_callback($matches) { |
| 1024 | - $codeblock = $matches[1]; |
|
| 1024 | + $codeblock = $matches[ 1 ]; |
|
| 1025 | 1025 | |
| 1026 | 1026 | $codeblock = $this->outdent($codeblock); |
| 1027 | 1027 | $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); |
@@ -1069,15 +1069,15 @@ discard block |
||
| 1069 | 1069 | foreach ($this->strong_relist as $strong => $strong_re) { |
| 1070 | 1070 | # Construct list of allowed token expressions. |
| 1071 | 1071 | $token_relist = array(); |
| 1072 | - if (isset($this->em_strong_relist["$em$strong"])) { |
|
| 1073 | - $token_relist[] = $this->em_strong_relist["$em$strong"]; |
|
| 1072 | + if (isset($this->em_strong_relist[ "$em$strong" ])) { |
|
| 1073 | + $token_relist[ ] = $this->em_strong_relist[ "$em$strong" ]; |
|
| 1074 | 1074 | } |
| 1075 | - $token_relist[] = $em_re; |
|
| 1076 | - $token_relist[] = $strong_re; |
|
| 1075 | + $token_relist[ ] = $em_re; |
|
| 1076 | + $token_relist[ ] = $strong_re; |
|
| 1077 | 1077 | |
| 1078 | 1078 | # Construct master expression from list. |
| 1079 | - $token_re = '{('. implode('|', $token_relist) .')}'; |
|
| 1080 | - $this->em_strong_prepared_relist["$em$strong"] = $token_re; |
|
| 1079 | + $token_re = '{('.implode('|', $token_relist).')}'; |
|
| 1080 | + $this->em_strong_prepared_relist[ "$em$strong" ] = $token_re; |
|
| 1081 | 1081 | } |
| 1082 | 1082 | } |
| 1083 | 1083 | } |
@@ -1094,23 +1094,23 @@ discard block |
||
| 1094 | 1094 | # Get prepared regular expression for seraching emphasis tokens |
| 1095 | 1095 | # in current context. |
| 1096 | 1096 | # |
| 1097 | - $token_re = $this->em_strong_prepared_relist["$em$strong"]; |
|
| 1097 | + $token_re = $this->em_strong_prepared_relist[ "$em$strong" ]; |
|
| 1098 | 1098 | |
| 1099 | 1099 | # |
| 1100 | 1100 | # Each loop iteration search for the next emphasis token. |
| 1101 | 1101 | # Each token is then passed to handleSpanToken. |
| 1102 | 1102 | # |
| 1103 | 1103 | $parts = preg_split($token_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); |
| 1104 | - $text_stack[0] .= $parts[0]; |
|
| 1105 | - $token =& $parts[1]; |
|
| 1106 | - $text =& $parts[2]; |
|
| 1104 | + $text_stack[ 0 ] .= $parts[ 0 ]; |
|
| 1105 | + $token = & $parts[ 1 ]; |
|
| 1106 | + $text = & $parts[ 2 ]; |
|
| 1107 | 1107 | |
| 1108 | 1108 | if (empty($token)) { |
| 1109 | 1109 | # Reached end of text span: empty stack without emitting. |
| 1110 | 1110 | # any more emphasis. |
| 1111 | - while ($token_stack[0]) { |
|
| 1112 | - $text_stack[1] .= array_shift($token_stack); |
|
| 1113 | - $text_stack[0] .= array_shift($text_stack); |
|
| 1111 | + while ($token_stack[ 0 ]) { |
|
| 1112 | + $text_stack[ 1 ] .= array_shift($token_stack); |
|
| 1113 | + $text_stack[ 0 ] .= array_shift($text_stack); |
|
| 1114 | 1114 | } |
| 1115 | 1115 | break; |
| 1116 | 1116 | } |
@@ -1124,18 +1124,18 @@ discard block |
||
| 1124 | 1124 | $span = array_shift($text_stack); |
| 1125 | 1125 | $span = $this->runSpanGamut($span); |
| 1126 | 1126 | $span = "<strong><em>$span</em></strong>"; |
| 1127 | - $text_stack[0] .= $this->hashPart($span); |
|
| 1127 | + $text_stack[ 0 ] .= $this->hashPart($span); |
|
| 1128 | 1128 | $em = ''; |
| 1129 | 1129 | $strong = ''; |
| 1130 | 1130 | } else { |
| 1131 | 1131 | # Other closing marker: close one em or strong and |
| 1132 | 1132 | # change current token state to match the other |
| 1133 | - $token_stack[0] = str_repeat($token{0}, 3-$token_len); |
|
| 1133 | + $token_stack[ 0 ] = str_repeat($token{0}, 3 - $token_len); |
|
| 1134 | 1134 | $tag = $token_len == 2 ? "strong" : "em"; |
| 1135 | - $span = $text_stack[0]; |
|
| 1135 | + $span = $text_stack[ 0 ]; |
|
| 1136 | 1136 | $span = $this->runSpanGamut($span); |
| 1137 | 1137 | $span = "<$tag>$span</$tag>"; |
| 1138 | - $text_stack[0] = $this->hashPart($span); |
|
| 1138 | + $text_stack[ 0 ] = $this->hashPart($span); |
|
| 1139 | 1139 | $$tag = ''; # $$tag stands for $em or $strong |
| 1140 | 1140 | } |
| 1141 | 1141 | $tree_char_em = false; |
@@ -1149,7 +1149,7 @@ discard block |
||
| 1149 | 1149 | $span = array_shift($text_stack); |
| 1150 | 1150 | $span = $this->runSpanGamut($span); |
| 1151 | 1151 | $span = "<$tag>$span</$tag>"; |
| 1152 | - $text_stack[0] .= $this->hashPart($span); |
|
| 1152 | + $text_stack[ 0 ] .= $this->hashPart($span); |
|
| 1153 | 1153 | $$tag = ''; # $$tag stands for $em or $strong |
| 1154 | 1154 | } |
| 1155 | 1155 | } else { |
@@ -1164,16 +1164,16 @@ discard block |
||
| 1164 | 1164 | } else if ($token_len == 2) { |
| 1165 | 1165 | if ($strong) { |
| 1166 | 1166 | # Unwind any dangling emphasis marker: |
| 1167 | - if (strlen($token_stack[0]) == 1) { |
|
| 1168 | - $text_stack[1] .= array_shift($token_stack); |
|
| 1169 | - $text_stack[0] .= array_shift($text_stack); |
|
| 1167 | + if (strlen($token_stack[ 0 ]) == 1) { |
|
| 1168 | + $text_stack[ 1 ] .= array_shift($token_stack); |
|
| 1169 | + $text_stack[ 0 ] .= array_shift($text_stack); |
|
| 1170 | 1170 | } |
| 1171 | 1171 | # Closing strong marker: |
| 1172 | 1172 | array_shift($token_stack); |
| 1173 | 1173 | $span = array_shift($text_stack); |
| 1174 | 1174 | $span = $this->runSpanGamut($span); |
| 1175 | 1175 | $span = "<strong>$span</strong>"; |
| 1176 | - $text_stack[0] .= $this->hashPart($span); |
|
| 1176 | + $text_stack[ 0 ] .= $this->hashPart($span); |
|
| 1177 | 1177 | $strong = ''; |
| 1178 | 1178 | } else { |
| 1179 | 1179 | array_unshift($token_stack, $token); |
@@ -1183,16 +1183,16 @@ discard block |
||
| 1183 | 1183 | } else { |
| 1184 | 1184 | # Here $token_len == 1 |
| 1185 | 1185 | if ($em) { |
| 1186 | - if (strlen($token_stack[0]) == 1) { |
|
| 1186 | + if (strlen($token_stack[ 0 ]) == 1) { |
|
| 1187 | 1187 | # Closing emphasis marker: |
| 1188 | 1188 | array_shift($token_stack); |
| 1189 | 1189 | $span = array_shift($text_stack); |
| 1190 | 1190 | $span = $this->runSpanGamut($span); |
| 1191 | 1191 | $span = "<em>$span</em>"; |
| 1192 | - $text_stack[0] .= $this->hashPart($span); |
|
| 1192 | + $text_stack[ 0 ] .= $this->hashPart($span); |
|
| 1193 | 1193 | $em = ''; |
| 1194 | 1194 | } else { |
| 1195 | - $text_stack[0] .= $token; |
|
| 1195 | + $text_stack[ 0 ] .= $token; |
|
| 1196 | 1196 | } |
| 1197 | 1197 | } else { |
| 1198 | 1198 | array_unshift($token_stack, $token); |
@@ -1201,7 +1201,7 @@ discard block |
||
| 1201 | 1201 | } |
| 1202 | 1202 | } |
| 1203 | 1203 | } |
| 1204 | - return $text_stack[0]; |
|
| 1204 | + return $text_stack[ 0 ]; |
|
| 1205 | 1205 | } |
| 1206 | 1206 | |
| 1207 | 1207 | |
@@ -1221,10 +1221,10 @@ discard block |
||
| 1221 | 1221 | return $text; |
| 1222 | 1222 | } |
| 1223 | 1223 | protected function _doBlockQuotes_callback($matches) { |
| 1224 | - $bq = $matches[1]; |
|
| 1224 | + $bq = $matches[ 1 ]; |
|
| 1225 | 1225 | # trim one level of quoting - trim whitespace-only lines |
| 1226 | 1226 | $bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq); |
| 1227 | - $bq = $this->runBlockGamut($bq); # recurse |
|
| 1227 | + $bq = $this->runBlockGamut($bq); # recurse |
|
| 1228 | 1228 | |
| 1229 | 1229 | $bq = preg_replace('/^/m', " ", $bq); |
| 1230 | 1230 | # These leading spaces cause problem with <pre> content, |
@@ -1232,10 +1232,10 @@ discard block |
||
| 1232 | 1232 | $bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx', |
| 1233 | 1233 | array($this, '_doBlockQuotes_callback2'), $bq); |
| 1234 | 1234 | |
| 1235 | - return "\n". $this->hashBlock("<blockquote>\n$bq\n</blockquote>")."\n\n"; |
|
| 1235 | + return "\n".$this->hashBlock("<blockquote>\n$bq\n</blockquote>")."\n\n"; |
|
| 1236 | 1236 | } |
| 1237 | 1237 | protected function _doBlockQuotes_callback2($matches) { |
| 1238 | - $pre = $matches[1]; |
|
| 1238 | + $pre = $matches[ 1 ]; |
|
| 1239 | 1239 | $pre = preg_replace('/^ /m', '', $pre); |
| 1240 | 1240 | return $pre; |
| 1241 | 1241 | } |
@@ -1260,13 +1260,13 @@ discard block |
||
| 1260 | 1260 | $value = $this->runSpanGamut($value); |
| 1261 | 1261 | $value = preg_replace('/^([ ]*)/', "<p>", $value); |
| 1262 | 1262 | $value .= "</p>"; |
| 1263 | - $grafs[$key] = $this->unhash($value); |
|
| 1263 | + $grafs[ $key ] = $this->unhash($value); |
|
| 1264 | 1264 | } |
| 1265 | 1265 | else { |
| 1266 | 1266 | # Is a block. |
| 1267 | 1267 | # Modify elements of @grafs in-place... |
| 1268 | 1268 | $graf = $value; |
| 1269 | - $block = $this->html_hashes[$graf]; |
|
| 1269 | + $block = $this->html_hashes[ $graf ]; |
|
| 1270 | 1270 | $graf = $block; |
| 1271 | 1271 | // if (preg_match('{ |
| 1272 | 1272 | // \A |
@@ -1303,7 +1303,7 @@ discard block |
||
| 1303 | 1303 | // |
| 1304 | 1304 | // $graf = $div_open . "\n" . $div_content . "\n" . $div_close; |
| 1305 | 1305 | // } |
| 1306 | - $grafs[$key] = $graf; |
|
| 1306 | + $grafs[ $key ] = $graf; |
|
| 1307 | 1307 | } |
| 1308 | 1308 | } |
| 1309 | 1309 | |
@@ -1398,12 +1398,12 @@ discard block |
||
| 1398 | 1398 | return $text; |
| 1399 | 1399 | } |
| 1400 | 1400 | protected function _doAutoLinks_url_callback($matches) { |
| 1401 | - $url = $this->encodeURLAttribute($matches[1], $text); |
|
| 1401 | + $url = $this->encodeURLAttribute($matches[ 1 ], $text); |
|
| 1402 | 1402 | $link = "<a href=\"$url\">$text</a>"; |
| 1403 | 1403 | return $this->hashPart($link); |
| 1404 | 1404 | } |
| 1405 | 1405 | protected function _doAutoLinks_email_callback($matches) { |
| 1406 | - $addr = $matches[1]; |
|
| 1406 | + $addr = $matches[ 1 ]; |
|
| 1407 | 1407 | $url = $this->encodeURLAttribute("mailto:$addr", $text); |
| 1408 | 1408 | $link = "<a href=\"$url\">$text</a>"; |
| 1409 | 1409 | return $this->hashPart($link); |
@@ -1432,7 +1432,7 @@ discard block |
||
| 1432 | 1432 | if ($text == "") return $tail = ""; |
| 1433 | 1433 | |
| 1434 | 1434 | $chars = preg_split('/(?<!^)(?!$)/', $text); |
| 1435 | - $seed = (int)abs(crc32($text) / strlen($text)); # Deterministic seed. |
|
| 1435 | + $seed = (int) abs(crc32($text) / strlen($text)); # Deterministic seed. |
|
| 1436 | 1436 | |
| 1437 | 1437 | foreach ($chars as $key => $char) { |
| 1438 | 1438 | $ord = ord($char); |
@@ -1443,8 +1443,8 @@ discard block |
||
| 1443 | 1443 | # '@' *must* be encoded. I insist. |
| 1444 | 1444 | # '"' and '>' have to be encoded inside the attribute |
| 1445 | 1445 | if ($r > 90 && strpos('@"&>', $char) === false) /* do nothing */; |
| 1446 | - else if ($r < 45) $chars[$key] = '&#x'.dechex($ord).';'; |
|
| 1447 | - else $chars[$key] = '&#'.$ord.';'; |
|
| 1446 | + else if ($r < 45) $chars[ $key ] = '&#x'.dechex($ord).';'; |
|
| 1447 | + else $chars[ $key ] = '&#'.$ord.';'; |
|
| 1448 | 1448 | } |
| 1449 | 1449 | } |
| 1450 | 1450 | |
@@ -1468,7 +1468,7 @@ discard block |
||
| 1468 | 1468 | | |
| 1469 | 1469 | (?<![`\\\\]) |
| 1470 | 1470 | `+ # code span marker |
| 1471 | - '.( $this->no_markup ? '' : ' |
|
| 1471 | + '.($this->no_markup ? '' : ' |
|
| 1472 | 1472 | | |
| 1473 | 1473 | <!-- .*? --> # comment |
| 1474 | 1474 | | |
@@ -1497,14 +1497,14 @@ discard block |
||
| 1497 | 1497 | $parts = preg_split($span_re, $str, 2, PREG_SPLIT_DELIM_CAPTURE); |
| 1498 | 1498 | |
| 1499 | 1499 | # Create token from text preceding tag. |
| 1500 | - if ($parts[0] != "") { |
|
| 1501 | - $output .= $parts[0]; |
|
| 1500 | + if ($parts[ 0 ] != "") { |
|
| 1501 | + $output .= $parts[ 0 ]; |
|
| 1502 | 1502 | } |
| 1503 | 1503 | |
| 1504 | 1504 | # Check if we reach the end. |
| 1505 | - if (isset($parts[1])) { |
|
| 1506 | - $output .= $this->handleSpanToken($parts[1], $parts[2]); |
|
| 1507 | - $str = $parts[2]; |
|
| 1505 | + if (isset($parts[ 1 ])) { |
|
| 1506 | + $output .= $this->handleSpanToken($parts[ 1 ], $parts[ 2 ]); |
|
| 1507 | + $str = $parts[ 2 ]; |
|
| 1508 | 1508 | } |
| 1509 | 1509 | else { |
| 1510 | 1510 | break; |
@@ -1522,14 +1522,14 @@ discard block |
||
| 1522 | 1522 | # |
| 1523 | 1523 | switch ($token{0}) { |
| 1524 | 1524 | case "\\": |
| 1525 | - return $this->hashPart("&#". ord($token{1}). ";"); |
|
| 1525 | + return $this->hashPart("&#".ord($token{1}).";"); |
|
| 1526 | 1526 | case "`": |
| 1527 | 1527 | # Search for end marker in remaining text. |
| 1528 | 1528 | if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm', |
| 1529 | 1529 | $str, $matches)) |
| 1530 | 1530 | { |
| 1531 | - $str = $matches[2]; |
|
| 1532 | - $codespan = $this->makeCodeSpan($matches[1]); |
|
| 1531 | + $str = $matches[ 2 ]; |
|
| 1532 | + $codespan = $this->makeCodeSpan($matches[ 1 ]); |
|
| 1533 | 1533 | return $this->hashPart($codespan); |
| 1534 | 1534 | } |
| 1535 | 1535 | return $token; // return as text since no ending marker found. |
@@ -1565,19 +1565,19 @@ discard block |
||
| 1565 | 1565 | return $text; |
| 1566 | 1566 | } |
| 1567 | 1567 | protected function _detab_callback($matches) { |
| 1568 | - $line = $matches[0]; |
|
| 1568 | + $line = $matches[ 0 ]; |
|
| 1569 | 1569 | $strlen = $this->utf8_strlen; # strlen function for UTF-8. |
| 1570 | 1570 | |
| 1571 | 1571 | # Split in blocks. |
| 1572 | 1572 | $blocks = explode("\t", $line); |
| 1573 | 1573 | # Add each blocks to the line. |
| 1574 | - $line = $blocks[0]; |
|
| 1575 | - unset($blocks[0]); # Do not add first block twice. |
|
| 1574 | + $line = $blocks[ 0 ]; |
|
| 1575 | + unset($blocks[ 0 ]); # Do not add first block twice. |
|
| 1576 | 1576 | foreach ($blocks as $block) { |
| 1577 | 1577 | # Calculate amount of space, insert spaces, insert block. |
| 1578 | 1578 | $amount = $this->tab_width - |
| 1579 | 1579 | $strlen($line, 'UTF-8') % $this->tab_width; |
| 1580 | - $line .= str_repeat(" ", $amount) . $block; |
|
| 1580 | + $line .= str_repeat(" ", $amount).$block; |
|
| 1581 | 1581 | } |
| 1582 | 1582 | return $line; |
| 1583 | 1583 | } |
@@ -1603,7 +1603,7 @@ discard block |
||
| 1603 | 1603 | array($this, '_unhash_callback'), $text); |
| 1604 | 1604 | } |
| 1605 | 1605 | protected function _unhash_callback($matches) { |
| 1606 | - return $this->html_hashes[$matches[0]]; |
|
| 1606 | + return $this->html_hashes[ $matches[ 0 ] ]; |
|
| 1607 | 1607 | } |
| 1608 | 1608 | |
| 1609 | 1609 | } |
@@ -38,8 +38,9 @@ discard block |
||
| 38 | 38 | $parser =& $parser_list[$parser_class]; |
| 39 | 39 | |
| 40 | 40 | # create the parser it not already set |
| 41 | - if (!$parser) |
|
| 42 | - $parser = new $parser_class; |
|
| 41 | + if (!$parser) { |
|
| 42 | + $parser = new $parser_class; |
|
| 43 | + } |
|
| 43 | 44 | |
| 44 | 45 | # Transform text using parser. |
| 45 | 46 | return $parser->transform($text); |
@@ -241,7 +242,9 @@ discard block |
||
| 241 | 242 | |
| 242 | 243 | |
| 243 | 244 | protected function hashHTMLBlocks($text) { |
| 244 | - if ($this->no_markup) return $text; |
|
| 245 | + if ($this->no_markup) { |
|
| 246 | + return $text; |
|
| 247 | + } |
|
| 245 | 248 | |
| 246 | 249 | $less_than_tab = $this->tab_width - 1; |
| 247 | 250 | |
@@ -529,7 +532,9 @@ discard block |
||
| 529 | 532 | # |
| 530 | 533 | # Turn Markdown link shortcuts into XHTML <a> tags. |
| 531 | 534 | # |
| 532 | - if ($this->in_anchor) return $text; |
|
| 535 | + if ($this->in_anchor) { |
|
| 536 | + return $text; |
|
| 537 | + } |
|
| 533 | 538 | $this->in_anchor = true; |
| 534 | 539 | |
| 535 | 540 | # |
@@ -623,8 +628,7 @@ discard block |
||
| 623 | 628 | $link_text = $this->runSpanGamut($link_text); |
| 624 | 629 | $result .= ">$link_text</a>"; |
| 625 | 630 | $result = $this->hashPart($result); |
| 626 | - } |
|
| 627 | - else { |
|
| 631 | + } else { |
|
| 628 | 632 | $result = $whole_match; |
| 629 | 633 | } |
| 630 | 634 | return $result; |
@@ -638,8 +642,9 @@ discard block |
||
| 638 | 642 | // if the URL was of the form <s p a c e s> it got caught by the HTML |
| 639 | 643 | // tag parser and hashed. Need to reverse the process before using the URL. |
| 640 | 644 | $unhashed = $this->unhash($url); |
| 641 | - if ($unhashed != $url) |
|
| 642 | - $url = preg_replace('/^<(.*)>$/', '\1', $unhashed); |
|
| 645 | + if ($unhashed != $url) { |
|
| 646 | + $url = preg_replace('/^<(.*)>$/', '\1', $unhashed); |
|
| 647 | + } |
|
| 643 | 648 | |
| 644 | 649 | $url = $this->encodeURLAttribute($url); |
| 645 | 650 | |
@@ -731,8 +736,7 @@ discard block |
||
| 731 | 736 | } |
| 732 | 737 | $result .= $this->empty_element_suffix; |
| 733 | 738 | $result = $this->hashPart($result); |
| 734 | - } |
|
| 735 | - else { |
|
| 739 | + } else { |
|
| 736 | 740 | # If there's no such link ID, leave intact: |
| 737 | 741 | $result = $whole_match; |
| 738 | 742 | } |
@@ -791,8 +795,9 @@ discard block |
||
| 791 | 795 | |
| 792 | 796 | protected function _doHeaders_callback_setext($matches) { |
| 793 | 797 | # Terrible hack to check we haven't found an empty list item. |
| 794 | - if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) |
|
| 795 | - return $matches[0]; |
|
| 798 | + if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) { |
|
| 799 | + return $matches[0]; |
|
| 800 | + } |
|
| 796 | 801 | |
| 797 | 802 | $level = $matches[2]{0} == '=' ? 1 : 2; |
| 798 | 803 | |
@@ -823,7 +828,9 @@ discard block |
||
| 823 | 828 | return ""; |
| 824 | 829 | } |
| 825 | 830 | $idValue = call_user_func($this->header_id_func, $headerValue); |
| 826 | - if (!$idValue) return ""; |
|
| 831 | + if (!$idValue) { |
|
| 832 | + return ""; |
|
| 833 | + } |
|
| 827 | 834 | |
| 828 | 835 | return ' id="' . $this->encodeAttribute($idValue) . '"'; |
| 829 | 836 | |
@@ -882,8 +889,7 @@ discard block |
||
| 882 | 889 | '.$whole_list_re.' |
| 883 | 890 | }mx', |
| 884 | 891 | array($this, '_doLists_callback'), $text); |
| 885 | - } |
|
| 886 | - else { |
|
| 892 | + } else { |
|
| 887 | 893 | $text = preg_replace_callback('{ |
| 888 | 894 | (?:(?<=\n)\n|\A\n?) # Must eat the newline |
| 889 | 895 | '.$whole_list_re.' |
@@ -990,8 +996,7 @@ discard block |
||
| 990 | 996 | # Replace marker with the appropriate whitespace indentation |
| 991 | 997 | $item = $leading_space . str_repeat(' ', strlen($marker_space)) . $item; |
| 992 | 998 | $item = $this->runBlockGamut($this->outdent($item)."\n"); |
| 993 | - } |
|
| 994 | - else { |
|
| 999 | + } else { |
|
| 995 | 1000 | # Recursion for sub-lists: |
| 996 | 1001 | $item = $this->doLists($this->outdent($item)); |
| 997 | 1002 | $item = preg_replace('/\n+$/', '', $item); |
@@ -1261,8 +1266,7 @@ discard block |
||
| 1261 | 1266 | $value = preg_replace('/^([ ]*)/', "<p>", $value); |
| 1262 | 1267 | $value .= "</p>"; |
| 1263 | 1268 | $grafs[$key] = $this->unhash($value); |
| 1264 | - } |
|
| 1265 | - else { |
|
| 1269 | + } else { |
|
| 1266 | 1270 | # Is a block. |
| 1267 | 1271 | # Modify elements of @grafs in-place... |
| 1268 | 1272 | $graf = $value; |
@@ -1329,17 +1333,17 @@ discard block |
||
| 1329 | 1333 | # representation for the URL (removing mailto: or tel:) storing it in $text. |
| 1330 | 1334 | # This function is *not* suitable for attributes enclosed in single quotes. |
| 1331 | 1335 | # |
| 1332 | - if ($this->url_filter_func) |
|
| 1333 | - $url = call_user_func($this->url_filter_func, $url); |
|
| 1336 | + if ($this->url_filter_func) { |
|
| 1337 | + $url = call_user_func($this->url_filter_func, $url); |
|
| 1338 | + } |
|
| 1334 | 1339 | |
| 1335 | - if (preg_match('{^mailto:}i', $url)) |
|
| 1336 | - $url = $this->encodeEntityObfuscatedAttribute($url, $text, 7); |
|
| 1337 | - else if (preg_match('{^tel:}i', $url)) |
|
| 1340 | + if (preg_match('{^mailto:}i', $url)) { |
|
| 1341 | + $url = $this->encodeEntityObfuscatedAttribute($url, $text, 7); |
|
| 1342 | + } else if (preg_match('{^tel:}i', $url)) |
|
| 1338 | 1343 | { |
| 1339 | 1344 | $url = $this->encodeAttribute($url); |
| 1340 | 1345 | $text = substr($url, 4); |
| 1341 | - } |
|
| 1342 | - else |
|
| 1346 | + } else |
|
| 1343 | 1347 | { |
| 1344 | 1348 | $url = $this->encodeAttribute($url); |
| 1345 | 1349 | $text = $url; |
@@ -1429,7 +1433,9 @@ discard block |
||
| 1429 | 1433 | # With some optimizations by Milian Wolff. Forced encoding of HTML |
| 1430 | 1434 | # attribute special characters by Allan Odgaard. |
| 1431 | 1435 | # |
| 1432 | - if ($text == "") return $tail = ""; |
|
| 1436 | + if ($text == "") { |
|
| 1437 | + return $tail = ""; |
|
| 1438 | + } |
|
| 1433 | 1439 | |
| 1434 | 1440 | $chars = preg_split('/(?<!^)(?!$)/', $text); |
| 1435 | 1441 | $seed = (int)abs(crc32($text) / strlen($text)); # Deterministic seed. |
@@ -1443,8 +1449,11 @@ discard block |
||
| 1443 | 1449 | # '@' *must* be encoded. I insist. |
| 1444 | 1450 | # '"' and '>' have to be encoded inside the attribute |
| 1445 | 1451 | if ($r > 90 && strpos('@"&>', $char) === false) /* do nothing */; |
| 1446 | - else if ($r < 45) $chars[$key] = '&#x'.dechex($ord).';'; |
|
| 1447 | - else $chars[$key] = '&#'.$ord.';'; |
|
| 1452 | + else if ($r < 45) { |
|
| 1453 | + $chars[$key] = '&#x'.dechex($ord).';'; |
|
| 1454 | + } else { |
|
| 1455 | + $chars[$key] = '&#'.$ord.';'; |
|
| 1456 | + } |
|
| 1448 | 1457 | } |
| 1449 | 1458 | } |
| 1450 | 1459 | |
@@ -1505,8 +1514,7 @@ discard block |
||
| 1505 | 1514 | if (isset($parts[1])) { |
| 1506 | 1515 | $output .= $this->handleSpanToken($parts[1], $parts[2]); |
| 1507 | 1516 | $str = $parts[2]; |
| 1508 | - } |
|
| 1509 | - else { |
|
| 1517 | + } else { |
|
| 1510 | 1518 | break; |
| 1511 | 1519 | } |
| 1512 | 1520 | } |
@@ -1588,7 +1596,9 @@ discard block |
||
| 1588 | 1596 | # function that will loosely count the number of UTF-8 characters with a |
| 1589 | 1597 | # regular expression. |
| 1590 | 1598 | # |
| 1591 | - if (function_exists($this->utf8_strlen)) return; |
|
| 1599 | + if (function_exists($this->utf8_strlen)) { |
|
| 1600 | + return; |
|
| 1601 | + } |
|
| 1592 | 1602 | $this->utf8_strlen = create_function('$text', 'return preg_match_all( |
| 1593 | 1603 | "/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/", |
| 1594 | 1604 | $text, $m);'); |
@@ -516,6 +516,12 @@ discard block |
||
| 516 | 516 | |
| 517 | 517 | return array($parsed, $text); |
| 518 | 518 | } |
| 519 | + |
|
| 520 | + /** |
|
| 521 | + * @param string $text |
|
| 522 | + * @param string $hash_method |
|
| 523 | + * @param boolean $md_attr |
|
| 524 | + */ |
|
| 519 | 525 | protected function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { |
| 520 | 526 | # |
| 521 | 527 | # Parse HTML, calling _HashHTMLBlocks_InMarkdown for block tags. |
@@ -1077,6 +1083,10 @@ discard block |
||
| 1077 | 1083 | |
| 1078 | 1084 | return $this->_doTable_callback(array($matches[0], $head, $underline, $content)); |
| 1079 | 1085 | } |
| 1086 | + |
|
| 1087 | + /** |
|
| 1088 | + * @param string $alignname |
|
| 1089 | + */ |
|
| 1080 | 1090 | protected function _doTable_makeAlignAttr($alignname) |
| 1081 | 1091 | { |
| 1082 | 1092 | if (empty($this->table_align_class_tmpl)) |
@@ -1203,6 +1213,9 @@ discard block |
||
| 1203 | 1213 | } |
| 1204 | 1214 | |
| 1205 | 1215 | |
| 1216 | + /** |
|
| 1217 | + * @return string |
|
| 1218 | + */ |
|
| 1206 | 1219 | protected function processDefListItems($list_str) { |
| 1207 | 1220 | # |
| 1208 | 1221 | # Process the contents of a single definition list, splitting it |
@@ -19,179 +19,179 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | class MarkdownExtra extends \Michelf\Markdown { |
| 21 | 21 | |
| 22 | - ### Configuration Variables ### |
|
| 22 | + ### Configuration Variables ### |
|
| 23 | 23 | |
| 24 | - # Prefix for footnote ids. |
|
| 25 | - public $fn_id_prefix = ""; |
|
| 24 | + # Prefix for footnote ids. |
|
| 25 | + public $fn_id_prefix = ""; |
|
| 26 | 26 | |
| 27 | - # Optional title attribute for footnote links and backlinks. |
|
| 28 | - public $fn_link_title = ""; |
|
| 29 | - public $fn_backlink_title = ""; |
|
| 27 | + # Optional title attribute for footnote links and backlinks. |
|
| 28 | + public $fn_link_title = ""; |
|
| 29 | + public $fn_backlink_title = ""; |
|
| 30 | 30 | |
| 31 | - # Optional class attribute for footnote links and backlinks. |
|
| 32 | - public $fn_link_class = "footnote-ref"; |
|
| 33 | - public $fn_backlink_class = "footnote-backref"; |
|
| 34 | - |
|
| 35 | - # Class name for table cell alignment (%% replaced left/center/right) |
|
| 36 | - # For instance: 'go-%%' becomes 'go-left' or 'go-right' or 'go-center' |
|
| 37 | - # If empty, the align attribute is used instead of a class name. |
|
| 38 | - public $table_align_class_tmpl = ''; |
|
| 39 | - |
|
| 40 | - # Optional class prefix for fenced code block. |
|
| 41 | - public $code_class_prefix = ""; |
|
| 42 | - # Class attribute for code blocks goes on the `code` tag; |
|
| 43 | - # setting this to true will put attributes on the `pre` tag instead. |
|
| 44 | - public $code_attr_on_pre = false; |
|
| 31 | + # Optional class attribute for footnote links and backlinks. |
|
| 32 | + public $fn_link_class = "footnote-ref"; |
|
| 33 | + public $fn_backlink_class = "footnote-backref"; |
|
| 34 | + |
|
| 35 | + # Class name for table cell alignment (%% replaced left/center/right) |
|
| 36 | + # For instance: 'go-%%' becomes 'go-left' or 'go-right' or 'go-center' |
|
| 37 | + # If empty, the align attribute is used instead of a class name. |
|
| 38 | + public $table_align_class_tmpl = ''; |
|
| 39 | + |
|
| 40 | + # Optional class prefix for fenced code block. |
|
| 41 | + public $code_class_prefix = ""; |
|
| 42 | + # Class attribute for code blocks goes on the `code` tag; |
|
| 43 | + # setting this to true will put attributes on the `pre` tag instead. |
|
| 44 | + public $code_attr_on_pre = false; |
|
| 45 | 45 | |
| 46 | - # Predefined abbreviations. |
|
| 47 | - public $predef_abbr = array(); |
|
| 48 | - |
|
| 49 | - ### Parser Implementation ### |
|
| 50 | - |
|
| 51 | - public function __construct() { |
|
| 52 | - # |
|
| 53 | - # Constructor function. Initialize the parser object. |
|
| 54 | - # |
|
| 55 | - # Add extra escapable characters before parent constructor |
|
| 56 | - # initialize the table. |
|
| 57 | - $this->escape_chars .= ':|'; |
|
| 46 | + # Predefined abbreviations. |
|
| 47 | + public $predef_abbr = array(); |
|
| 48 | + |
|
| 49 | + ### Parser Implementation ### |
|
| 50 | + |
|
| 51 | + public function __construct() { |
|
| 52 | + # |
|
| 53 | + # Constructor function. Initialize the parser object. |
|
| 54 | + # |
|
| 55 | + # Add extra escapable characters before parent constructor |
|
| 56 | + # initialize the table. |
|
| 57 | + $this->escape_chars .= ':|'; |
|
| 58 | 58 | |
| 59 | - # Insert extra document, block, and span transformations. |
|
| 60 | - # Parent constructor will do the sorting. |
|
| 61 | - $this->document_gamut += array( |
|
| 62 | - "doFencedCodeBlocks" => 5, |
|
| 63 | - "stripFootnotes" => 15, |
|
| 64 | - "stripAbbreviations" => 25, |
|
| 65 | - "appendFootnotes" => 50, |
|
| 66 | - ); |
|
| 67 | - $this->block_gamut += array( |
|
| 68 | - "doFencedCodeBlocks" => 5, |
|
| 69 | - "doTables" => 15, |
|
| 70 | - "doDefLists" => 45, |
|
| 71 | - ); |
|
| 72 | - $this->span_gamut += array( |
|
| 73 | - "doFootnotes" => 5, |
|
| 74 | - "doAbbreviations" => 70, |
|
| 75 | - ); |
|
| 59 | + # Insert extra document, block, and span transformations. |
|
| 60 | + # Parent constructor will do the sorting. |
|
| 61 | + $this->document_gamut += array( |
|
| 62 | + "doFencedCodeBlocks" => 5, |
|
| 63 | + "stripFootnotes" => 15, |
|
| 64 | + "stripAbbreviations" => 25, |
|
| 65 | + "appendFootnotes" => 50, |
|
| 66 | + ); |
|
| 67 | + $this->block_gamut += array( |
|
| 68 | + "doFencedCodeBlocks" => 5, |
|
| 69 | + "doTables" => 15, |
|
| 70 | + "doDefLists" => 45, |
|
| 71 | + ); |
|
| 72 | + $this->span_gamut += array( |
|
| 73 | + "doFootnotes" => 5, |
|
| 74 | + "doAbbreviations" => 70, |
|
| 75 | + ); |
|
| 76 | 76 | |
| 77 | - $this->enhanced_ordered_list = true; |
|
| 78 | - parent::__construct(); |
|
| 79 | - } |
|
| 77 | + $this->enhanced_ordered_list = true; |
|
| 78 | + parent::__construct(); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | 81 | |
| 82 | - # Extra variables used during extra transformations. |
|
| 83 | - protected $footnotes = array(); |
|
| 84 | - protected $footnotes_ordered = array(); |
|
| 85 | - protected $footnotes_ref_count = array(); |
|
| 86 | - protected $footnotes_numbers = array(); |
|
| 87 | - protected $abbr_desciptions = array(); |
|
| 88 | - protected $abbr_word_re = ''; |
|
| 82 | + # Extra variables used during extra transformations. |
|
| 83 | + protected $footnotes = array(); |
|
| 84 | + protected $footnotes_ordered = array(); |
|
| 85 | + protected $footnotes_ref_count = array(); |
|
| 86 | + protected $footnotes_numbers = array(); |
|
| 87 | + protected $abbr_desciptions = array(); |
|
| 88 | + protected $abbr_word_re = ''; |
|
| 89 | 89 | |
| 90 | - # Give the current footnote number. |
|
| 91 | - protected $footnote_counter = 1; |
|
| 90 | + # Give the current footnote number. |
|
| 91 | + protected $footnote_counter = 1; |
|
| 92 | 92 | |
| 93 | 93 | |
| 94 | - protected function setup() { |
|
| 95 | - # |
|
| 96 | - # Setting up Extra-specific variables. |
|
| 97 | - # |
|
| 98 | - parent::setup(); |
|
| 94 | + protected function setup() { |
|
| 95 | + # |
|
| 96 | + # Setting up Extra-specific variables. |
|
| 97 | + # |
|
| 98 | + parent::setup(); |
|
| 99 | 99 | |
| 100 | - $this->footnotes = array(); |
|
| 101 | - $this->footnotes_ordered = array(); |
|
| 102 | - $this->footnotes_ref_count = array(); |
|
| 103 | - $this->footnotes_numbers = array(); |
|
| 104 | - $this->abbr_desciptions = array(); |
|
| 105 | - $this->abbr_word_re = ''; |
|
| 106 | - $this->footnote_counter = 1; |
|
| 100 | + $this->footnotes = array(); |
|
| 101 | + $this->footnotes_ordered = array(); |
|
| 102 | + $this->footnotes_ref_count = array(); |
|
| 103 | + $this->footnotes_numbers = array(); |
|
| 104 | + $this->abbr_desciptions = array(); |
|
| 105 | + $this->abbr_word_re = ''; |
|
| 106 | + $this->footnote_counter = 1; |
|
| 107 | 107 | |
| 108 | - foreach ($this->predef_abbr as $abbr_word => $abbr_desc) { |
|
| 109 | - if ($this->abbr_word_re) |
|
| 110 | - $this->abbr_word_re .= '|'; |
|
| 111 | - $this->abbr_word_re .= preg_quote($abbr_word); |
|
| 112 | - $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); |
|
| 113 | - } |
|
| 114 | - } |
|
| 108 | + foreach ($this->predef_abbr as $abbr_word => $abbr_desc) { |
|
| 109 | + if ($this->abbr_word_re) |
|
| 110 | + $this->abbr_word_re .= '|'; |
|
| 111 | + $this->abbr_word_re .= preg_quote($abbr_word); |
|
| 112 | + $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - protected function teardown() { |
|
| 117 | - # |
|
| 118 | - # Clearing Extra-specific variables. |
|
| 119 | - # |
|
| 120 | - $this->footnotes = array(); |
|
| 121 | - $this->footnotes_ordered = array(); |
|
| 122 | - $this->footnotes_ref_count = array(); |
|
| 123 | - $this->footnotes_numbers = array(); |
|
| 124 | - $this->abbr_desciptions = array(); |
|
| 125 | - $this->abbr_word_re = ''; |
|
| 116 | + protected function teardown() { |
|
| 117 | + # |
|
| 118 | + # Clearing Extra-specific variables. |
|
| 119 | + # |
|
| 120 | + $this->footnotes = array(); |
|
| 121 | + $this->footnotes_ordered = array(); |
|
| 122 | + $this->footnotes_ref_count = array(); |
|
| 123 | + $this->footnotes_numbers = array(); |
|
| 124 | + $this->abbr_desciptions = array(); |
|
| 125 | + $this->abbr_word_re = ''; |
|
| 126 | 126 | |
| 127 | - parent::teardown(); |
|
| 128 | - } |
|
| 127 | + parent::teardown(); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | 130 | |
| 131 | - ### Extra Attribute Parser ### |
|
| 132 | - |
|
| 133 | - # Expression to use to catch attributes (includes the braces) |
|
| 134 | - protected $id_class_attr_catch_re = '\{((?:[ ]*[#.a-z][-_:a-zA-Z0-9=]+){1,})[ ]*\}'; |
|
| 135 | - # Expression to use when parsing in a context when no capture is desired |
|
| 136 | - protected $id_class_attr_nocatch_re = '\{(?:[ ]*[#.a-z][-_:a-zA-Z0-9=]+){1,}[ ]*\}'; |
|
| 137 | - |
|
| 138 | - protected function doExtraAttributes($tag_name, $attr, $defaultIdValue = null) { |
|
| 139 | - # |
|
| 140 | - # Parse attributes caught by the $this->id_class_attr_catch_re expression |
|
| 141 | - # and return the HTML-formatted list of attributes. |
|
| 142 | - # |
|
| 143 | - # Currently supported attributes are .class and #id. |
|
| 144 | - # |
|
| 145 | - # In addition, this method also supports supplying a default Id value, |
|
| 146 | - # which will be used to populate the id attribute in case it was not |
|
| 147 | - # overridden. |
|
| 148 | - if (empty($attr) && !$defaultIdValue) return ""; |
|
| 131 | + ### Extra Attribute Parser ### |
|
| 132 | + |
|
| 133 | + # Expression to use to catch attributes (includes the braces) |
|
| 134 | + protected $id_class_attr_catch_re = '\{((?:[ ]*[#.a-z][-_:a-zA-Z0-9=]+){1,})[ ]*\}'; |
|
| 135 | + # Expression to use when parsing in a context when no capture is desired |
|
| 136 | + protected $id_class_attr_nocatch_re = '\{(?:[ ]*[#.a-z][-_:a-zA-Z0-9=]+){1,}[ ]*\}'; |
|
| 137 | + |
|
| 138 | + protected function doExtraAttributes($tag_name, $attr, $defaultIdValue = null) { |
|
| 139 | + # |
|
| 140 | + # Parse attributes caught by the $this->id_class_attr_catch_re expression |
|
| 141 | + # and return the HTML-formatted list of attributes. |
|
| 142 | + # |
|
| 143 | + # Currently supported attributes are .class and #id. |
|
| 144 | + # |
|
| 145 | + # In addition, this method also supports supplying a default Id value, |
|
| 146 | + # which will be used to populate the id attribute in case it was not |
|
| 147 | + # overridden. |
|
| 148 | + if (empty($attr) && !$defaultIdValue) return ""; |
|
| 149 | 149 | |
| 150 | - # Split on components |
|
| 151 | - preg_match_all('/[#.a-z][-_:a-zA-Z0-9=]+/', $attr, $matches); |
|
| 152 | - $elements = $matches[0]; |
|
| 153 | - |
|
| 154 | - # handle classes and ids (only first id taken into account) |
|
| 155 | - $classes = array(); |
|
| 156 | - $attributes = array(); |
|
| 157 | - $id = false; |
|
| 158 | - foreach ($elements as $element) { |
|
| 159 | - if ($element{0} == '.') { |
|
| 160 | - $classes[] = substr($element, 1); |
|
| 161 | - } else if ($element{0} == '#') { |
|
| 162 | - if ($id === false) $id = substr($element, 1); |
|
| 163 | - } else if (strpos($element, '=') > 0) { |
|
| 164 | - $parts = explode('=', $element, 2); |
|
| 165 | - $attributes[] = $parts[0] . '="' . $parts[1] . '"'; |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - if (!$id) $id = $defaultIdValue; |
|
| 170 | - |
|
| 171 | - # compose attributes as string |
|
| 172 | - $attr_str = ""; |
|
| 173 | - if (!empty($id)) { |
|
| 174 | - $attr_str .= ' id="'.$this->encodeAttribute($id) .'"'; |
|
| 175 | - } |
|
| 176 | - if (!empty($classes)) { |
|
| 177 | - $attr_str .= ' class="'. implode(" ", $classes) . '"'; |
|
| 178 | - } |
|
| 179 | - if (!$this->no_markup && !empty($attributes)) { |
|
| 180 | - $attr_str .= ' '.implode(" ", $attributes); |
|
| 181 | - } |
|
| 182 | - return $attr_str; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - protected function stripLinkDefinitions($text) { |
|
| 187 | - # |
|
| 188 | - # Strips link definitions from text, stores the URLs and titles in |
|
| 189 | - # hash references. |
|
| 190 | - # |
|
| 191 | - $less_than_tab = $this->tab_width - 1; |
|
| 192 | - |
|
| 193 | - # Link defs are in the form: ^[id]: url "optional title" |
|
| 194 | - $text = preg_replace_callback('{ |
|
| 150 | + # Split on components |
|
| 151 | + preg_match_all('/[#.a-z][-_:a-zA-Z0-9=]+/', $attr, $matches); |
|
| 152 | + $elements = $matches[0]; |
|
| 153 | + |
|
| 154 | + # handle classes and ids (only first id taken into account) |
|
| 155 | + $classes = array(); |
|
| 156 | + $attributes = array(); |
|
| 157 | + $id = false; |
|
| 158 | + foreach ($elements as $element) { |
|
| 159 | + if ($element{0} == '.') { |
|
| 160 | + $classes[] = substr($element, 1); |
|
| 161 | + } else if ($element{0} == '#') { |
|
| 162 | + if ($id === false) $id = substr($element, 1); |
|
| 163 | + } else if (strpos($element, '=') > 0) { |
|
| 164 | + $parts = explode('=', $element, 2); |
|
| 165 | + $attributes[] = $parts[0] . '="' . $parts[1] . '"'; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + if (!$id) $id = $defaultIdValue; |
|
| 170 | + |
|
| 171 | + # compose attributes as string |
|
| 172 | + $attr_str = ""; |
|
| 173 | + if (!empty($id)) { |
|
| 174 | + $attr_str .= ' id="'.$this->encodeAttribute($id) .'"'; |
|
| 175 | + } |
|
| 176 | + if (!empty($classes)) { |
|
| 177 | + $attr_str .= ' class="'. implode(" ", $classes) . '"'; |
|
| 178 | + } |
|
| 179 | + if (!$this->no_markup && !empty($attributes)) { |
|
| 180 | + $attr_str .= ' '.implode(" ", $attributes); |
|
| 181 | + } |
|
| 182 | + return $attr_str; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + protected function stripLinkDefinitions($text) { |
|
| 187 | + # |
|
| 188 | + # Strips link definitions from text, stores the URLs and titles in |
|
| 189 | + # hash references. |
|
| 190 | + # |
|
| 191 | + $less_than_tab = $this->tab_width - 1; |
|
| 192 | + |
|
| 193 | + # Link defs are in the form: ^[id]: url "optional title" |
|
| 194 | + $text = preg_replace_callback('{ |
|
| 195 | 195 | ^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?: # id = $1 |
| 196 | 196 | [ ]* |
| 197 | 197 | \n? # maybe *one* newline |
@@ -214,106 +214,106 @@ discard block |
||
| 214 | 214 | (?:[ ]* '.$this->id_class_attr_catch_re.' )? # $5 = extra id & class attr |
| 215 | 215 | (?:\n+|\Z) |
| 216 | 216 | }xm', |
| 217 | - array($this, '_stripLinkDefinitions_callback'), |
|
| 218 | - $text); |
|
| 219 | - return $text; |
|
| 220 | - } |
|
| 221 | - protected function _stripLinkDefinitions_callback($matches) { |
|
| 222 | - $link_id = strtolower($matches[1]); |
|
| 223 | - $url = $matches[2] == '' ? $matches[3] : $matches[2]; |
|
| 224 | - $this->urls[$link_id] = $url; |
|
| 225 | - $this->titles[$link_id] =& $matches[4]; |
|
| 226 | - $this->ref_attr[$link_id] = $this->doExtraAttributes("", $dummy =& $matches[5]); |
|
| 227 | - return ''; # String that will replace the block |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - ### HTML Block Parser ### |
|
| 217 | + array($this, '_stripLinkDefinitions_callback'), |
|
| 218 | + $text); |
|
| 219 | + return $text; |
|
| 220 | + } |
|
| 221 | + protected function _stripLinkDefinitions_callback($matches) { |
|
| 222 | + $link_id = strtolower($matches[1]); |
|
| 223 | + $url = $matches[2] == '' ? $matches[3] : $matches[2]; |
|
| 224 | + $this->urls[$link_id] = $url; |
|
| 225 | + $this->titles[$link_id] =& $matches[4]; |
|
| 226 | + $this->ref_attr[$link_id] = $this->doExtraAttributes("", $dummy =& $matches[5]); |
|
| 227 | + return ''; # String that will replace the block |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + ### HTML Block Parser ### |
|
| 232 | 232 | |
| 233 | - # Tags that are always treated as block tags: |
|
| 234 | - 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'; |
|
| 233 | + # Tags that are always treated as block tags: |
|
| 234 | + 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'; |
|
| 235 | 235 | |
| 236 | - # Tags treated as block tags only if the opening tag is alone on its line: |
|
| 237 | - protected $context_block_tags_re = 'script|noscript|style|ins|del|iframe|object|source|track|param|math|svg|canvas|audio|video'; |
|
| 236 | + # Tags treated as block tags only if the opening tag is alone on its line: |
|
| 237 | + protected $context_block_tags_re = 'script|noscript|style|ins|del|iframe|object|source|track|param|math|svg|canvas|audio|video'; |
|
| 238 | 238 | |
| 239 | - # Tags where markdown="1" default to span mode: |
|
| 240 | - protected $contain_span_tags_re = 'p|h[1-6]|li|dd|dt|td|th|legend|address'; |
|
| 239 | + # Tags where markdown="1" default to span mode: |
|
| 240 | + protected $contain_span_tags_re = 'p|h[1-6]|li|dd|dt|td|th|legend|address'; |
|
| 241 | 241 | |
| 242 | - # Tags which must not have their contents modified, no matter where |
|
| 243 | - # they appear: |
|
| 244 | - protected $clean_tags_re = 'script|style|math|svg'; |
|
| 242 | + # Tags which must not have their contents modified, no matter where |
|
| 243 | + # they appear: |
|
| 244 | + protected $clean_tags_re = 'script|style|math|svg'; |
|
| 245 | 245 | |
| 246 | - # Tags that do not need to be closed. |
|
| 247 | - protected $auto_close_tags_re = 'hr|img|param|source|track'; |
|
| 246 | + # Tags that do not need to be closed. |
|
| 247 | + protected $auto_close_tags_re = 'hr|img|param|source|track'; |
|
| 248 | 248 | |
| 249 | 249 | |
| 250 | - protected function hashHTMLBlocks($text) { |
|
| 251 | - # |
|
| 252 | - # Hashify HTML Blocks and "clean tags". |
|
| 253 | - # |
|
| 254 | - # We only want to do this for block-level HTML tags, such as headers, |
|
| 255 | - # lists, and tables. That's because we still want to wrap <p>s around |
|
| 256 | - # "paragraphs" that are wrapped in non-block-level tags, such as anchors, |
|
| 257 | - # phrase emphasis, and spans. The list of tags we're looking for is |
|
| 258 | - # hard-coded. |
|
| 259 | - # |
|
| 260 | - # This works by calling _HashHTMLBlocks_InMarkdown, which then calls |
|
| 261 | - # _HashHTMLBlocks_InHTML when it encounter block tags. When the markdown="1" |
|
| 262 | - # attribute is found within a tag, _HashHTMLBlocks_InHTML calls back |
|
| 263 | - # _HashHTMLBlocks_InMarkdown to handle the Markdown syntax within the tag. |
|
| 264 | - # These two functions are calling each other. It's recursive! |
|
| 265 | - # |
|
| 266 | - if ($this->no_markup) return $text; |
|
| 267 | - |
|
| 268 | - # |
|
| 269 | - # Call the HTML-in-Markdown hasher. |
|
| 270 | - # |
|
| 271 | - list($text, ) = $this->_hashHTMLBlocks_inMarkdown($text); |
|
| 250 | + protected function hashHTMLBlocks($text) { |
|
| 251 | + # |
|
| 252 | + # Hashify HTML Blocks and "clean tags". |
|
| 253 | + # |
|
| 254 | + # We only want to do this for block-level HTML tags, such as headers, |
|
| 255 | + # lists, and tables. That's because we still want to wrap <p>s around |
|
| 256 | + # "paragraphs" that are wrapped in non-block-level tags, such as anchors, |
|
| 257 | + # phrase emphasis, and spans. The list of tags we're looking for is |
|
| 258 | + # hard-coded. |
|
| 259 | + # |
|
| 260 | + # This works by calling _HashHTMLBlocks_InMarkdown, which then calls |
|
| 261 | + # _HashHTMLBlocks_InHTML when it encounter block tags. When the markdown="1" |
|
| 262 | + # attribute is found within a tag, _HashHTMLBlocks_InHTML calls back |
|
| 263 | + # _HashHTMLBlocks_InMarkdown to handle the Markdown syntax within the tag. |
|
| 264 | + # These two functions are calling each other. It's recursive! |
|
| 265 | + # |
|
| 266 | + if ($this->no_markup) return $text; |
|
| 267 | + |
|
| 268 | + # |
|
| 269 | + # Call the HTML-in-Markdown hasher. |
|
| 270 | + # |
|
| 271 | + list($text, ) = $this->_hashHTMLBlocks_inMarkdown($text); |
|
| 272 | 272 | |
| 273 | - return $text; |
|
| 274 | - } |
|
| 275 | - protected function _hashHTMLBlocks_inMarkdown($text, $indent = 0, |
|
| 276 | - $enclosing_tag_re = '', $span = false) |
|
| 277 | - { |
|
| 278 | - # |
|
| 279 | - # Parse markdown text, calling _HashHTMLBlocks_InHTML for block tags. |
|
| 280 | - # |
|
| 281 | - # * $indent is the number of space to be ignored when checking for code |
|
| 282 | - # blocks. This is important because if we don't take the indent into |
|
| 283 | - # account, something like this (which looks right) won't work as expected: |
|
| 284 | - # |
|
| 285 | - # <div> |
|
| 286 | - # <div markdown="1"> |
|
| 287 | - # Hello World. <-- Is this a Markdown code block or text? |
|
| 288 | - # </div> <-- Is this a Markdown code block or a real tag? |
|
| 289 | - # <div> |
|
| 290 | - # |
|
| 291 | - # If you don't like this, just don't indent the tag on which |
|
| 292 | - # you apply the markdown="1" attribute. |
|
| 293 | - # |
|
| 294 | - # * If $enclosing_tag_re is not empty, stops at the first unmatched closing |
|
| 295 | - # tag with that name. Nested tags supported. |
|
| 296 | - # |
|
| 297 | - # * If $span is true, text inside must treated as span. So any double |
|
| 298 | - # newline will be replaced by a single newline so that it does not create |
|
| 299 | - # paragraphs. |
|
| 300 | - # |
|
| 301 | - # Returns an array of that form: ( processed text , remaining text ) |
|
| 302 | - # |
|
| 303 | - if ($text === '') return array('', ''); |
|
| 304 | - |
|
| 305 | - # Regex to check for the presense of newlines around a block tag. |
|
| 306 | - $newline_before_re = '/(?:^\n?|\n\n)*$/'; |
|
| 307 | - $newline_after_re = |
|
| 308 | - '{ |
|
| 273 | + return $text; |
|
| 274 | + } |
|
| 275 | + protected function _hashHTMLBlocks_inMarkdown($text, $indent = 0, |
|
| 276 | + $enclosing_tag_re = '', $span = false) |
|
| 277 | + { |
|
| 278 | + # |
|
| 279 | + # Parse markdown text, calling _HashHTMLBlocks_InHTML for block tags. |
|
| 280 | + # |
|
| 281 | + # * $indent is the number of space to be ignored when checking for code |
|
| 282 | + # blocks. This is important because if we don't take the indent into |
|
| 283 | + # account, something like this (which looks right) won't work as expected: |
|
| 284 | + # |
|
| 285 | + # <div> |
|
| 286 | + # <div markdown="1"> |
|
| 287 | + # Hello World. <-- Is this a Markdown code block or text? |
|
| 288 | + # </div> <-- Is this a Markdown code block or a real tag? |
|
| 289 | + # <div> |
|
| 290 | + # |
|
| 291 | + # If you don't like this, just don't indent the tag on which |
|
| 292 | + # you apply the markdown="1" attribute. |
|
| 293 | + # |
|
| 294 | + # * If $enclosing_tag_re is not empty, stops at the first unmatched closing |
|
| 295 | + # tag with that name. Nested tags supported. |
|
| 296 | + # |
|
| 297 | + # * If $span is true, text inside must treated as span. So any double |
|
| 298 | + # newline will be replaced by a single newline so that it does not create |
|
| 299 | + # paragraphs. |
|
| 300 | + # |
|
| 301 | + # Returns an array of that form: ( processed text , remaining text ) |
|
| 302 | + # |
|
| 303 | + if ($text === '') return array('', ''); |
|
| 304 | + |
|
| 305 | + # Regex to check for the presense of newlines around a block tag. |
|
| 306 | + $newline_before_re = '/(?:^\n?|\n\n)*$/'; |
|
| 307 | + $newline_after_re = |
|
| 308 | + '{ |
|
| 309 | 309 | ^ # Start of text following the tag. |
| 310 | 310 | (?>[ ]*<!--.*?-->)? # Optional comment. |
| 311 | 311 | [ ]*\n # Must be followed by newline. |
| 312 | 312 | }xs'; |
| 313 | 313 | |
| 314 | - # Regex to match any tag. |
|
| 315 | - $block_tag_re = |
|
| 316 | - '{ |
|
| 314 | + # Regex to match any tag. |
|
| 315 | + $block_tag_re = |
|
| 316 | + '{ |
|
| 317 | 317 | ( # $2: Capture whole tag. |
| 318 | 318 | </? # Any opening or closing tag. |
| 319 | 319 | (?> # Tag name. |
@@ -368,169 +368,169 @@ discard block |
||
| 368 | 368 | }xs'; |
| 369 | 369 | |
| 370 | 370 | |
| 371 | - $depth = 0; # Current depth inside the tag tree. |
|
| 372 | - $parsed = ""; # Parsed text that will be returned. |
|
| 373 | - |
|
| 374 | - # |
|
| 375 | - # Loop through every tag until we find the closing tag of the parent |
|
| 376 | - # or loop until reaching the end of text if no parent tag specified. |
|
| 377 | - # |
|
| 378 | - do { |
|
| 379 | - # |
|
| 380 | - # Split the text using the first $tag_match pattern found. |
|
| 381 | - # Text before pattern will be first in the array, text after |
|
| 382 | - # pattern will be at the end, and between will be any catches made |
|
| 383 | - # by the pattern. |
|
| 384 | - # |
|
| 385 | - $parts = preg_split($block_tag_re, $text, 2, |
|
| 386 | - PREG_SPLIT_DELIM_CAPTURE); |
|
| 371 | + $depth = 0; # Current depth inside the tag tree. |
|
| 372 | + $parsed = ""; # Parsed text that will be returned. |
|
| 373 | + |
|
| 374 | + # |
|
| 375 | + # Loop through every tag until we find the closing tag of the parent |
|
| 376 | + # or loop until reaching the end of text if no parent tag specified. |
|
| 377 | + # |
|
| 378 | + do { |
|
| 379 | + # |
|
| 380 | + # Split the text using the first $tag_match pattern found. |
|
| 381 | + # Text before pattern will be first in the array, text after |
|
| 382 | + # pattern will be at the end, and between will be any catches made |
|
| 383 | + # by the pattern. |
|
| 384 | + # |
|
| 385 | + $parts = preg_split($block_tag_re, $text, 2, |
|
| 386 | + PREG_SPLIT_DELIM_CAPTURE); |
|
| 387 | 387 | |
| 388 | - # If in Markdown span mode, add a empty-string span-level hash |
|
| 389 | - # after each newline to prevent triggering any block element. |
|
| 390 | - if ($span) { |
|
| 391 | - $void = $this->hashPart("", ':'); |
|
| 392 | - $newline = "$void\n"; |
|
| 393 | - $parts[0] = $void . str_replace("\n", $newline, $parts[0]) . $void; |
|
| 394 | - } |
|
| 388 | + # If in Markdown span mode, add a empty-string span-level hash |
|
| 389 | + # after each newline to prevent triggering any block element. |
|
| 390 | + if ($span) { |
|
| 391 | + $void = $this->hashPart("", ':'); |
|
| 392 | + $newline = "$void\n"; |
|
| 393 | + $parts[0] = $void . str_replace("\n", $newline, $parts[0]) . $void; |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | - $parsed .= $parts[0]; # Text before current tag. |
|
| 396 | + $parsed .= $parts[0]; # Text before current tag. |
|
| 397 | 397 | |
| 398 | - # If end of $text has been reached. Stop loop. |
|
| 399 | - if (count($parts) < 3) { |
|
| 400 | - $text = ""; |
|
| 401 | - break; |
|
| 402 | - } |
|
| 398 | + # If end of $text has been reached. Stop loop. |
|
| 399 | + if (count($parts) < 3) { |
|
| 400 | + $text = ""; |
|
| 401 | + break; |
|
| 402 | + } |
|
| 403 | 403 | |
| 404 | - $tag = $parts[1]; # Tag to handle. |
|
| 405 | - $text = $parts[2]; # Remaining text after current tag. |
|
| 406 | - $tag_re = preg_quote($tag); # For use in a regular expression. |
|
| 404 | + $tag = $parts[1]; # Tag to handle. |
|
| 405 | + $text = $parts[2]; # Remaining text after current tag. |
|
| 406 | + $tag_re = preg_quote($tag); # For use in a regular expression. |
|
| 407 | 407 | |
| 408 | - # |
|
| 409 | - # Check for: Fenced code block marker. |
|
| 410 | - # Note: need to recheck the whole tag to disambiguate backtick |
|
| 411 | - # fences from code spans |
|
| 412 | - # |
|
| 413 | - if (preg_match('{^\n?([ ]{0,'.($indent+3).'})(~{3,}|`{3,})[ ]*(?:\.?[-_:a-zA-Z0-9]+|'.$this->id_class_attr_nocatch_re.')?[ ]*\n?$}', $tag, $capture)) { |
|
| 414 | - # Fenced code block marker: find matching end marker. |
|
| 415 | - $fence_indent = strlen($capture[1]); # use captured indent in re |
|
| 416 | - $fence_re = $capture[2]; # use captured fence in re |
|
| 417 | - if (preg_match('{^(?>.*\n)*?[ ]{'.($fence_indent).'}'.$fence_re.'[ ]*(?:\n|$)}', $text, |
|
| 418 | - $matches)) |
|
| 419 | - { |
|
| 420 | - # End marker found: pass text unchanged until marker. |
|
| 421 | - $parsed .= $tag . $matches[0]; |
|
| 422 | - $text = substr($text, strlen($matches[0])); |
|
| 423 | - } |
|
| 424 | - else { |
|
| 425 | - # No end marker: just skip it. |
|
| 426 | - $parsed .= $tag; |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - # |
|
| 430 | - # Check for: Indented code block. |
|
| 431 | - # |
|
| 432 | - else if ($tag{0} == "\n" || $tag{0} == " ") { |
|
| 433 | - # Indented code block: pass it unchanged, will be handled |
|
| 434 | - # later. |
|
| 435 | - $parsed .= $tag; |
|
| 436 | - } |
|
| 437 | - # |
|
| 438 | - # Check for: Code span marker |
|
| 439 | - # Note: need to check this after backtick fenced code blocks |
|
| 440 | - # |
|
| 441 | - else if ($tag{0} == "`") { |
|
| 442 | - # Find corresponding end marker. |
|
| 443 | - $tag_re = preg_quote($tag); |
|
| 444 | - if (preg_match('{^(?>.+?|\n(?!\n))*?(?<!`)'.$tag_re.'(?!`)}', |
|
| 445 | - $text, $matches)) |
|
| 446 | - { |
|
| 447 | - # End marker found: pass text unchanged until marker. |
|
| 448 | - $parsed .= $tag . $matches[0]; |
|
| 449 | - $text = substr($text, strlen($matches[0])); |
|
| 450 | - } |
|
| 451 | - else { |
|
| 452 | - # Unmatched marker: just skip it. |
|
| 453 | - $parsed .= $tag; |
|
| 454 | - } |
|
| 455 | - } |
|
| 456 | - # |
|
| 457 | - # Check for: Opening Block level tag or |
|
| 458 | - # Opening Context Block tag (like ins and del) |
|
| 459 | - # used as a block tag (tag is alone on it's line). |
|
| 460 | - # |
|
| 461 | - else if (preg_match('{^<(?:'.$this->block_tags_re.')\b}', $tag) || |
|
| 462 | - ( preg_match('{^<(?:'.$this->context_block_tags_re.')\b}', $tag) && |
|
| 463 | - preg_match($newline_before_re, $parsed) && |
|
| 464 | - preg_match($newline_after_re, $text) ) |
|
| 465 | - ) |
|
| 466 | - { |
|
| 467 | - # Need to parse tag and following text using the HTML parser. |
|
| 468 | - list($block_text, $text) = |
|
| 469 | - $this->_hashHTMLBlocks_inHTML($tag . $text, "hashBlock", true); |
|
| 408 | + # |
|
| 409 | + # Check for: Fenced code block marker. |
|
| 410 | + # Note: need to recheck the whole tag to disambiguate backtick |
|
| 411 | + # fences from code spans |
|
| 412 | + # |
|
| 413 | + if (preg_match('{^\n?([ ]{0,'.($indent+3).'})(~{3,}|`{3,})[ ]*(?:\.?[-_:a-zA-Z0-9]+|'.$this->id_class_attr_nocatch_re.')?[ ]*\n?$}', $tag, $capture)) { |
|
| 414 | + # Fenced code block marker: find matching end marker. |
|
| 415 | + $fence_indent = strlen($capture[1]); # use captured indent in re |
|
| 416 | + $fence_re = $capture[2]; # use captured fence in re |
|
| 417 | + if (preg_match('{^(?>.*\n)*?[ ]{'.($fence_indent).'}'.$fence_re.'[ ]*(?:\n|$)}', $text, |
|
| 418 | + $matches)) |
|
| 419 | + { |
|
| 420 | + # End marker found: pass text unchanged until marker. |
|
| 421 | + $parsed .= $tag . $matches[0]; |
|
| 422 | + $text = substr($text, strlen($matches[0])); |
|
| 423 | + } |
|
| 424 | + else { |
|
| 425 | + # No end marker: just skip it. |
|
| 426 | + $parsed .= $tag; |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + # |
|
| 430 | + # Check for: Indented code block. |
|
| 431 | + # |
|
| 432 | + else if ($tag{0} == "\n" || $tag{0} == " ") { |
|
| 433 | + # Indented code block: pass it unchanged, will be handled |
|
| 434 | + # later. |
|
| 435 | + $parsed .= $tag; |
|
| 436 | + } |
|
| 437 | + # |
|
| 438 | + # Check for: Code span marker |
|
| 439 | + # Note: need to check this after backtick fenced code blocks |
|
| 440 | + # |
|
| 441 | + else if ($tag{0} == "`") { |
|
| 442 | + # Find corresponding end marker. |
|
| 443 | + $tag_re = preg_quote($tag); |
|
| 444 | + if (preg_match('{^(?>.+?|\n(?!\n))*?(?<!`)'.$tag_re.'(?!`)}', |
|
| 445 | + $text, $matches)) |
|
| 446 | + { |
|
| 447 | + # End marker found: pass text unchanged until marker. |
|
| 448 | + $parsed .= $tag . $matches[0]; |
|
| 449 | + $text = substr($text, strlen($matches[0])); |
|
| 450 | + } |
|
| 451 | + else { |
|
| 452 | + # Unmatched marker: just skip it. |
|
| 453 | + $parsed .= $tag; |
|
| 454 | + } |
|
| 455 | + } |
|
| 456 | + # |
|
| 457 | + # Check for: Opening Block level tag or |
|
| 458 | + # Opening Context Block tag (like ins and del) |
|
| 459 | + # used as a block tag (tag is alone on it's line). |
|
| 460 | + # |
|
| 461 | + else if (preg_match('{^<(?:'.$this->block_tags_re.')\b}', $tag) || |
|
| 462 | + ( preg_match('{^<(?:'.$this->context_block_tags_re.')\b}', $tag) && |
|
| 463 | + preg_match($newline_before_re, $parsed) && |
|
| 464 | + preg_match($newline_after_re, $text) ) |
|
| 465 | + ) |
|
| 466 | + { |
|
| 467 | + # Need to parse tag and following text using the HTML parser. |
|
| 468 | + list($block_text, $text) = |
|
| 469 | + $this->_hashHTMLBlocks_inHTML($tag . $text, "hashBlock", true); |
|
| 470 | 470 | |
| 471 | - # Make sure it stays outside of any paragraph by adding newlines. |
|
| 472 | - $parsed .= "\n\n$block_text\n\n"; |
|
| 473 | - } |
|
| 474 | - # |
|
| 475 | - # Check for: Clean tag (like script, math) |
|
| 476 | - # HTML Comments, processing instructions. |
|
| 477 | - # |
|
| 478 | - else if (preg_match('{^<(?:'.$this->clean_tags_re.')\b}', $tag) || |
|
| 479 | - $tag{1} == '!' || $tag{1} == '?') |
|
| 480 | - { |
|
| 481 | - # Need to parse tag and following text using the HTML parser. |
|
| 482 | - # (don't check for markdown attribute) |
|
| 483 | - list($block_text, $text) = |
|
| 484 | - $this->_hashHTMLBlocks_inHTML($tag . $text, "hashClean", false); |
|
| 471 | + # Make sure it stays outside of any paragraph by adding newlines. |
|
| 472 | + $parsed .= "\n\n$block_text\n\n"; |
|
| 473 | + } |
|
| 474 | + # |
|
| 475 | + # Check for: Clean tag (like script, math) |
|
| 476 | + # HTML Comments, processing instructions. |
|
| 477 | + # |
|
| 478 | + else if (preg_match('{^<(?:'.$this->clean_tags_re.')\b}', $tag) || |
|
| 479 | + $tag{1} == '!' || $tag{1} == '?') |
|
| 480 | + { |
|
| 481 | + # Need to parse tag and following text using the HTML parser. |
|
| 482 | + # (don't check for markdown attribute) |
|
| 483 | + list($block_text, $text) = |
|
| 484 | + $this->_hashHTMLBlocks_inHTML($tag . $text, "hashClean", false); |
|
| 485 | 485 | |
| 486 | - $parsed .= $block_text; |
|
| 487 | - } |
|
| 488 | - # |
|
| 489 | - # Check for: Tag with same name as enclosing tag. |
|
| 490 | - # |
|
| 491 | - else if ($enclosing_tag_re !== '' && |
|
| 492 | - # Same name as enclosing tag. |
|
| 493 | - preg_match('{^</?(?:'.$enclosing_tag_re.')\b}', $tag)) |
|
| 494 | - { |
|
| 495 | - # |
|
| 496 | - # Increase/decrease nested tag count. |
|
| 497 | - # |
|
| 498 | - if ($tag{1} == '/') $depth--; |
|
| 499 | - else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
| 500 | - |
|
| 501 | - if ($depth < 0) { |
|
| 502 | - # |
|
| 503 | - # Going out of parent element. Clean up and break so we |
|
| 504 | - # return to the calling function. |
|
| 505 | - # |
|
| 506 | - $text = $tag . $text; |
|
| 507 | - break; |
|
| 508 | - } |
|
| 486 | + $parsed .= $block_text; |
|
| 487 | + } |
|
| 488 | + # |
|
| 489 | + # Check for: Tag with same name as enclosing tag. |
|
| 490 | + # |
|
| 491 | + else if ($enclosing_tag_re !== '' && |
|
| 492 | + # Same name as enclosing tag. |
|
| 493 | + preg_match('{^</?(?:'.$enclosing_tag_re.')\b}', $tag)) |
|
| 494 | + { |
|
| 495 | + # |
|
| 496 | + # Increase/decrease nested tag count. |
|
| 497 | + # |
|
| 498 | + if ($tag{1} == '/') $depth--; |
|
| 499 | + else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
| 500 | + |
|
| 501 | + if ($depth < 0) { |
|
| 502 | + # |
|
| 503 | + # Going out of parent element. Clean up and break so we |
|
| 504 | + # return to the calling function. |
|
| 505 | + # |
|
| 506 | + $text = $tag . $text; |
|
| 507 | + break; |
|
| 508 | + } |
|
| 509 | 509 | |
| 510 | - $parsed .= $tag; |
|
| 511 | - } |
|
| 512 | - else { |
|
| 513 | - $parsed .= $tag; |
|
| 514 | - } |
|
| 515 | - } while ($depth >= 0); |
|
| 510 | + $parsed .= $tag; |
|
| 511 | + } |
|
| 512 | + else { |
|
| 513 | + $parsed .= $tag; |
|
| 514 | + } |
|
| 515 | + } while ($depth >= 0); |
|
| 516 | 516 | |
| 517 | - return array($parsed, $text); |
|
| 518 | - } |
|
| 519 | - protected function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { |
|
| 520 | - # |
|
| 521 | - # Parse HTML, calling _HashHTMLBlocks_InMarkdown for block tags. |
|
| 522 | - # |
|
| 523 | - # * Calls $hash_method to convert any blocks. |
|
| 524 | - # * Stops when the first opening tag closes. |
|
| 525 | - # * $md_attr indicate if the use of the `markdown="1"` attribute is allowed. |
|
| 526 | - # (it is not inside clean tags) |
|
| 527 | - # |
|
| 528 | - # Returns an array of that form: ( processed text , remaining text ) |
|
| 529 | - # |
|
| 530 | - if ($text === '') return array('', ''); |
|
| 517 | + return array($parsed, $text); |
|
| 518 | + } |
|
| 519 | + protected function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { |
|
| 520 | + # |
|
| 521 | + # Parse HTML, calling _HashHTMLBlocks_InMarkdown for block tags. |
|
| 522 | + # |
|
| 523 | + # * Calls $hash_method to convert any blocks. |
|
| 524 | + # * Stops when the first opening tag closes. |
|
| 525 | + # * $md_attr indicate if the use of the `markdown="1"` attribute is allowed. |
|
| 526 | + # (it is not inside clean tags) |
|
| 527 | + # |
|
| 528 | + # Returns an array of that form: ( processed text , remaining text ) |
|
| 529 | + # |
|
| 530 | + if ($text === '') return array('', ''); |
|
| 531 | 531 | |
| 532 | - # Regex to match `markdown` attribute inside of a tag. |
|
| 533 | - $markdown_attr_re = ' |
|
| 532 | + # Regex to match `markdown` attribute inside of a tag. |
|
| 533 | + $markdown_attr_re = ' |
|
| 534 | 534 | { |
| 535 | 535 | \s* # Eat whitespace before the `markdown` attribute |
| 536 | 536 | markdown |
@@ -545,8 +545,8 @@ discard block |
||
| 545 | 545 | () # $4: make $3 always defined (avoid warnings) |
| 546 | 546 | }xs'; |
| 547 | 547 | |
| 548 | - # Regex to match any tag. |
|
| 549 | - $tag_re = '{ |
|
| 548 | + # Regex to match any tag. |
|
| 549 | + $tag_re = '{ |
|
| 550 | 550 | ( # $2: Capture whole tag. |
| 551 | 551 | </? # Any opening or closing tag. |
| 552 | 552 | [\w:$]+ # Tag name. |
@@ -568,150 +568,150 @@ discard block |
||
| 568 | 568 | ) |
| 569 | 569 | }xs'; |
| 570 | 570 | |
| 571 | - $original_text = $text; # Save original text in case of faliure. |
|
| 571 | + $original_text = $text; # Save original text in case of faliure. |
|
| 572 | 572 | |
| 573 | - $depth = 0; # Current depth inside the tag tree. |
|
| 574 | - $block_text = ""; # Temporary text holder for current text. |
|
| 575 | - $parsed = ""; # Parsed text that will be returned. |
|
| 576 | - |
|
| 577 | - # |
|
| 578 | - # Get the name of the starting tag. |
|
| 579 | - # (This pattern makes $base_tag_name_re safe without quoting.) |
|
| 580 | - # |
|
| 581 | - if (preg_match('/^<([\w:$]*)\b/', $text, $matches)) |
|
| 582 | - $base_tag_name_re = $matches[1]; |
|
| 583 | - |
|
| 584 | - # |
|
| 585 | - # Loop through every tag until we find the corresponding closing tag. |
|
| 586 | - # |
|
| 587 | - do { |
|
| 588 | - # |
|
| 589 | - # Split the text using the first $tag_match pattern found. |
|
| 590 | - # Text before pattern will be first in the array, text after |
|
| 591 | - # pattern will be at the end, and between will be any catches made |
|
| 592 | - # by the pattern. |
|
| 593 | - # |
|
| 594 | - $parts = preg_split($tag_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 573 | + $depth = 0; # Current depth inside the tag tree. |
|
| 574 | + $block_text = ""; # Temporary text holder for current text. |
|
| 575 | + $parsed = ""; # Parsed text that will be returned. |
|
| 576 | + |
|
| 577 | + # |
|
| 578 | + # Get the name of the starting tag. |
|
| 579 | + # (This pattern makes $base_tag_name_re safe without quoting.) |
|
| 580 | + # |
|
| 581 | + if (preg_match('/^<([\w:$]*)\b/', $text, $matches)) |
|
| 582 | + $base_tag_name_re = $matches[1]; |
|
| 583 | + |
|
| 584 | + # |
|
| 585 | + # Loop through every tag until we find the corresponding closing tag. |
|
| 586 | + # |
|
| 587 | + do { |
|
| 588 | + # |
|
| 589 | + # Split the text using the first $tag_match pattern found. |
|
| 590 | + # Text before pattern will be first in the array, text after |
|
| 591 | + # pattern will be at the end, and between will be any catches made |
|
| 592 | + # by the pattern. |
|
| 593 | + # |
|
| 594 | + $parts = preg_split($tag_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 595 | 595 | |
| 596 | - if (count($parts) < 3) { |
|
| 597 | - # |
|
| 598 | - # End of $text reached with unbalenced tag(s). |
|
| 599 | - # In that case, we return original text unchanged and pass the |
|
| 600 | - # first character as filtered to prevent an infinite loop in the |
|
| 601 | - # parent function. |
|
| 602 | - # |
|
| 603 | - return array($original_text{0}, substr($original_text, 1)); |
|
| 604 | - } |
|
| 596 | + if (count($parts) < 3) { |
|
| 597 | + # |
|
| 598 | + # End of $text reached with unbalenced tag(s). |
|
| 599 | + # In that case, we return original text unchanged and pass the |
|
| 600 | + # first character as filtered to prevent an infinite loop in the |
|
| 601 | + # parent function. |
|
| 602 | + # |
|
| 603 | + return array($original_text{0}, substr($original_text, 1)); |
|
| 604 | + } |
|
| 605 | 605 | |
| 606 | - $block_text .= $parts[0]; # Text before current tag. |
|
| 607 | - $tag = $parts[1]; # Tag to handle. |
|
| 608 | - $text = $parts[2]; # Remaining text after current tag. |
|
| 606 | + $block_text .= $parts[0]; # Text before current tag. |
|
| 607 | + $tag = $parts[1]; # Tag to handle. |
|
| 608 | + $text = $parts[2]; # Remaining text after current tag. |
|
| 609 | 609 | |
| 610 | - # |
|
| 611 | - # Check for: Auto-close tag (like <hr/>) |
|
| 612 | - # Comments and Processing Instructions. |
|
| 613 | - # |
|
| 614 | - if (preg_match('{^</?(?:'.$this->auto_close_tags_re.')\b}', $tag) || |
|
| 615 | - $tag{1} == '!' || $tag{1} == '?') |
|
| 616 | - { |
|
| 617 | - # Just add the tag to the block as if it was text. |
|
| 618 | - $block_text .= $tag; |
|
| 619 | - } |
|
| 620 | - else { |
|
| 621 | - # |
|
| 622 | - # Increase/decrease nested tag count. Only do so if |
|
| 623 | - # the tag's name match base tag's. |
|
| 624 | - # |
|
| 625 | - if (preg_match('{^</?'.$base_tag_name_re.'\b}', $tag)) { |
|
| 626 | - if ($tag{1} == '/') $depth--; |
|
| 627 | - else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
| 628 | - } |
|
| 610 | + # |
|
| 611 | + # Check for: Auto-close tag (like <hr/>) |
|
| 612 | + # Comments and Processing Instructions. |
|
| 613 | + # |
|
| 614 | + if (preg_match('{^</?(?:'.$this->auto_close_tags_re.')\b}', $tag) || |
|
| 615 | + $tag{1} == '!' || $tag{1} == '?') |
|
| 616 | + { |
|
| 617 | + # Just add the tag to the block as if it was text. |
|
| 618 | + $block_text .= $tag; |
|
| 619 | + } |
|
| 620 | + else { |
|
| 621 | + # |
|
| 622 | + # Increase/decrease nested tag count. Only do so if |
|
| 623 | + # the tag's name match base tag's. |
|
| 624 | + # |
|
| 625 | + if (preg_match('{^</?'.$base_tag_name_re.'\b}', $tag)) { |
|
| 626 | + if ($tag{1} == '/') $depth--; |
|
| 627 | + else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
| 628 | + } |
|
| 629 | 629 | |
| 630 | - # |
|
| 631 | - # Check for `markdown="1"` attribute and handle it. |
|
| 632 | - # |
|
| 633 | - if ($md_attr && |
|
| 634 | - preg_match($markdown_attr_re, $tag, $attr_m) && |
|
| 635 | - preg_match('/^1|block|span$/', $attr_m[2] . $attr_m[3])) |
|
| 636 | - { |
|
| 637 | - # Remove `markdown` attribute from opening tag. |
|
| 638 | - $tag = preg_replace($markdown_attr_re, '', $tag); |
|
| 630 | + # |
|
| 631 | + # Check for `markdown="1"` attribute and handle it. |
|
| 632 | + # |
|
| 633 | + if ($md_attr && |
|
| 634 | + preg_match($markdown_attr_re, $tag, $attr_m) && |
|
| 635 | + preg_match('/^1|block|span$/', $attr_m[2] . $attr_m[3])) |
|
| 636 | + { |
|
| 637 | + # Remove `markdown` attribute from opening tag. |
|
| 638 | + $tag = preg_replace($markdown_attr_re, '', $tag); |
|
| 639 | 639 | |
| 640 | - # Check if text inside this tag must be parsed in span mode. |
|
| 641 | - $this->mode = $attr_m[2] . $attr_m[3]; |
|
| 642 | - $span_mode = $this->mode == 'span' || $this->mode != 'block' && |
|
| 643 | - preg_match('{^<(?:'.$this->contain_span_tags_re.')\b}', $tag); |
|
| 640 | + # Check if text inside this tag must be parsed in span mode. |
|
| 641 | + $this->mode = $attr_m[2] . $attr_m[3]; |
|
| 642 | + $span_mode = $this->mode == 'span' || $this->mode != 'block' && |
|
| 643 | + preg_match('{^<(?:'.$this->contain_span_tags_re.')\b}', $tag); |
|
| 644 | 644 | |
| 645 | - # Calculate indent before tag. |
|
| 646 | - if (preg_match('/(?:^|\n)( *?)(?! ).*?$/', $block_text, $matches)) { |
|
| 647 | - $strlen = $this->utf8_strlen; |
|
| 648 | - $indent = $strlen($matches[1], 'UTF-8'); |
|
| 649 | - } else { |
|
| 650 | - $indent = 0; |
|
| 651 | - } |
|
| 645 | + # Calculate indent before tag. |
|
| 646 | + if (preg_match('/(?:^|\n)( *?)(?! ).*?$/', $block_text, $matches)) { |
|
| 647 | + $strlen = $this->utf8_strlen; |
|
| 648 | + $indent = $strlen($matches[1], 'UTF-8'); |
|
| 649 | + } else { |
|
| 650 | + $indent = 0; |
|
| 651 | + } |
|
| 652 | 652 | |
| 653 | - # End preceding block with this tag. |
|
| 654 | - $block_text .= $tag; |
|
| 655 | - $parsed .= $this->$hash_method($block_text); |
|
| 653 | + # End preceding block with this tag. |
|
| 654 | + $block_text .= $tag; |
|
| 655 | + $parsed .= $this->$hash_method($block_text); |
|
| 656 | 656 | |
| 657 | - # Get enclosing tag name for the ParseMarkdown function. |
|
| 658 | - # (This pattern makes $tag_name_re safe without quoting.) |
|
| 659 | - preg_match('/^<([\w:$]*)\b/', $tag, $matches); |
|
| 660 | - $tag_name_re = $matches[1]; |
|
| 657 | + # Get enclosing tag name for the ParseMarkdown function. |
|
| 658 | + # (This pattern makes $tag_name_re safe without quoting.) |
|
| 659 | + preg_match('/^<([\w:$]*)\b/', $tag, $matches); |
|
| 660 | + $tag_name_re = $matches[1]; |
|
| 661 | 661 | |
| 662 | - # Parse the content using the HTML-in-Markdown parser. |
|
| 663 | - list ($block_text, $text) |
|
| 664 | - = $this->_hashHTMLBlocks_inMarkdown($text, $indent, |
|
| 665 | - $tag_name_re, $span_mode); |
|
| 662 | + # Parse the content using the HTML-in-Markdown parser. |
|
| 663 | + list ($block_text, $text) |
|
| 664 | + = $this->_hashHTMLBlocks_inMarkdown($text, $indent, |
|
| 665 | + $tag_name_re, $span_mode); |
|
| 666 | 666 | |
| 667 | - # Outdent markdown text. |
|
| 668 | - if ($indent > 0) { |
|
| 669 | - $block_text = preg_replace("/^[ ]{1,$indent}/m", "", |
|
| 670 | - $block_text); |
|
| 671 | - } |
|
| 667 | + # Outdent markdown text. |
|
| 668 | + if ($indent > 0) { |
|
| 669 | + $block_text = preg_replace("/^[ ]{1,$indent}/m", "", |
|
| 670 | + $block_text); |
|
| 671 | + } |
|
| 672 | 672 | |
| 673 | - # Append tag content to parsed text. |
|
| 674 | - if (!$span_mode) $parsed .= "\n\n$block_text\n\n"; |
|
| 675 | - else $parsed .= "$block_text"; |
|
| 673 | + # Append tag content to parsed text. |
|
| 674 | + if (!$span_mode) $parsed .= "\n\n$block_text\n\n"; |
|
| 675 | + else $parsed .= "$block_text"; |
|
| 676 | 676 | |
| 677 | - # Start over with a new block. |
|
| 678 | - $block_text = ""; |
|
| 679 | - } |
|
| 680 | - else $block_text .= $tag; |
|
| 681 | - } |
|
| 677 | + # Start over with a new block. |
|
| 678 | + $block_text = ""; |
|
| 679 | + } |
|
| 680 | + else $block_text .= $tag; |
|
| 681 | + } |
|
| 682 | 682 | |
| 683 | - } while ($depth > 0); |
|
| 683 | + } while ($depth > 0); |
|
| 684 | 684 | |
| 685 | - # |
|
| 686 | - # Hash last block text that wasn't processed inside the loop. |
|
| 687 | - # |
|
| 688 | - $parsed .= $this->$hash_method($block_text); |
|
| 685 | + # |
|
| 686 | + # Hash last block text that wasn't processed inside the loop. |
|
| 687 | + # |
|
| 688 | + $parsed .= $this->$hash_method($block_text); |
|
| 689 | 689 | |
| 690 | - return array($parsed, $text); |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - protected function hashClean($text) { |
|
| 695 | - # |
|
| 696 | - # Called whenever a tag must be hashed when a function inserts a "clean" tag |
|
| 697 | - # in $text, it passes through this function and is automaticaly escaped, |
|
| 698 | - # blocking invalid nested overlap. |
|
| 699 | - # |
|
| 700 | - return $this->hashPart($text, 'C'); |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - |
|
| 704 | - protected function doAnchors($text) { |
|
| 705 | - # |
|
| 706 | - # Turn Markdown link shortcuts into XHTML <a> tags. |
|
| 707 | - # |
|
| 708 | - if ($this->in_anchor) return $text; |
|
| 709 | - $this->in_anchor = true; |
|
| 690 | + return array($parsed, $text); |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + protected function hashClean($text) { |
|
| 695 | + # |
|
| 696 | + # Called whenever a tag must be hashed when a function inserts a "clean" tag |
|
| 697 | + # in $text, it passes through this function and is automaticaly escaped, |
|
| 698 | + # blocking invalid nested overlap. |
|
| 699 | + # |
|
| 700 | + return $this->hashPart($text, 'C'); |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + |
|
| 704 | + protected function doAnchors($text) { |
|
| 705 | + # |
|
| 706 | + # Turn Markdown link shortcuts into XHTML <a> tags. |
|
| 707 | + # |
|
| 708 | + if ($this->in_anchor) return $text; |
|
| 709 | + $this->in_anchor = true; |
|
| 710 | 710 | |
| 711 | - # |
|
| 712 | - # First, handle reference-style links: [link text] [id] |
|
| 713 | - # |
|
| 714 | - $text = preg_replace_callback('{ |
|
| 711 | + # |
|
| 712 | + # First, handle reference-style links: [link text] [id] |
|
| 713 | + # |
|
| 714 | + $text = preg_replace_callback('{ |
|
| 715 | 715 | ( # wrap whole match in $1 |
| 716 | 716 | \[ |
| 717 | 717 | ('.$this->nested_brackets_re.') # link text = $2 |
@@ -725,12 +725,12 @@ discard block |
||
| 725 | 725 | \] |
| 726 | 726 | ) |
| 727 | 727 | }xs', |
| 728 | - array($this, '_doAnchors_reference_callback'), $text); |
|
| 728 | + array($this, '_doAnchors_reference_callback'), $text); |
|
| 729 | 729 | |
| 730 | - # |
|
| 731 | - # Next, inline-style links: [link text](url "optional title") |
|
| 732 | - # |
|
| 733 | - $text = preg_replace_callback('{ |
|
| 730 | + # |
|
| 731 | + # Next, inline-style links: [link text](url "optional title") |
|
| 732 | + # |
|
| 733 | + $text = preg_replace_callback('{ |
|
| 734 | 734 | ( # wrap whole match in $1 |
| 735 | 735 | \[ |
| 736 | 736 | ('.$this->nested_brackets_re.') # link text = $2 |
@@ -753,98 +753,98 @@ discard block |
||
| 753 | 753 | (?:[ ]? '.$this->id_class_attr_catch_re.' )? # $8 = id/class attributes |
| 754 | 754 | ) |
| 755 | 755 | }xs', |
| 756 | - array($this, '_doAnchors_inline_callback'), $text); |
|
| 757 | - |
|
| 758 | - # |
|
| 759 | - # Last, handle reference-style shortcuts: [link text] |
|
| 760 | - # These must come last in case you've also got [link text][1] |
|
| 761 | - # or [link text](/foo) |
|
| 762 | - # |
|
| 763 | - $text = preg_replace_callback('{ |
|
| 756 | + array($this, '_doAnchors_inline_callback'), $text); |
|
| 757 | + |
|
| 758 | + # |
|
| 759 | + # Last, handle reference-style shortcuts: [link text] |
|
| 760 | + # These must come last in case you've also got [link text][1] |
|
| 761 | + # or [link text](/foo) |
|
| 762 | + # |
|
| 763 | + $text = preg_replace_callback('{ |
|
| 764 | 764 | ( # wrap whole match in $1 |
| 765 | 765 | \[ |
| 766 | 766 | ([^\[\]]+) # link text = $2; can\'t contain [ or ] |
| 767 | 767 | \] |
| 768 | 768 | ) |
| 769 | 769 | }xs', |
| 770 | - array($this, '_doAnchors_reference_callback'), $text); |
|
| 771 | - |
|
| 772 | - $this->in_anchor = false; |
|
| 773 | - return $text; |
|
| 774 | - } |
|
| 775 | - protected function _doAnchors_reference_callback($matches) { |
|
| 776 | - $whole_match = $matches[1]; |
|
| 777 | - $link_text = $matches[2]; |
|
| 778 | - $link_id =& $matches[3]; |
|
| 779 | - |
|
| 780 | - if ($link_id == "") { |
|
| 781 | - # for shortcut links like [this][] or [this]. |
|
| 782 | - $link_id = $link_text; |
|
| 783 | - } |
|
| 770 | + array($this, '_doAnchors_reference_callback'), $text); |
|
| 771 | + |
|
| 772 | + $this->in_anchor = false; |
|
| 773 | + return $text; |
|
| 774 | + } |
|
| 775 | + protected function _doAnchors_reference_callback($matches) { |
|
| 776 | + $whole_match = $matches[1]; |
|
| 777 | + $link_text = $matches[2]; |
|
| 778 | + $link_id =& $matches[3]; |
|
| 779 | + |
|
| 780 | + if ($link_id == "") { |
|
| 781 | + # for shortcut links like [this][] or [this]. |
|
| 782 | + $link_id = $link_text; |
|
| 783 | + } |
|
| 784 | 784 | |
| 785 | - # lower-case and turn embedded newlines into spaces |
|
| 786 | - $link_id = strtolower($link_id); |
|
| 787 | - $link_id = preg_replace('{[ ]?\n}', ' ', $link_id); |
|
| 785 | + # lower-case and turn embedded newlines into spaces |
|
| 786 | + $link_id = strtolower($link_id); |
|
| 787 | + $link_id = preg_replace('{[ ]?\n}', ' ', $link_id); |
|
| 788 | 788 | |
| 789 | - if (isset($this->urls[$link_id])) { |
|
| 790 | - $url = $this->urls[$link_id]; |
|
| 791 | - $url = $this->encodeURLAttribute($url); |
|
| 789 | + if (isset($this->urls[$link_id])) { |
|
| 790 | + $url = $this->urls[$link_id]; |
|
| 791 | + $url = $this->encodeURLAttribute($url); |
|
| 792 | 792 | |
| 793 | - $result = "<a href=\"$url\""; |
|
| 794 | - if ( isset( $this->titles[$link_id] ) ) { |
|
| 795 | - $title = $this->titles[$link_id]; |
|
| 796 | - $title = $this->encodeAttribute($title); |
|
| 797 | - $result .= " title=\"$title\""; |
|
| 798 | - } |
|
| 799 | - if (isset($this->ref_attr[$link_id])) |
|
| 800 | - $result .= $this->ref_attr[$link_id]; |
|
| 793 | + $result = "<a href=\"$url\""; |
|
| 794 | + if ( isset( $this->titles[$link_id] ) ) { |
|
| 795 | + $title = $this->titles[$link_id]; |
|
| 796 | + $title = $this->encodeAttribute($title); |
|
| 797 | + $result .= " title=\"$title\""; |
|
| 798 | + } |
|
| 799 | + if (isset($this->ref_attr[$link_id])) |
|
| 800 | + $result .= $this->ref_attr[$link_id]; |
|
| 801 | 801 | |
| 802 | - $link_text = $this->runSpanGamut($link_text); |
|
| 803 | - $result .= ">$link_text</a>"; |
|
| 804 | - $result = $this->hashPart($result); |
|
| 805 | - } |
|
| 806 | - else { |
|
| 807 | - $result = $whole_match; |
|
| 808 | - } |
|
| 809 | - return $result; |
|
| 810 | - } |
|
| 811 | - protected function _doAnchors_inline_callback($matches) { |
|
| 812 | - $whole_match = $matches[1]; |
|
| 813 | - $link_text = $this->runSpanGamut($matches[2]); |
|
| 814 | - $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 815 | - $title =& $matches[7]; |
|
| 816 | - $attr = $this->doExtraAttributes("a", $dummy =& $matches[8]); |
|
| 817 | - |
|
| 818 | - // if the URL was of the form <s p a c e s> it got caught by the HTML |
|
| 819 | - // tag parser and hashed. Need to reverse the process before using the URL. |
|
| 820 | - $unhashed = $this->unhash($url); |
|
| 821 | - if ($unhashed != $url) |
|
| 822 | - $url = preg_replace('/^<(.*)>$/', '\1', $unhashed); |
|
| 823 | - |
|
| 824 | - $url = $this->encodeURLAttribute($url); |
|
| 825 | - |
|
| 826 | - $result = "<a href=\"$url\""; |
|
| 827 | - if (isset($title)) { |
|
| 828 | - $title = $this->encodeAttribute($title); |
|
| 829 | - $result .= " title=\"$title\""; |
|
| 830 | - } |
|
| 831 | - $result .= $attr; |
|
| 802 | + $link_text = $this->runSpanGamut($link_text); |
|
| 803 | + $result .= ">$link_text</a>"; |
|
| 804 | + $result = $this->hashPart($result); |
|
| 805 | + } |
|
| 806 | + else { |
|
| 807 | + $result = $whole_match; |
|
| 808 | + } |
|
| 809 | + return $result; |
|
| 810 | + } |
|
| 811 | + protected function _doAnchors_inline_callback($matches) { |
|
| 812 | + $whole_match = $matches[1]; |
|
| 813 | + $link_text = $this->runSpanGamut($matches[2]); |
|
| 814 | + $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 815 | + $title =& $matches[7]; |
|
| 816 | + $attr = $this->doExtraAttributes("a", $dummy =& $matches[8]); |
|
| 817 | + |
|
| 818 | + // if the URL was of the form <s p a c e s> it got caught by the HTML |
|
| 819 | + // tag parser and hashed. Need to reverse the process before using the URL. |
|
| 820 | + $unhashed = $this->unhash($url); |
|
| 821 | + if ($unhashed != $url) |
|
| 822 | + $url = preg_replace('/^<(.*)>$/', '\1', $unhashed); |
|
| 823 | + |
|
| 824 | + $url = $this->encodeURLAttribute($url); |
|
| 825 | + |
|
| 826 | + $result = "<a href=\"$url\""; |
|
| 827 | + if (isset($title)) { |
|
| 828 | + $title = $this->encodeAttribute($title); |
|
| 829 | + $result .= " title=\"$title\""; |
|
| 830 | + } |
|
| 831 | + $result .= $attr; |
|
| 832 | 832 | |
| 833 | - $link_text = $this->runSpanGamut($link_text); |
|
| 834 | - $result .= ">$link_text</a>"; |
|
| 833 | + $link_text = $this->runSpanGamut($link_text); |
|
| 834 | + $result .= ">$link_text</a>"; |
|
| 835 | 835 | |
| 836 | - return $this->hashPart($result); |
|
| 837 | - } |
|
| 836 | + return $this->hashPart($result); |
|
| 837 | + } |
|
| 838 | 838 | |
| 839 | 839 | |
| 840 | - protected function doImages($text) { |
|
| 841 | - # |
|
| 842 | - # Turn Markdown image shortcuts into <img> tags. |
|
| 843 | - # |
|
| 844 | - # |
|
| 845 | - # First, handle reference-style labeled images: ![alt text][id] |
|
| 846 | - # |
|
| 847 | - $text = preg_replace_callback('{ |
|
| 840 | + protected function doImages($text) { |
|
| 841 | + # |
|
| 842 | + # Turn Markdown image shortcuts into <img> tags. |
|
| 843 | + # |
|
| 844 | + # |
|
| 845 | + # First, handle reference-style labeled images: ![alt text][id] |
|
| 846 | + # |
|
| 847 | + $text = preg_replace_callback('{ |
|
| 848 | 848 | ( # wrap whole match in $1 |
| 849 | 849 | !\[ |
| 850 | 850 | ('.$this->nested_brackets_re.') # alt text = $2 |
@@ -859,13 +859,13 @@ discard block |
||
| 859 | 859 | |
| 860 | 860 | ) |
| 861 | 861 | }xs', |
| 862 | - array($this, '_doImages_reference_callback'), $text); |
|
| 862 | + array($this, '_doImages_reference_callback'), $text); |
|
| 863 | 863 | |
| 864 | - # |
|
| 865 | - # Next, handle inline images:  |
|
| 866 | - # Don't forget: encode * and _ |
|
| 867 | - # |
|
| 868 | - $text = preg_replace_callback('{ |
|
| 864 | + # |
|
| 865 | + # Next, handle inline images:  |
|
| 866 | + # Don't forget: encode * and _ |
|
| 867 | + # |
|
| 868 | + $text = preg_replace_callback('{ |
|
| 869 | 869 | ( # wrap whole match in $1 |
| 870 | 870 | !\[ |
| 871 | 871 | ('.$this->nested_brackets_re.') # alt text = $2 |
@@ -889,88 +889,88 @@ discard block |
||
| 889 | 889 | (?:[ ]? '.$this->id_class_attr_catch_re.' )? # $8 = id/class attributes |
| 890 | 890 | ) |
| 891 | 891 | }xs', |
| 892 | - array($this, '_doImages_inline_callback'), $text); |
|
| 893 | - |
|
| 894 | - return $text; |
|
| 895 | - } |
|
| 896 | - protected function _doImages_reference_callback($matches) { |
|
| 897 | - $whole_match = $matches[1]; |
|
| 898 | - $alt_text = $matches[2]; |
|
| 899 | - $link_id = strtolower($matches[3]); |
|
| 900 | - |
|
| 901 | - if ($link_id == "") { |
|
| 902 | - $link_id = strtolower($alt_text); # for shortcut links like ![this][]. |
|
| 903 | - } |
|
| 904 | - |
|
| 905 | - $alt_text = $this->encodeAttribute($alt_text); |
|
| 906 | - if (isset($this->urls[$link_id])) { |
|
| 907 | - $url = $this->encodeURLAttribute($this->urls[$link_id]); |
|
| 908 | - $result = "<img src=\"$url\" alt=\"$alt_text\""; |
|
| 909 | - if (isset($this->titles[$link_id])) { |
|
| 910 | - $title = $this->titles[$link_id]; |
|
| 911 | - $title = $this->encodeAttribute($title); |
|
| 912 | - $result .= " title=\"$title\""; |
|
| 913 | - } |
|
| 914 | - if (isset($this->ref_attr[$link_id])) |
|
| 915 | - $result .= $this->ref_attr[$link_id]; |
|
| 916 | - $result .= $this->empty_element_suffix; |
|
| 917 | - $result = $this->hashPart($result); |
|
| 918 | - } |
|
| 919 | - else { |
|
| 920 | - # If there's no such link ID, leave intact: |
|
| 921 | - $result = $whole_match; |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - return $result; |
|
| 925 | - } |
|
| 926 | - protected function _doImages_inline_callback($matches) { |
|
| 927 | - $whole_match = $matches[1]; |
|
| 928 | - $alt_text = $matches[2]; |
|
| 929 | - $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 930 | - $title =& $matches[7]; |
|
| 931 | - $attr = $this->doExtraAttributes("img", $dummy =& $matches[8]); |
|
| 932 | - |
|
| 933 | - $alt_text = $this->encodeAttribute($alt_text); |
|
| 934 | - $url = $this->encodeURLAttribute($url); |
|
| 935 | - $result = "<img src=\"$url\" alt=\"$alt_text\""; |
|
| 936 | - if (isset($title)) { |
|
| 937 | - $title = $this->encodeAttribute($title); |
|
| 938 | - $result .= " title=\"$title\""; # $title already quoted |
|
| 939 | - } |
|
| 940 | - $result .= $attr; |
|
| 941 | - $result .= $this->empty_element_suffix; |
|
| 942 | - |
|
| 943 | - return $this->hashPart($result); |
|
| 944 | - } |
|
| 945 | - |
|
| 946 | - |
|
| 947 | - protected function doHeaders($text) { |
|
| 948 | - # |
|
| 949 | - # Redefined to add id and class attribute support. |
|
| 950 | - # |
|
| 951 | - # Setext-style headers: |
|
| 952 | - # Header 1 {#header1} |
|
| 953 | - # ======== |
|
| 954 | - # |
|
| 955 | - # Header 2 {#header2 .class1 .class2} |
|
| 956 | - # -------- |
|
| 957 | - # |
|
| 958 | - $text = preg_replace_callback( |
|
| 959 | - '{ |
|
| 892 | + array($this, '_doImages_inline_callback'), $text); |
|
| 893 | + |
|
| 894 | + return $text; |
|
| 895 | + } |
|
| 896 | + protected function _doImages_reference_callback($matches) { |
|
| 897 | + $whole_match = $matches[1]; |
|
| 898 | + $alt_text = $matches[2]; |
|
| 899 | + $link_id = strtolower($matches[3]); |
|
| 900 | + |
|
| 901 | + if ($link_id == "") { |
|
| 902 | + $link_id = strtolower($alt_text); # for shortcut links like ![this][]. |
|
| 903 | + } |
|
| 904 | + |
|
| 905 | + $alt_text = $this->encodeAttribute($alt_text); |
|
| 906 | + if (isset($this->urls[$link_id])) { |
|
| 907 | + $url = $this->encodeURLAttribute($this->urls[$link_id]); |
|
| 908 | + $result = "<img src=\"$url\" alt=\"$alt_text\""; |
|
| 909 | + if (isset($this->titles[$link_id])) { |
|
| 910 | + $title = $this->titles[$link_id]; |
|
| 911 | + $title = $this->encodeAttribute($title); |
|
| 912 | + $result .= " title=\"$title\""; |
|
| 913 | + } |
|
| 914 | + if (isset($this->ref_attr[$link_id])) |
|
| 915 | + $result .= $this->ref_attr[$link_id]; |
|
| 916 | + $result .= $this->empty_element_suffix; |
|
| 917 | + $result = $this->hashPart($result); |
|
| 918 | + } |
|
| 919 | + else { |
|
| 920 | + # If there's no such link ID, leave intact: |
|
| 921 | + $result = $whole_match; |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + return $result; |
|
| 925 | + } |
|
| 926 | + protected function _doImages_inline_callback($matches) { |
|
| 927 | + $whole_match = $matches[1]; |
|
| 928 | + $alt_text = $matches[2]; |
|
| 929 | + $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 930 | + $title =& $matches[7]; |
|
| 931 | + $attr = $this->doExtraAttributes("img", $dummy =& $matches[8]); |
|
| 932 | + |
|
| 933 | + $alt_text = $this->encodeAttribute($alt_text); |
|
| 934 | + $url = $this->encodeURLAttribute($url); |
|
| 935 | + $result = "<img src=\"$url\" alt=\"$alt_text\""; |
|
| 936 | + if (isset($title)) { |
|
| 937 | + $title = $this->encodeAttribute($title); |
|
| 938 | + $result .= " title=\"$title\""; # $title already quoted |
|
| 939 | + } |
|
| 940 | + $result .= $attr; |
|
| 941 | + $result .= $this->empty_element_suffix; |
|
| 942 | + |
|
| 943 | + return $this->hashPart($result); |
|
| 944 | + } |
|
| 945 | + |
|
| 946 | + |
|
| 947 | + protected function doHeaders($text) { |
|
| 948 | + # |
|
| 949 | + # Redefined to add id and class attribute support. |
|
| 950 | + # |
|
| 951 | + # Setext-style headers: |
|
| 952 | + # Header 1 {#header1} |
|
| 953 | + # ======== |
|
| 954 | + # |
|
| 955 | + # Header 2 {#header2 .class1 .class2} |
|
| 956 | + # -------- |
|
| 957 | + # |
|
| 958 | + $text = preg_replace_callback( |
|
| 959 | + '{ |
|
| 960 | 960 | (^.+?) # $1: Header text |
| 961 | 961 | (?:[ ]+ '.$this->id_class_attr_catch_re.' )? # $3 = id/class attributes |
| 962 | 962 | [ ]*\n(=+|-+)[ ]*\n+ # $3: Header footer |
| 963 | 963 | }mx', |
| 964 | - array($this, '_doHeaders_callback_setext'), $text); |
|
| 965 | - |
|
| 966 | - # atx-style headers: |
|
| 967 | - # # Header 1 {#header1} |
|
| 968 | - # ## Header 2 {#header2} |
|
| 969 | - # ## Header 2 with closing hashes ## {#header3.class1.class2} |
|
| 970 | - # ... |
|
| 971 | - # ###### Header 6 {.class2} |
|
| 972 | - # |
|
| 973 | - $text = preg_replace_callback('{ |
|
| 964 | + array($this, '_doHeaders_callback_setext'), $text); |
|
| 965 | + |
|
| 966 | + # atx-style headers: |
|
| 967 | + # # Header 1 {#header1} |
|
| 968 | + # ## Header 2 {#header2} |
|
| 969 | + # ## Header 2 with closing hashes ## {#header3.class1.class2} |
|
| 970 | + # ... |
|
| 971 | + # ###### Header 6 {.class2} |
|
| 972 | + # |
|
| 973 | + $text = preg_replace_callback('{ |
|
| 974 | 974 | ^(\#{1,6}) # $1 = string of #\'s |
| 975 | 975 | [ ]* |
| 976 | 976 | (.+?) # $2 = Header text |
@@ -980,46 +980,46 @@ discard block |
||
| 980 | 980 | [ ]* |
| 981 | 981 | \n+ |
| 982 | 982 | }xm', |
| 983 | - array($this, '_doHeaders_callback_atx'), $text); |
|
| 984 | - |
|
| 985 | - return $text; |
|
| 986 | - } |
|
| 987 | - protected function _doHeaders_callback_setext($matches) { |
|
| 988 | - if ($matches[3] == '-' && preg_match('{^- }', $matches[1])) |
|
| 989 | - return $matches[0]; |
|
| 990 | - |
|
| 991 | - $level = $matches[3]{0} == '=' ? 1 : 2; |
|
| 992 | - |
|
| 993 | - $defaultId = is_callable($this->header_id_func) ? call_user_func($this->header_id_func, $matches[1]) : null; |
|
| 994 | - |
|
| 995 | - $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[2], $defaultId); |
|
| 996 | - $block = "<h$level$attr>".$this->runSpanGamut($matches[1])."</h$level>"; |
|
| 997 | - return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 998 | - } |
|
| 999 | - protected function _doHeaders_callback_atx($matches) { |
|
| 1000 | - $level = strlen($matches[1]); |
|
| 1001 | - |
|
| 1002 | - $defaultId = is_callable($this->header_id_func) ? call_user_func($this->header_id_func, $matches[2]) : null; |
|
| 1003 | - $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[3], $defaultId); |
|
| 1004 | - $block = "<h$level$attr>".$this->runSpanGamut($matches[2])."</h$level>"; |
|
| 1005 | - return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 1006 | - } |
|
| 1007 | - |
|
| 1008 | - |
|
| 1009 | - protected function doTables($text) { |
|
| 1010 | - # |
|
| 1011 | - # Form HTML tables. |
|
| 1012 | - # |
|
| 1013 | - $less_than_tab = $this->tab_width - 1; |
|
| 1014 | - # |
|
| 1015 | - # Find tables with leading pipe. |
|
| 1016 | - # |
|
| 1017 | - # | Header 1 | Header 2 |
|
| 1018 | - # | -------- | -------- |
|
| 1019 | - # | Cell 1 | Cell 2 |
|
| 1020 | - # | Cell 3 | Cell 4 |
|
| 1021 | - # |
|
| 1022 | - $text = preg_replace_callback(' |
|
| 983 | + array($this, '_doHeaders_callback_atx'), $text); |
|
| 984 | + |
|
| 985 | + return $text; |
|
| 986 | + } |
|
| 987 | + protected function _doHeaders_callback_setext($matches) { |
|
| 988 | + if ($matches[3] == '-' && preg_match('{^- }', $matches[1])) |
|
| 989 | + return $matches[0]; |
|
| 990 | + |
|
| 991 | + $level = $matches[3]{0} == '=' ? 1 : 2; |
|
| 992 | + |
|
| 993 | + $defaultId = is_callable($this->header_id_func) ? call_user_func($this->header_id_func, $matches[1]) : null; |
|
| 994 | + |
|
| 995 | + $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[2], $defaultId); |
|
| 996 | + $block = "<h$level$attr>".$this->runSpanGamut($matches[1])."</h$level>"; |
|
| 997 | + return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 998 | + } |
|
| 999 | + protected function _doHeaders_callback_atx($matches) { |
|
| 1000 | + $level = strlen($matches[1]); |
|
| 1001 | + |
|
| 1002 | + $defaultId = is_callable($this->header_id_func) ? call_user_func($this->header_id_func, $matches[2]) : null; |
|
| 1003 | + $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[3], $defaultId); |
|
| 1004 | + $block = "<h$level$attr>".$this->runSpanGamut($matches[2])."</h$level>"; |
|
| 1005 | + return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 1006 | + } |
|
| 1007 | + |
|
| 1008 | + |
|
| 1009 | + protected function doTables($text) { |
|
| 1010 | + # |
|
| 1011 | + # Form HTML tables. |
|
| 1012 | + # |
|
| 1013 | + $less_than_tab = $this->tab_width - 1; |
|
| 1014 | + # |
|
| 1015 | + # Find tables with leading pipe. |
|
| 1016 | + # |
|
| 1017 | + # | Header 1 | Header 2 |
|
| 1018 | + # | -------- | -------- |
|
| 1019 | + # | Cell 1 | Cell 2 |
|
| 1020 | + # | Cell 3 | Cell 4 |
|
| 1021 | + # |
|
| 1022 | + $text = preg_replace_callback(' |
|
| 1023 | 1023 | { |
| 1024 | 1024 | ^ # Start of a line |
| 1025 | 1025 | [ ]{0,'.$less_than_tab.'} # Allowed whitespace. |
@@ -1037,17 +1037,17 @@ discard block |
||
| 1037 | 1037 | ) |
| 1038 | 1038 | (?=\n|\Z) # Stop at final double newline. |
| 1039 | 1039 | }xm', |
| 1040 | - array($this, '_doTable_leadingPipe_callback'), $text); |
|
| 1040 | + array($this, '_doTable_leadingPipe_callback'), $text); |
|
| 1041 | 1041 | |
| 1042 | - # |
|
| 1043 | - # Find tables without leading pipe. |
|
| 1044 | - # |
|
| 1045 | - # Header 1 | Header 2 |
|
| 1046 | - # -------- | -------- |
|
| 1047 | - # Cell 1 | Cell 2 |
|
| 1048 | - # Cell 3 | Cell 4 |
|
| 1049 | - # |
|
| 1050 | - $text = preg_replace_callback(' |
|
| 1042 | + # |
|
| 1043 | + # Find tables without leading pipe. |
|
| 1044 | + # |
|
| 1045 | + # Header 1 | Header 2 |
|
| 1046 | + # -------- | -------- |
|
| 1047 | + # Cell 1 | Cell 2 |
|
| 1048 | + # Cell 3 | Cell 4 |
|
| 1049 | + # |
|
| 1050 | + $text = preg_replace_callback(' |
|
| 1051 | 1051 | { |
| 1052 | 1052 | ^ # Start of a line |
| 1053 | 1053 | [ ]{0,'.$less_than_tab.'} # Allowed whitespace. |
@@ -1063,100 +1063,100 @@ discard block |
||
| 1063 | 1063 | ) |
| 1064 | 1064 | (?=\n|\Z) # Stop at final double newline. |
| 1065 | 1065 | }xm', |
| 1066 | - array($this, '_DoTable_callback'), $text); |
|
| 1067 | - |
|
| 1068 | - return $text; |
|
| 1069 | - } |
|
| 1070 | - protected function _doTable_leadingPipe_callback($matches) { |
|
| 1071 | - $head = $matches[1]; |
|
| 1072 | - $underline = $matches[2]; |
|
| 1073 | - $content = $matches[3]; |
|
| 1066 | + array($this, '_DoTable_callback'), $text); |
|
| 1067 | + |
|
| 1068 | + return $text; |
|
| 1069 | + } |
|
| 1070 | + protected function _doTable_leadingPipe_callback($matches) { |
|
| 1071 | + $head = $matches[1]; |
|
| 1072 | + $underline = $matches[2]; |
|
| 1073 | + $content = $matches[3]; |
|
| 1074 | 1074 | |
| 1075 | - # Remove leading pipe for each row. |
|
| 1076 | - $content = preg_replace('/^ *[|]/m', '', $content); |
|
| 1075 | + # Remove leading pipe for each row. |
|
| 1076 | + $content = preg_replace('/^ *[|]/m', '', $content); |
|
| 1077 | 1077 | |
| 1078 | - return $this->_doTable_callback(array($matches[0], $head, $underline, $content)); |
|
| 1079 | - } |
|
| 1080 | - protected function _doTable_makeAlignAttr($alignname) |
|
| 1081 | - { |
|
| 1082 | - if (empty($this->table_align_class_tmpl)) |
|
| 1083 | - return " align=\"$alignname\""; |
|
| 1084 | - |
|
| 1085 | - $classname = str_replace('%%', $alignname, $this->table_align_class_tmpl); |
|
| 1086 | - return " class=\"$classname\""; |
|
| 1087 | - } |
|
| 1088 | - protected function _doTable_callback($matches) { |
|
| 1089 | - $head = $matches[1]; |
|
| 1090 | - $underline = $matches[2]; |
|
| 1091 | - $content = $matches[3]; |
|
| 1092 | - |
|
| 1093 | - # Remove any tailing pipes for each line. |
|
| 1094 | - $head = preg_replace('/[|] *$/m', '', $head); |
|
| 1095 | - $underline = preg_replace('/[|] *$/m', '', $underline); |
|
| 1096 | - $content = preg_replace('/[|] *$/m', '', $content); |
|
| 1078 | + return $this->_doTable_callback(array($matches[0], $head, $underline, $content)); |
|
| 1079 | + } |
|
| 1080 | + protected function _doTable_makeAlignAttr($alignname) |
|
| 1081 | + { |
|
| 1082 | + if (empty($this->table_align_class_tmpl)) |
|
| 1083 | + return " align=\"$alignname\""; |
|
| 1084 | + |
|
| 1085 | + $classname = str_replace('%%', $alignname, $this->table_align_class_tmpl); |
|
| 1086 | + return " class=\"$classname\""; |
|
| 1087 | + } |
|
| 1088 | + protected function _doTable_callback($matches) { |
|
| 1089 | + $head = $matches[1]; |
|
| 1090 | + $underline = $matches[2]; |
|
| 1091 | + $content = $matches[3]; |
|
| 1092 | + |
|
| 1093 | + # Remove any tailing pipes for each line. |
|
| 1094 | + $head = preg_replace('/[|] *$/m', '', $head); |
|
| 1095 | + $underline = preg_replace('/[|] *$/m', '', $underline); |
|
| 1096 | + $content = preg_replace('/[|] *$/m', '', $content); |
|
| 1097 | 1097 | |
| 1098 | - # Reading alignement from header underline. |
|
| 1099 | - $separators = preg_split('/ *[|] */', $underline); |
|
| 1100 | - foreach ($separators as $n => $s) { |
|
| 1101 | - if (preg_match('/^ *-+: *$/', $s)) |
|
| 1102 | - $attr[$n] = $this->_doTable_makeAlignAttr('right'); |
|
| 1103 | - else if (preg_match('/^ *:-+: *$/', $s)) |
|
| 1104 | - $attr[$n] = $this->_doTable_makeAlignAttr('center'); |
|
| 1105 | - else if (preg_match('/^ *:-+ *$/', $s)) |
|
| 1106 | - $attr[$n] = $this->_doTable_makeAlignAttr('left'); |
|
| 1107 | - else |
|
| 1108 | - $attr[$n] = ''; |
|
| 1109 | - } |
|
| 1098 | + # Reading alignement from header underline. |
|
| 1099 | + $separators = preg_split('/ *[|] */', $underline); |
|
| 1100 | + foreach ($separators as $n => $s) { |
|
| 1101 | + if (preg_match('/^ *-+: *$/', $s)) |
|
| 1102 | + $attr[$n] = $this->_doTable_makeAlignAttr('right'); |
|
| 1103 | + else if (preg_match('/^ *:-+: *$/', $s)) |
|
| 1104 | + $attr[$n] = $this->_doTable_makeAlignAttr('center'); |
|
| 1105 | + else if (preg_match('/^ *:-+ *$/', $s)) |
|
| 1106 | + $attr[$n] = $this->_doTable_makeAlignAttr('left'); |
|
| 1107 | + else |
|
| 1108 | + $attr[$n] = ''; |
|
| 1109 | + } |
|
| 1110 | 1110 | |
| 1111 | - # Parsing span elements, including code spans, character escapes, |
|
| 1112 | - # and inline HTML tags, so that pipes inside those gets ignored. |
|
| 1113 | - $head = $this->parseSpan($head); |
|
| 1114 | - $headers = preg_split('/ *[|] */', $head); |
|
| 1115 | - $col_count = count($headers); |
|
| 1116 | - $attr = array_pad($attr, $col_count, ''); |
|
| 1111 | + # Parsing span elements, including code spans, character escapes, |
|
| 1112 | + # and inline HTML tags, so that pipes inside those gets ignored. |
|
| 1113 | + $head = $this->parseSpan($head); |
|
| 1114 | + $headers = preg_split('/ *[|] */', $head); |
|
| 1115 | + $col_count = count($headers); |
|
| 1116 | + $attr = array_pad($attr, $col_count, ''); |
|
| 1117 | 1117 | |
| 1118 | - # Write column headers. |
|
| 1119 | - $text = "<table>\n"; |
|
| 1120 | - $text .= "<thead>\n"; |
|
| 1121 | - $text .= "<tr>\n"; |
|
| 1122 | - foreach ($headers as $n => $header) |
|
| 1123 | - $text .= " <th$attr[$n]>".$this->runSpanGamut(trim($header))."</th>\n"; |
|
| 1124 | - $text .= "</tr>\n"; |
|
| 1125 | - $text .= "</thead>\n"; |
|
| 1118 | + # Write column headers. |
|
| 1119 | + $text = "<table>\n"; |
|
| 1120 | + $text .= "<thead>\n"; |
|
| 1121 | + $text .= "<tr>\n"; |
|
| 1122 | + foreach ($headers as $n => $header) |
|
| 1123 | + $text .= " <th$attr[$n]>".$this->runSpanGamut(trim($header))."</th>\n"; |
|
| 1124 | + $text .= "</tr>\n"; |
|
| 1125 | + $text .= "</thead>\n"; |
|
| 1126 | 1126 | |
| 1127 | - # Split content by row. |
|
| 1128 | - $rows = explode("\n", trim($content, "\n")); |
|
| 1127 | + # Split content by row. |
|
| 1128 | + $rows = explode("\n", trim($content, "\n")); |
|
| 1129 | 1129 | |
| 1130 | - $text .= "<tbody>\n"; |
|
| 1131 | - foreach ($rows as $row) { |
|
| 1132 | - # Parsing span elements, including code spans, character escapes, |
|
| 1133 | - # and inline HTML tags, so that pipes inside those gets ignored. |
|
| 1134 | - $row = $this->parseSpan($row); |
|
| 1130 | + $text .= "<tbody>\n"; |
|
| 1131 | + foreach ($rows as $row) { |
|
| 1132 | + # Parsing span elements, including code spans, character escapes, |
|
| 1133 | + # and inline HTML tags, so that pipes inside those gets ignored. |
|
| 1134 | + $row = $this->parseSpan($row); |
|
| 1135 | 1135 | |
| 1136 | - # Split row by cell. |
|
| 1137 | - $row_cells = preg_split('/ *[|] */', $row, $col_count); |
|
| 1138 | - $row_cells = array_pad($row_cells, $col_count, ''); |
|
| 1136 | + # Split row by cell. |
|
| 1137 | + $row_cells = preg_split('/ *[|] */', $row, $col_count); |
|
| 1138 | + $row_cells = array_pad($row_cells, $col_count, ''); |
|
| 1139 | 1139 | |
| 1140 | - $text .= "<tr>\n"; |
|
| 1141 | - foreach ($row_cells as $n => $cell) |
|
| 1142 | - $text .= " <td$attr[$n]>".$this->runSpanGamut(trim($cell))."</td>\n"; |
|
| 1143 | - $text .= "</tr>\n"; |
|
| 1144 | - } |
|
| 1145 | - $text .= "</tbody>\n"; |
|
| 1146 | - $text .= "</table>"; |
|
| 1140 | + $text .= "<tr>\n"; |
|
| 1141 | + foreach ($row_cells as $n => $cell) |
|
| 1142 | + $text .= " <td$attr[$n]>".$this->runSpanGamut(trim($cell))."</td>\n"; |
|
| 1143 | + $text .= "</tr>\n"; |
|
| 1144 | + } |
|
| 1145 | + $text .= "</tbody>\n"; |
|
| 1146 | + $text .= "</table>"; |
|
| 1147 | 1147 | |
| 1148 | - return $this->hashBlock($text) . "\n"; |
|
| 1149 | - } |
|
| 1148 | + return $this->hashBlock($text) . "\n"; |
|
| 1149 | + } |
|
| 1150 | 1150 | |
| 1151 | 1151 | |
| 1152 | - protected function doDefLists($text) { |
|
| 1153 | - # |
|
| 1154 | - # Form HTML definition lists. |
|
| 1155 | - # |
|
| 1156 | - $less_than_tab = $this->tab_width - 1; |
|
| 1157 | - |
|
| 1158 | - # Re-usable pattern to match any entire dl list: |
|
| 1159 | - $whole_list_re = '(?> |
|
| 1152 | + protected function doDefLists($text) { |
|
| 1153 | + # |
|
| 1154 | + # Form HTML definition lists. |
|
| 1155 | + # |
|
| 1156 | + $less_than_tab = $this->tab_width - 1; |
|
| 1157 | + |
|
| 1158 | + # Re-usable pattern to match any entire dl list: |
|
| 1159 | + $whole_list_re = '(?> |
|
| 1160 | 1160 | ( # $1 = whole list |
| 1161 | 1161 | ( # $2 |
| 1162 | 1162 | [ ]{0,'.$less_than_tab.'} |
@@ -1183,38 +1183,38 @@ discard block |
||
| 1183 | 1183 | ) |
| 1184 | 1184 | )'; // mx |
| 1185 | 1185 | |
| 1186 | - $text = preg_replace_callback('{ |
|
| 1186 | + $text = preg_replace_callback('{ |
|
| 1187 | 1187 | (?>\A\n?|(?<=\n\n)) |
| 1188 | 1188 | '.$whole_list_re.' |
| 1189 | 1189 | }mx', |
| 1190 | - array($this, '_doDefLists_callback'), $text); |
|
| 1190 | + array($this, '_doDefLists_callback'), $text); |
|
| 1191 | 1191 | |
| 1192 | - return $text; |
|
| 1193 | - } |
|
| 1194 | - protected function _doDefLists_callback($matches) { |
|
| 1195 | - # Re-usable patterns to match list item bullets and number markers: |
|
| 1196 | - $list = $matches[1]; |
|
| 1192 | + return $text; |
|
| 1193 | + } |
|
| 1194 | + protected function _doDefLists_callback($matches) { |
|
| 1195 | + # Re-usable patterns to match list item bullets and number markers: |
|
| 1196 | + $list = $matches[1]; |
|
| 1197 | 1197 | |
| 1198 | - # Turn double returns into triple returns, so that we can make a |
|
| 1199 | - # paragraph for the last item in a list, if necessary: |
|
| 1200 | - $result = trim($this->processDefListItems($list)); |
|
| 1201 | - $result = "<dl>\n" . $result . "\n</dl>"; |
|
| 1202 | - return $this->hashBlock($result) . "\n\n"; |
|
| 1203 | - } |
|
| 1204 | - |
|
| 1205 | - |
|
| 1206 | - protected function processDefListItems($list_str) { |
|
| 1207 | - # |
|
| 1208 | - # Process the contents of a single definition list, splitting it |
|
| 1209 | - # into individual term and definition list items. |
|
| 1210 | - # |
|
| 1211 | - $less_than_tab = $this->tab_width - 1; |
|
| 1198 | + # Turn double returns into triple returns, so that we can make a |
|
| 1199 | + # paragraph for the last item in a list, if necessary: |
|
| 1200 | + $result = trim($this->processDefListItems($list)); |
|
| 1201 | + $result = "<dl>\n" . $result . "\n</dl>"; |
|
| 1202 | + return $this->hashBlock($result) . "\n\n"; |
|
| 1203 | + } |
|
| 1204 | + |
|
| 1205 | + |
|
| 1206 | + protected function processDefListItems($list_str) { |
|
| 1207 | + # |
|
| 1208 | + # Process the contents of a single definition list, splitting it |
|
| 1209 | + # into individual term and definition list items. |
|
| 1210 | + # |
|
| 1211 | + $less_than_tab = $this->tab_width - 1; |
|
| 1212 | 1212 | |
| 1213 | - # trim trailing blank lines: |
|
| 1214 | - $list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str); |
|
| 1213 | + # trim trailing blank lines: |
|
| 1214 | + $list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str); |
|
| 1215 | 1215 | |
| 1216 | - # Process definition terms. |
|
| 1217 | - $list_str = preg_replace_callback('{ |
|
| 1216 | + # Process definition terms. |
|
| 1217 | + $list_str = preg_replace_callback('{ |
|
| 1218 | 1218 | (?>\A\n?|\n\n+) # leading line |
| 1219 | 1219 | ( # definition terms = $1 |
| 1220 | 1220 | [ ]{0,'.$less_than_tab.'} # leading whitespace |
@@ -1225,10 +1225,10 @@ discard block |
||
| 1225 | 1225 | (?=\n?[ ]{0,3}:[ ]) # lookahead for following line feed |
| 1226 | 1226 | # with a definition mark. |
| 1227 | 1227 | }xm', |
| 1228 | - array($this, '_processDefListItems_callback_dt'), $list_str); |
|
| 1228 | + array($this, '_processDefListItems_callback_dt'), $list_str); |
|
| 1229 | 1229 | |
| 1230 | - # Process actual definitions. |
|
| 1231 | - $list_str = preg_replace_callback('{ |
|
| 1230 | + # Process actual definitions. |
|
| 1231 | + $list_str = preg_replace_callback('{ |
|
| 1232 | 1232 | \n(\n+)? # leading line = $1 |
| 1233 | 1233 | ( # marker space = $2 |
| 1234 | 1234 | [ ]{0,'.$less_than_tab.'} # whitespace before colon |
@@ -1242,50 +1242,50 @@ discard block |
||
| 1242 | 1242 | ) |
| 1243 | 1243 | ) |
| 1244 | 1244 | }xm', |
| 1245 | - array($this, '_processDefListItems_callback_dd'), $list_str); |
|
| 1246 | - |
|
| 1247 | - return $list_str; |
|
| 1248 | - } |
|
| 1249 | - protected function _processDefListItems_callback_dt($matches) { |
|
| 1250 | - $terms = explode("\n", trim($matches[1])); |
|
| 1251 | - $text = ''; |
|
| 1252 | - foreach ($terms as $term) { |
|
| 1253 | - $term = $this->runSpanGamut(trim($term)); |
|
| 1254 | - $text .= "\n<dt>" . $term . "</dt>"; |
|
| 1255 | - } |
|
| 1256 | - return $text . "\n"; |
|
| 1257 | - } |
|
| 1258 | - protected function _processDefListItems_callback_dd($matches) { |
|
| 1259 | - $leading_line = $matches[1]; |
|
| 1260 | - $marker_space = $matches[2]; |
|
| 1261 | - $def = $matches[3]; |
|
| 1262 | - |
|
| 1263 | - if ($leading_line || preg_match('/\n{2,}/', $def)) { |
|
| 1264 | - # Replace marker with the appropriate whitespace indentation |
|
| 1265 | - $def = str_repeat(' ', strlen($marker_space)) . $def; |
|
| 1266 | - $def = $this->runBlockGamut($this->outdent($def . "\n\n")); |
|
| 1267 | - $def = "\n". $def ."\n"; |
|
| 1268 | - } |
|
| 1269 | - else { |
|
| 1270 | - $def = rtrim($def); |
|
| 1271 | - $def = $this->runSpanGamut($this->outdent($def)); |
|
| 1272 | - } |
|
| 1273 | - |
|
| 1274 | - return "\n<dd>" . $def . "</dd>\n"; |
|
| 1275 | - } |
|
| 1276 | - |
|
| 1277 | - |
|
| 1278 | - protected function doFencedCodeBlocks($text) { |
|
| 1279 | - # |
|
| 1280 | - # Adding the fenced code block syntax to regular Markdown: |
|
| 1281 | - # |
|
| 1282 | - # ~~~ |
|
| 1283 | - # Code block |
|
| 1284 | - # ~~~ |
|
| 1285 | - # |
|
| 1286 | - $less_than_tab = $this->tab_width; |
|
| 1245 | + array($this, '_processDefListItems_callback_dd'), $list_str); |
|
| 1246 | + |
|
| 1247 | + return $list_str; |
|
| 1248 | + } |
|
| 1249 | + protected function _processDefListItems_callback_dt($matches) { |
|
| 1250 | + $terms = explode("\n", trim($matches[1])); |
|
| 1251 | + $text = ''; |
|
| 1252 | + foreach ($terms as $term) { |
|
| 1253 | + $term = $this->runSpanGamut(trim($term)); |
|
| 1254 | + $text .= "\n<dt>" . $term . "</dt>"; |
|
| 1255 | + } |
|
| 1256 | + return $text . "\n"; |
|
| 1257 | + } |
|
| 1258 | + protected function _processDefListItems_callback_dd($matches) { |
|
| 1259 | + $leading_line = $matches[1]; |
|
| 1260 | + $marker_space = $matches[2]; |
|
| 1261 | + $def = $matches[3]; |
|
| 1262 | + |
|
| 1263 | + if ($leading_line || preg_match('/\n{2,}/', $def)) { |
|
| 1264 | + # Replace marker with the appropriate whitespace indentation |
|
| 1265 | + $def = str_repeat(' ', strlen($marker_space)) . $def; |
|
| 1266 | + $def = $this->runBlockGamut($this->outdent($def . "\n\n")); |
|
| 1267 | + $def = "\n". $def ."\n"; |
|
| 1268 | + } |
|
| 1269 | + else { |
|
| 1270 | + $def = rtrim($def); |
|
| 1271 | + $def = $this->runSpanGamut($this->outdent($def)); |
|
| 1272 | + } |
|
| 1273 | + |
|
| 1274 | + return "\n<dd>" . $def . "</dd>\n"; |
|
| 1275 | + } |
|
| 1276 | + |
|
| 1277 | + |
|
| 1278 | + protected function doFencedCodeBlocks($text) { |
|
| 1279 | + # |
|
| 1280 | + # Adding the fenced code block syntax to regular Markdown: |
|
| 1281 | + # |
|
| 1282 | + # ~~~ |
|
| 1283 | + # Code block |
|
| 1284 | + # ~~~ |
|
| 1285 | + # |
|
| 1286 | + $less_than_tab = $this->tab_width; |
|
| 1287 | 1287 | |
| 1288 | - $text = preg_replace_callback('{ |
|
| 1288 | + $text = preg_replace_callback('{ |
|
| 1289 | 1289 | (?:\n|\A) |
| 1290 | 1290 | # 1: Opening marker |
| 1291 | 1291 | ( |
@@ -1310,105 +1310,105 @@ discard block |
||
| 1310 | 1310 | # Closing marker. |
| 1311 | 1311 | \1 [ ]* (?= \n ) |
| 1312 | 1312 | }xm', |
| 1313 | - array($this, '_doFencedCodeBlocks_callback'), $text); |
|
| 1314 | - |
|
| 1315 | - return $text; |
|
| 1316 | - } |
|
| 1317 | - protected function _doFencedCodeBlocks_callback($matches) { |
|
| 1318 | - $classname =& $matches[2]; |
|
| 1319 | - $attrs =& $matches[3]; |
|
| 1320 | - $codeblock = $matches[4]; |
|
| 1321 | - $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); |
|
| 1322 | - $codeblock = preg_replace_callback('/^\n+/', |
|
| 1323 | - array($this, '_doFencedCodeBlocks_newlines'), $codeblock); |
|
| 1324 | - |
|
| 1325 | - if ($classname != "") { |
|
| 1326 | - if ($classname{0} == '.') |
|
| 1327 | - $classname = substr($classname, 1); |
|
| 1328 | - $attr_str = ' class="'.$this->code_class_prefix.$classname.'"'; |
|
| 1329 | - } else { |
|
| 1330 | - $attr_str = $this->doExtraAttributes($this->code_attr_on_pre ? "pre" : "code", $attrs); |
|
| 1331 | - } |
|
| 1332 | - $pre_attr_str = $this->code_attr_on_pre ? $attr_str : ''; |
|
| 1333 | - $code_attr_str = $this->code_attr_on_pre ? '' : $attr_str; |
|
| 1334 | - $codeblock = "<pre$pre_attr_str><code$code_attr_str>$codeblock</code></pre>"; |
|
| 1313 | + array($this, '_doFencedCodeBlocks_callback'), $text); |
|
| 1314 | + |
|
| 1315 | + return $text; |
|
| 1316 | + } |
|
| 1317 | + protected function _doFencedCodeBlocks_callback($matches) { |
|
| 1318 | + $classname =& $matches[2]; |
|
| 1319 | + $attrs =& $matches[3]; |
|
| 1320 | + $codeblock = $matches[4]; |
|
| 1321 | + $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); |
|
| 1322 | + $codeblock = preg_replace_callback('/^\n+/', |
|
| 1323 | + array($this, '_doFencedCodeBlocks_newlines'), $codeblock); |
|
| 1324 | + |
|
| 1325 | + if ($classname != "") { |
|
| 1326 | + if ($classname{0} == '.') |
|
| 1327 | + $classname = substr($classname, 1); |
|
| 1328 | + $attr_str = ' class="'.$this->code_class_prefix.$classname.'"'; |
|
| 1329 | + } else { |
|
| 1330 | + $attr_str = $this->doExtraAttributes($this->code_attr_on_pre ? "pre" : "code", $attrs); |
|
| 1331 | + } |
|
| 1332 | + $pre_attr_str = $this->code_attr_on_pre ? $attr_str : ''; |
|
| 1333 | + $code_attr_str = $this->code_attr_on_pre ? '' : $attr_str; |
|
| 1334 | + $codeblock = "<pre$pre_attr_str><code$code_attr_str>$codeblock</code></pre>"; |
|
| 1335 | 1335 | |
| 1336 | - return "\n\n".$this->hashBlock($codeblock)."\n\n"; |
|
| 1337 | - } |
|
| 1338 | - protected function _doFencedCodeBlocks_newlines($matches) { |
|
| 1339 | - return str_repeat("<br$this->empty_element_suffix", |
|
| 1340 | - strlen($matches[0])); |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - |
|
| 1344 | - # |
|
| 1345 | - # Redefining emphasis markers so that emphasis by underscore does not |
|
| 1346 | - # work in the middle of a word. |
|
| 1347 | - # |
|
| 1348 | - protected $em_relist = array( |
|
| 1349 | - '' => '(?:(?<!\*)\*(?!\*)|(?<![a-zA-Z0-9_])_(?!_))(?![\.,:;]?\s)', |
|
| 1350 | - '*' => '(?<![\s*])\*(?!\*)', |
|
| 1351 | - '_' => '(?<![\s_])_(?![a-zA-Z0-9_])', |
|
| 1352 | - ); |
|
| 1353 | - protected $strong_relist = array( |
|
| 1354 | - '' => '(?:(?<!\*)\*\*(?!\*)|(?<![a-zA-Z0-9_])__(?!_))(?![\.,:;]?\s)', |
|
| 1355 | - '**' => '(?<![\s*])\*\*(?!\*)', |
|
| 1356 | - '__' => '(?<![\s_])__(?![a-zA-Z0-9_])', |
|
| 1357 | - ); |
|
| 1358 | - protected $em_strong_relist = array( |
|
| 1359 | - '' => '(?:(?<!\*)\*\*\*(?!\*)|(?<![a-zA-Z0-9_])___(?!_))(?![\.,:;]?\s)', |
|
| 1360 | - '***' => '(?<![\s*])\*\*\*(?!\*)', |
|
| 1361 | - '___' => '(?<![\s_])___(?![a-zA-Z0-9_])', |
|
| 1362 | - ); |
|
| 1363 | - |
|
| 1364 | - |
|
| 1365 | - protected function formParagraphs($text) { |
|
| 1366 | - # |
|
| 1367 | - # Params: |
|
| 1368 | - # $text - string to process with html <p> tags |
|
| 1369 | - # |
|
| 1370 | - # Strip leading and trailing lines: |
|
| 1371 | - $text = preg_replace('/\A\n+|\n+\z/', '', $text); |
|
| 1336 | + return "\n\n".$this->hashBlock($codeblock)."\n\n"; |
|
| 1337 | + } |
|
| 1338 | + protected function _doFencedCodeBlocks_newlines($matches) { |
|
| 1339 | + return str_repeat("<br$this->empty_element_suffix", |
|
| 1340 | + strlen($matches[0])); |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + |
|
| 1344 | + # |
|
| 1345 | + # Redefining emphasis markers so that emphasis by underscore does not |
|
| 1346 | + # work in the middle of a word. |
|
| 1347 | + # |
|
| 1348 | + protected $em_relist = array( |
|
| 1349 | + '' => '(?:(?<!\*)\*(?!\*)|(?<![a-zA-Z0-9_])_(?!_))(?![\.,:;]?\s)', |
|
| 1350 | + '*' => '(?<![\s*])\*(?!\*)', |
|
| 1351 | + '_' => '(?<![\s_])_(?![a-zA-Z0-9_])', |
|
| 1352 | + ); |
|
| 1353 | + protected $strong_relist = array( |
|
| 1354 | + '' => '(?:(?<!\*)\*\*(?!\*)|(?<![a-zA-Z0-9_])__(?!_))(?![\.,:;]?\s)', |
|
| 1355 | + '**' => '(?<![\s*])\*\*(?!\*)', |
|
| 1356 | + '__' => '(?<![\s_])__(?![a-zA-Z0-9_])', |
|
| 1357 | + ); |
|
| 1358 | + protected $em_strong_relist = array( |
|
| 1359 | + '' => '(?:(?<!\*)\*\*\*(?!\*)|(?<![a-zA-Z0-9_])___(?!_))(?![\.,:;]?\s)', |
|
| 1360 | + '***' => '(?<![\s*])\*\*\*(?!\*)', |
|
| 1361 | + '___' => '(?<![\s_])___(?![a-zA-Z0-9_])', |
|
| 1362 | + ); |
|
| 1363 | + |
|
| 1364 | + |
|
| 1365 | + protected function formParagraphs($text) { |
|
| 1366 | + # |
|
| 1367 | + # Params: |
|
| 1368 | + # $text - string to process with html <p> tags |
|
| 1369 | + # |
|
| 1370 | + # Strip leading and trailing lines: |
|
| 1371 | + $text = preg_replace('/\A\n+|\n+\z/', '', $text); |
|
| 1372 | 1372 | |
| 1373 | - $grafs = preg_split('/\n{2,}/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
| 1373 | + $grafs = preg_split('/\n{2,}/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
| 1374 | 1374 | |
| 1375 | - # |
|
| 1376 | - # Wrap <p> tags and unhashify HTML blocks |
|
| 1377 | - # |
|
| 1378 | - foreach ($grafs as $key => $value) { |
|
| 1379 | - $value = trim($this->runSpanGamut($value)); |
|
| 1375 | + # |
|
| 1376 | + # Wrap <p> tags and unhashify HTML blocks |
|
| 1377 | + # |
|
| 1378 | + foreach ($grafs as $key => $value) { |
|
| 1379 | + $value = trim($this->runSpanGamut($value)); |
|
| 1380 | 1380 | |
| 1381 | - # Check if this should be enclosed in a paragraph. |
|
| 1382 | - # Clean tag hashes & block tag hashes are left alone. |
|
| 1383 | - $is_p = !preg_match('/^B\x1A[0-9]+B|^C\x1A[0-9]+C$/', $value); |
|
| 1381 | + # Check if this should be enclosed in a paragraph. |
|
| 1382 | + # Clean tag hashes & block tag hashes are left alone. |
|
| 1383 | + $is_p = !preg_match('/^B\x1A[0-9]+B|^C\x1A[0-9]+C$/', $value); |
|
| 1384 | 1384 | |
| 1385 | - if ($is_p) { |
|
| 1386 | - $value = "<p>$value</p>"; |
|
| 1387 | - } |
|
| 1388 | - $grafs[$key] = $value; |
|
| 1389 | - } |
|
| 1385 | + if ($is_p) { |
|
| 1386 | + $value = "<p>$value</p>"; |
|
| 1387 | + } |
|
| 1388 | + $grafs[$key] = $value; |
|
| 1389 | + } |
|
| 1390 | 1390 | |
| 1391 | - # Join grafs in one text, then unhash HTML tags. |
|
| 1392 | - $text = implode("\n\n", $grafs); |
|
| 1391 | + # Join grafs in one text, then unhash HTML tags. |
|
| 1392 | + $text = implode("\n\n", $grafs); |
|
| 1393 | 1393 | |
| 1394 | - # Finish by removing any tag hashes still present in $text. |
|
| 1395 | - $text = $this->unhash($text); |
|
| 1394 | + # Finish by removing any tag hashes still present in $text. |
|
| 1395 | + $text = $this->unhash($text); |
|
| 1396 | 1396 | |
| 1397 | - return $text; |
|
| 1398 | - } |
|
| 1397 | + return $text; |
|
| 1398 | + } |
|
| 1399 | 1399 | |
| 1400 | 1400 | |
| 1401 | - ### Footnotes |
|
| 1401 | + ### Footnotes |
|
| 1402 | 1402 | |
| 1403 | - protected function stripFootnotes($text) { |
|
| 1404 | - # |
|
| 1405 | - # Strips link definitions from text, stores the URLs and titles in |
|
| 1406 | - # hash references. |
|
| 1407 | - # |
|
| 1408 | - $less_than_tab = $this->tab_width - 1; |
|
| 1409 | - |
|
| 1410 | - # Link defs are in the form: [^id]: url "optional title" |
|
| 1411 | - $text = preg_replace_callback('{ |
|
| 1403 | + protected function stripFootnotes($text) { |
|
| 1404 | + # |
|
| 1405 | + # Strips link definitions from text, stores the URLs and titles in |
|
| 1406 | + # hash references. |
|
| 1407 | + # |
|
| 1408 | + $less_than_tab = $this->tab_width - 1; |
|
| 1409 | + |
|
| 1410 | + # Link defs are in the form: [^id]: url "optional title" |
|
| 1411 | + $text = preg_replace_callback('{ |
|
| 1412 | 1412 | ^[ ]{0,'.$less_than_tab.'}\[\^(.+?)\][ ]?: # note_id = $1 |
| 1413 | 1413 | [ ]* |
| 1414 | 1414 | \n? # maybe *one* newline |
@@ -1423,192 +1423,192 @@ discard block |
||
| 1423 | 1423 | )* |
| 1424 | 1424 | ) |
| 1425 | 1425 | }xm', |
| 1426 | - array($this, '_stripFootnotes_callback'), |
|
| 1427 | - $text); |
|
| 1428 | - return $text; |
|
| 1429 | - } |
|
| 1430 | - protected function _stripFootnotes_callback($matches) { |
|
| 1431 | - $note_id = $this->fn_id_prefix . $matches[1]; |
|
| 1432 | - $this->footnotes[$note_id] = $this->outdent($matches[2]); |
|
| 1433 | - return ''; # String that will replace the block |
|
| 1434 | - } |
|
| 1435 | - |
|
| 1436 | - |
|
| 1437 | - protected function doFootnotes($text) { |
|
| 1438 | - # |
|
| 1439 | - # Replace footnote references in $text [^id] with a special text-token |
|
| 1440 | - # which will be replaced by the actual footnote marker in appendFootnotes. |
|
| 1441 | - # |
|
| 1442 | - if (!$this->in_anchor) { |
|
| 1443 | - $text = preg_replace('{\[\^(.+?)\]}', "F\x1Afn:\\1\x1A:", $text); |
|
| 1444 | - } |
|
| 1445 | - return $text; |
|
| 1446 | - } |
|
| 1426 | + array($this, '_stripFootnotes_callback'), |
|
| 1427 | + $text); |
|
| 1428 | + return $text; |
|
| 1429 | + } |
|
| 1430 | + protected function _stripFootnotes_callback($matches) { |
|
| 1431 | + $note_id = $this->fn_id_prefix . $matches[1]; |
|
| 1432 | + $this->footnotes[$note_id] = $this->outdent($matches[2]); |
|
| 1433 | + return ''; # String that will replace the block |
|
| 1434 | + } |
|
| 1435 | + |
|
| 1436 | + |
|
| 1437 | + protected function doFootnotes($text) { |
|
| 1438 | + # |
|
| 1439 | + # Replace footnote references in $text [^id] with a special text-token |
|
| 1440 | + # which will be replaced by the actual footnote marker in appendFootnotes. |
|
| 1441 | + # |
|
| 1442 | + if (!$this->in_anchor) { |
|
| 1443 | + $text = preg_replace('{\[\^(.+?)\]}', "F\x1Afn:\\1\x1A:", $text); |
|
| 1444 | + } |
|
| 1445 | + return $text; |
|
| 1446 | + } |
|
| 1447 | 1447 | |
| 1448 | 1448 | |
| 1449 | - protected function appendFootnotes($text) { |
|
| 1450 | - # |
|
| 1451 | - # Append footnote list to text. |
|
| 1452 | - # |
|
| 1453 | - $text = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', |
|
| 1454 | - array($this, '_appendFootnotes_callback'), $text); |
|
| 1449 | + protected function appendFootnotes($text) { |
|
| 1450 | + # |
|
| 1451 | + # Append footnote list to text. |
|
| 1452 | + # |
|
| 1453 | + $text = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', |
|
| 1454 | + array($this, '_appendFootnotes_callback'), $text); |
|
| 1455 | 1455 | |
| 1456 | - if (!empty($this->footnotes_ordered)) { |
|
| 1457 | - $text .= "\n\n"; |
|
| 1458 | - $text .= "<div class=\"footnotes\">\n"; |
|
| 1459 | - $text .= "<hr". $this->empty_element_suffix ."\n"; |
|
| 1460 | - $text .= "<ol>\n\n"; |
|
| 1461 | - |
|
| 1462 | - $attr = ""; |
|
| 1463 | - if ($this->fn_backlink_class != "") { |
|
| 1464 | - $class = $this->fn_backlink_class; |
|
| 1465 | - $class = $this->encodeAttribute($class); |
|
| 1466 | - $attr .= " class=\"$class\""; |
|
| 1467 | - } |
|
| 1468 | - if ($this->fn_backlink_title != "") { |
|
| 1469 | - $title = $this->fn_backlink_title; |
|
| 1470 | - $title = $this->encodeAttribute($title); |
|
| 1471 | - $attr .= " title=\"$title\""; |
|
| 1472 | - } |
|
| 1473 | - $num = 0; |
|
| 1456 | + if (!empty($this->footnotes_ordered)) { |
|
| 1457 | + $text .= "\n\n"; |
|
| 1458 | + $text .= "<div class=\"footnotes\">\n"; |
|
| 1459 | + $text .= "<hr". $this->empty_element_suffix ."\n"; |
|
| 1460 | + $text .= "<ol>\n\n"; |
|
| 1461 | + |
|
| 1462 | + $attr = ""; |
|
| 1463 | + if ($this->fn_backlink_class != "") { |
|
| 1464 | + $class = $this->fn_backlink_class; |
|
| 1465 | + $class = $this->encodeAttribute($class); |
|
| 1466 | + $attr .= " class=\"$class\""; |
|
| 1467 | + } |
|
| 1468 | + if ($this->fn_backlink_title != "") { |
|
| 1469 | + $title = $this->fn_backlink_title; |
|
| 1470 | + $title = $this->encodeAttribute($title); |
|
| 1471 | + $attr .= " title=\"$title\""; |
|
| 1472 | + } |
|
| 1473 | + $num = 0; |
|
| 1474 | 1474 | |
| 1475 | - while (!empty($this->footnotes_ordered)) { |
|
| 1476 | - $footnote = reset($this->footnotes_ordered); |
|
| 1477 | - $note_id = key($this->footnotes_ordered); |
|
| 1478 | - unset($this->footnotes_ordered[$note_id]); |
|
| 1479 | - $ref_count = $this->footnotes_ref_count[$note_id]; |
|
| 1480 | - unset($this->footnotes_ref_count[$note_id]); |
|
| 1481 | - unset($this->footnotes[$note_id]); |
|
| 1475 | + while (!empty($this->footnotes_ordered)) { |
|
| 1476 | + $footnote = reset($this->footnotes_ordered); |
|
| 1477 | + $note_id = key($this->footnotes_ordered); |
|
| 1478 | + unset($this->footnotes_ordered[$note_id]); |
|
| 1479 | + $ref_count = $this->footnotes_ref_count[$note_id]; |
|
| 1480 | + unset($this->footnotes_ref_count[$note_id]); |
|
| 1481 | + unset($this->footnotes[$note_id]); |
|
| 1482 | 1482 | |
| 1483 | - $footnote .= "\n"; # Need to append newline before parsing. |
|
| 1484 | - $footnote = $this->runBlockGamut("$footnote\n"); |
|
| 1485 | - $footnote = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', |
|
| 1486 | - array($this, '_appendFootnotes_callback'), $footnote); |
|
| 1483 | + $footnote .= "\n"; # Need to append newline before parsing. |
|
| 1484 | + $footnote = $this->runBlockGamut("$footnote\n"); |
|
| 1485 | + $footnote = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', |
|
| 1486 | + array($this, '_appendFootnotes_callback'), $footnote); |
|
| 1487 | 1487 | |
| 1488 | - $attr = str_replace("%%", ++$num, $attr); |
|
| 1489 | - $note_id = $this->encodeAttribute($note_id); |
|
| 1490 | - |
|
| 1491 | - # Prepare backlink, multiple backlinks if multiple references |
|
| 1492 | - $backlink = "<a href=\"#fnref:$note_id\"$attr>↩</a>"; |
|
| 1493 | - for ($ref_num = 2; $ref_num <= $ref_count; ++$ref_num) { |
|
| 1494 | - $backlink .= " <a href=\"#fnref$ref_num:$note_id\"$attr>↩</a>"; |
|
| 1495 | - } |
|
| 1496 | - # Add backlink to last paragraph; create new paragraph if needed. |
|
| 1497 | - if (preg_match('{</p>$}', $footnote)) { |
|
| 1498 | - $footnote = substr($footnote, 0, -4) . " $backlink</p>"; |
|
| 1499 | - } else { |
|
| 1500 | - $footnote .= "\n\n<p>$backlink</p>"; |
|
| 1501 | - } |
|
| 1488 | + $attr = str_replace("%%", ++$num, $attr); |
|
| 1489 | + $note_id = $this->encodeAttribute($note_id); |
|
| 1490 | + |
|
| 1491 | + # Prepare backlink, multiple backlinks if multiple references |
|
| 1492 | + $backlink = "<a href=\"#fnref:$note_id\"$attr>↩</a>"; |
|
| 1493 | + for ($ref_num = 2; $ref_num <= $ref_count; ++$ref_num) { |
|
| 1494 | + $backlink .= " <a href=\"#fnref$ref_num:$note_id\"$attr>↩</a>"; |
|
| 1495 | + } |
|
| 1496 | + # Add backlink to last paragraph; create new paragraph if needed. |
|
| 1497 | + if (preg_match('{</p>$}', $footnote)) { |
|
| 1498 | + $footnote = substr($footnote, 0, -4) . " $backlink</p>"; |
|
| 1499 | + } else { |
|
| 1500 | + $footnote .= "\n\n<p>$backlink</p>"; |
|
| 1501 | + } |
|
| 1502 | 1502 | |
| 1503 | - $text .= "<li id=\"fn:$note_id\">\n"; |
|
| 1504 | - $text .= $footnote . "\n"; |
|
| 1505 | - $text .= "</li>\n\n"; |
|
| 1506 | - } |
|
| 1503 | + $text .= "<li id=\"fn:$note_id\">\n"; |
|
| 1504 | + $text .= $footnote . "\n"; |
|
| 1505 | + $text .= "</li>\n\n"; |
|
| 1506 | + } |
|
| 1507 | 1507 | |
| 1508 | - $text .= "</ol>\n"; |
|
| 1509 | - $text .= "</div>"; |
|
| 1510 | - } |
|
| 1511 | - return $text; |
|
| 1512 | - } |
|
| 1513 | - protected function _appendFootnotes_callback($matches) { |
|
| 1514 | - $node_id = $this->fn_id_prefix . $matches[1]; |
|
| 1508 | + $text .= "</ol>\n"; |
|
| 1509 | + $text .= "</div>"; |
|
| 1510 | + } |
|
| 1511 | + return $text; |
|
| 1512 | + } |
|
| 1513 | + protected function _appendFootnotes_callback($matches) { |
|
| 1514 | + $node_id = $this->fn_id_prefix . $matches[1]; |
|
| 1515 | 1515 | |
| 1516 | - # Create footnote marker only if it has a corresponding footnote *and* |
|
| 1517 | - # the footnote hasn't been used by another marker. |
|
| 1518 | - if (isset($this->footnotes[$node_id])) { |
|
| 1519 | - $num =& $this->footnotes_numbers[$node_id]; |
|
| 1520 | - if (!isset($num)) { |
|
| 1521 | - # Transfer footnote content to the ordered list and give it its |
|
| 1522 | - # number |
|
| 1523 | - $this->footnotes_ordered[$node_id] = $this->footnotes[$node_id]; |
|
| 1524 | - $this->footnotes_ref_count[$node_id] = 1; |
|
| 1525 | - $num = $this->footnote_counter++; |
|
| 1526 | - $ref_count_mark = ''; |
|
| 1527 | - } else { |
|
| 1528 | - $ref_count_mark = $this->footnotes_ref_count[$node_id] += 1; |
|
| 1529 | - } |
|
| 1530 | - |
|
| 1531 | - $attr = ""; |
|
| 1532 | - if ($this->fn_link_class != "") { |
|
| 1533 | - $class = $this->fn_link_class; |
|
| 1534 | - $class = $this->encodeAttribute($class); |
|
| 1535 | - $attr .= " class=\"$class\""; |
|
| 1536 | - } |
|
| 1537 | - if ($this->fn_link_title != "") { |
|
| 1538 | - $title = $this->fn_link_title; |
|
| 1539 | - $title = $this->encodeAttribute($title); |
|
| 1540 | - $attr .= " title=\"$title\""; |
|
| 1541 | - } |
|
| 1516 | + # Create footnote marker only if it has a corresponding footnote *and* |
|
| 1517 | + # the footnote hasn't been used by another marker. |
|
| 1518 | + if (isset($this->footnotes[$node_id])) { |
|
| 1519 | + $num =& $this->footnotes_numbers[$node_id]; |
|
| 1520 | + if (!isset($num)) { |
|
| 1521 | + # Transfer footnote content to the ordered list and give it its |
|
| 1522 | + # number |
|
| 1523 | + $this->footnotes_ordered[$node_id] = $this->footnotes[$node_id]; |
|
| 1524 | + $this->footnotes_ref_count[$node_id] = 1; |
|
| 1525 | + $num = $this->footnote_counter++; |
|
| 1526 | + $ref_count_mark = ''; |
|
| 1527 | + } else { |
|
| 1528 | + $ref_count_mark = $this->footnotes_ref_count[$node_id] += 1; |
|
| 1529 | + } |
|
| 1530 | + |
|
| 1531 | + $attr = ""; |
|
| 1532 | + if ($this->fn_link_class != "") { |
|
| 1533 | + $class = $this->fn_link_class; |
|
| 1534 | + $class = $this->encodeAttribute($class); |
|
| 1535 | + $attr .= " class=\"$class\""; |
|
| 1536 | + } |
|
| 1537 | + if ($this->fn_link_title != "") { |
|
| 1538 | + $title = $this->fn_link_title; |
|
| 1539 | + $title = $this->encodeAttribute($title); |
|
| 1540 | + $attr .= " title=\"$title\""; |
|
| 1541 | + } |
|
| 1542 | 1542 | |
| 1543 | - $attr = str_replace("%%", $num, $attr); |
|
| 1544 | - $node_id = $this->encodeAttribute($node_id); |
|
| 1543 | + $attr = str_replace("%%", $num, $attr); |
|
| 1544 | + $node_id = $this->encodeAttribute($node_id); |
|
| 1545 | 1545 | |
| 1546 | - return |
|
| 1547 | - "<sup id=\"fnref$ref_count_mark:$node_id\">". |
|
| 1548 | - "<a href=\"#fn:$node_id\"$attr>$num</a>". |
|
| 1549 | - "</sup>"; |
|
| 1550 | - } |
|
| 1546 | + return |
|
| 1547 | + "<sup id=\"fnref$ref_count_mark:$node_id\">". |
|
| 1548 | + "<a href=\"#fn:$node_id\"$attr>$num</a>". |
|
| 1549 | + "</sup>"; |
|
| 1550 | + } |
|
| 1551 | 1551 | |
| 1552 | - return "[^".$matches[1]."]"; |
|
| 1553 | - } |
|
| 1552 | + return "[^".$matches[1]."]"; |
|
| 1553 | + } |
|
| 1554 | 1554 | |
| 1555 | 1555 | |
| 1556 | - ### Abbreviations ### |
|
| 1556 | + ### Abbreviations ### |
|
| 1557 | 1557 | |
| 1558 | - protected function stripAbbreviations($text) { |
|
| 1559 | - # |
|
| 1560 | - # Strips abbreviations from text, stores titles in hash references. |
|
| 1561 | - # |
|
| 1562 | - $less_than_tab = $this->tab_width - 1; |
|
| 1563 | - |
|
| 1564 | - # Link defs are in the form: [id]*: url "optional title" |
|
| 1565 | - $text = preg_replace_callback('{ |
|
| 1558 | + protected function stripAbbreviations($text) { |
|
| 1559 | + # |
|
| 1560 | + # Strips abbreviations from text, stores titles in hash references. |
|
| 1561 | + # |
|
| 1562 | + $less_than_tab = $this->tab_width - 1; |
|
| 1563 | + |
|
| 1564 | + # Link defs are in the form: [id]*: url "optional title" |
|
| 1565 | + $text = preg_replace_callback('{ |
|
| 1566 | 1566 | ^[ ]{0,'.$less_than_tab.'}\*\[(.+?)\][ ]?: # abbr_id = $1 |
| 1567 | 1567 | (.*) # text = $2 (no blank lines allowed) |
| 1568 | 1568 | }xm', |
| 1569 | - array($this, '_stripAbbreviations_callback'), |
|
| 1570 | - $text); |
|
| 1571 | - return $text; |
|
| 1572 | - } |
|
| 1573 | - protected function _stripAbbreviations_callback($matches) { |
|
| 1574 | - $abbr_word = $matches[1]; |
|
| 1575 | - $abbr_desc = $matches[2]; |
|
| 1576 | - if ($this->abbr_word_re) |
|
| 1577 | - $this->abbr_word_re .= '|'; |
|
| 1578 | - $this->abbr_word_re .= preg_quote($abbr_word); |
|
| 1579 | - $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); |
|
| 1580 | - return ''; # String that will replace the block |
|
| 1581 | - } |
|
| 1569 | + array($this, '_stripAbbreviations_callback'), |
|
| 1570 | + $text); |
|
| 1571 | + return $text; |
|
| 1572 | + } |
|
| 1573 | + protected function _stripAbbreviations_callback($matches) { |
|
| 1574 | + $abbr_word = $matches[1]; |
|
| 1575 | + $abbr_desc = $matches[2]; |
|
| 1576 | + if ($this->abbr_word_re) |
|
| 1577 | + $this->abbr_word_re .= '|'; |
|
| 1578 | + $this->abbr_word_re .= preg_quote($abbr_word); |
|
| 1579 | + $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); |
|
| 1580 | + return ''; # String that will replace the block |
|
| 1581 | + } |
|
| 1582 | 1582 | |
| 1583 | 1583 | |
| 1584 | - protected function doAbbreviations($text) { |
|
| 1585 | - # |
|
| 1586 | - # Find defined abbreviations in text and wrap them in <abbr> elements. |
|
| 1587 | - # |
|
| 1588 | - if ($this->abbr_word_re) { |
|
| 1589 | - // cannot use the /x modifier because abbr_word_re may |
|
| 1590 | - // contain significant spaces: |
|
| 1591 | - $text = preg_replace_callback('{'. |
|
| 1592 | - '(?<![\w\x1A])'. |
|
| 1593 | - '(?:'.$this->abbr_word_re.')'. |
|
| 1594 | - '(?![\w\x1A])'. |
|
| 1595 | - '}', |
|
| 1596 | - array($this, '_doAbbreviations_callback'), $text); |
|
| 1597 | - } |
|
| 1598 | - return $text; |
|
| 1599 | - } |
|
| 1600 | - protected function _doAbbreviations_callback($matches) { |
|
| 1601 | - $abbr = $matches[0]; |
|
| 1602 | - if (isset($this->abbr_desciptions[$abbr])) { |
|
| 1603 | - $desc = $this->abbr_desciptions[$abbr]; |
|
| 1604 | - if (empty($desc)) { |
|
| 1605 | - return $this->hashPart("<abbr>$abbr</abbr>"); |
|
| 1606 | - } else { |
|
| 1607 | - $desc = $this->encodeAttribute($desc); |
|
| 1608 | - return $this->hashPart("<abbr title=\"$desc\">$abbr</abbr>"); |
|
| 1609 | - } |
|
| 1610 | - } else { |
|
| 1611 | - return $matches[0]; |
|
| 1612 | - } |
|
| 1613 | - } |
|
| 1584 | + protected function doAbbreviations($text) { |
|
| 1585 | + # |
|
| 1586 | + # Find defined abbreviations in text and wrap them in <abbr> elements. |
|
| 1587 | + # |
|
| 1588 | + if ($this->abbr_word_re) { |
|
| 1589 | + // cannot use the /x modifier because abbr_word_re may |
|
| 1590 | + // contain significant spaces: |
|
| 1591 | + $text = preg_replace_callback('{'. |
|
| 1592 | + '(?<![\w\x1A])'. |
|
| 1593 | + '(?:'.$this->abbr_word_re.')'. |
|
| 1594 | + '(?![\w\x1A])'. |
|
| 1595 | + '}', |
|
| 1596 | + array($this, '_doAbbreviations_callback'), $text); |
|
| 1597 | + } |
|
| 1598 | + return $text; |
|
| 1599 | + } |
|
| 1600 | + protected function _doAbbreviations_callback($matches) { |
|
| 1601 | + $abbr = $matches[0]; |
|
| 1602 | + if (isset($this->abbr_desciptions[$abbr])) { |
|
| 1603 | + $desc = $this->abbr_desciptions[$abbr]; |
|
| 1604 | + if (empty($desc)) { |
|
| 1605 | + return $this->hashPart("<abbr>$abbr</abbr>"); |
|
| 1606 | + } else { |
|
| 1607 | + $desc = $this->encodeAttribute($desc); |
|
| 1608 | + return $this->hashPart("<abbr title=\"$desc\">$abbr</abbr>"); |
|
| 1609 | + } |
|
| 1610 | + } else { |
|
| 1611 | + return $matches[0]; |
|
| 1612 | + } |
|
| 1613 | + } |
|
| 1614 | 1614 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | if ($this->abbr_word_re) |
| 110 | 110 | $this->abbr_word_re .= '|'; |
| 111 | 111 | $this->abbr_word_re .= preg_quote($abbr_word); |
| 112 | - $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); |
|
| 112 | + $this->abbr_desciptions[ $abbr_word ] = trim($abbr_desc); |
|
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | |
| 150 | 150 | # Split on components |
| 151 | 151 | preg_match_all('/[#.a-z][-_:a-zA-Z0-9=]+/', $attr, $matches); |
| 152 | - $elements = $matches[0]; |
|
| 152 | + $elements = $matches[ 0 ]; |
|
| 153 | 153 | |
| 154 | 154 | # handle classes and ids (only first id taken into account) |
| 155 | 155 | $classes = array(); |
@@ -157,12 +157,12 @@ discard block |
||
| 157 | 157 | $id = false; |
| 158 | 158 | foreach ($elements as $element) { |
| 159 | 159 | if ($element{0} == '.') { |
| 160 | - $classes[] = substr($element, 1); |
|
| 160 | + $classes[ ] = substr($element, 1); |
|
| 161 | 161 | } else if ($element{0} == '#') { |
| 162 | 162 | if ($id === false) $id = substr($element, 1); |
| 163 | 163 | } else if (strpos($element, '=') > 0) { |
| 164 | 164 | $parts = explode('=', $element, 2); |
| 165 | - $attributes[] = $parts[0] . '="' . $parts[1] . '"'; |
|
| 165 | + $attributes[ ] = $parts[ 0 ].'="'.$parts[ 1 ].'"'; |
|
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | |
@@ -171,10 +171,10 @@ discard block |
||
| 171 | 171 | # compose attributes as string |
| 172 | 172 | $attr_str = ""; |
| 173 | 173 | if (!empty($id)) { |
| 174 | - $attr_str .= ' id="'.$this->encodeAttribute($id) .'"'; |
|
| 174 | + $attr_str .= ' id="'.$this->encodeAttribute($id).'"'; |
|
| 175 | 175 | } |
| 176 | 176 | if (!empty($classes)) { |
| 177 | - $attr_str .= ' class="'. implode(" ", $classes) . '"'; |
|
| 177 | + $attr_str .= ' class="'.implode(" ", $classes).'"'; |
|
| 178 | 178 | } |
| 179 | 179 | if (!$this->no_markup && !empty($attributes)) { |
| 180 | 180 | $attr_str .= ' '.implode(" ", $attributes); |
@@ -219,11 +219,11 @@ discard block |
||
| 219 | 219 | return $text; |
| 220 | 220 | } |
| 221 | 221 | protected function _stripLinkDefinitions_callback($matches) { |
| 222 | - $link_id = strtolower($matches[1]); |
|
| 223 | - $url = $matches[2] == '' ? $matches[3] : $matches[2]; |
|
| 224 | - $this->urls[$link_id] = $url; |
|
| 225 | - $this->titles[$link_id] =& $matches[4]; |
|
| 226 | - $this->ref_attr[$link_id] = $this->doExtraAttributes("", $dummy =& $matches[5]); |
|
| 222 | + $link_id = strtolower($matches[ 1 ]); |
|
| 223 | + $url = $matches[ 2 ] == '' ? $matches[ 3 ] : $matches[ 2 ]; |
|
| 224 | + $this->urls[ $link_id ] = $url; |
|
| 225 | + $this->titles[ $link_id ] = & $matches[ 4 ]; |
|
| 226 | + $this->ref_attr[ $link_id ] = $this->doExtraAttributes("", $dummy = & $matches[ 5 ]); |
|
| 227 | 227 | return ''; # String that will replace the block |
| 228 | 228 | } |
| 229 | 229 | |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | # |
| 269 | 269 | # Call the HTML-in-Markdown hasher. |
| 270 | 270 | # |
| 271 | - list($text, ) = $this->_hashHTMLBlocks_inMarkdown($text); |
|
| 271 | + list($text,) = $this->_hashHTMLBlocks_inMarkdown($text); |
|
| 272 | 272 | |
| 273 | 273 | return $text; |
| 274 | 274 | } |
@@ -337,18 +337,18 @@ discard block |
||
| 337 | 337 | <\?.*?\?> | <%.*?%> # Processing instruction |
| 338 | 338 | | |
| 339 | 339 | <!\[CDATA\[.*?\]\]> # CData Block |
| 340 | - '. ( !$span ? ' # If not in span. |
|
| 340 | + '. (!$span ? ' # If not in span. |
|
| 341 | 341 | | |
| 342 | 342 | # Indented code block |
| 343 | 343 | (?: ^[ ]*\n | ^ | \n[ ]*\n ) |
| 344 | - [ ]{'.($indent+4).'}[^\n]* \n |
|
| 344 | + [ ]{'.($indent + 4).'}[^\n]* \n |
|
| 345 | 345 | (?> |
| 346 | - (?: [ ]{'.($indent+4).'}[^\n]* | [ ]* ) \n |
|
| 346 | + (?: [ ]{'.($indent + 4).'}[^\n]* | [ ]* ) \n |
|
| 347 | 347 | )* |
| 348 | 348 | | |
| 349 | 349 | # Fenced code block marker |
| 350 | 350 | (?<= ^ | \n ) |
| 351 | - [ ]{0,'.($indent+3).'}(?:~{3,}|`{3,}) |
|
| 351 | + [ ]{0,'.($indent + 3).'}(?:~{3,}|`{3,}) |
|
| 352 | 352 | [ ]* |
| 353 | 353 | (?: |
| 354 | 354 | \.?[-_:a-zA-Z0-9]+ # standalone class name |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | )? |
| 358 | 358 | [ ]* |
| 359 | 359 | (?= \n ) |
| 360 | - ' : '' ). ' # End (if not is span). |
|
| 360 | + ' : '').' # End (if not is span). |
|
| 361 | 361 | | |
| 362 | 362 | # Code span marker |
| 363 | 363 | # Note, this regex needs to go after backtick fenced |
@@ -368,8 +368,8 @@ discard block |
||
| 368 | 368 | }xs'; |
| 369 | 369 | |
| 370 | 370 | |
| 371 | - $depth = 0; # Current depth inside the tag tree. |
|
| 372 | - $parsed = ""; # Parsed text that will be returned. |
|
| 371 | + $depth = 0; # Current depth inside the tag tree. |
|
| 372 | + $parsed = ""; # Parsed text that will be returned. |
|
| 373 | 373 | |
| 374 | 374 | # |
| 375 | 375 | # Loop through every tag until we find the closing tag of the parent |
@@ -390,10 +390,10 @@ discard block |
||
| 390 | 390 | if ($span) { |
| 391 | 391 | $void = $this->hashPart("", ':'); |
| 392 | 392 | $newline = "$void\n"; |
| 393 | - $parts[0] = $void . str_replace("\n", $newline, $parts[0]) . $void; |
|
| 393 | + $parts[ 0 ] = $void.str_replace("\n", $newline, $parts[ 0 ]).$void; |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - $parsed .= $parts[0]; # Text before current tag. |
|
| 396 | + $parsed .= $parts[ 0 ]; # Text before current tag. |
|
| 397 | 397 | |
| 398 | 398 | # If end of $text has been reached. Stop loop. |
| 399 | 399 | if (count($parts) < 3) { |
@@ -401,8 +401,8 @@ discard block |
||
| 401 | 401 | break; |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | - $tag = $parts[1]; # Tag to handle. |
|
| 405 | - $text = $parts[2]; # Remaining text after current tag. |
|
| 404 | + $tag = $parts[ 1 ]; # Tag to handle. |
|
| 405 | + $text = $parts[ 2 ]; # Remaining text after current tag. |
|
| 406 | 406 | $tag_re = preg_quote($tag); # For use in a regular expression. |
| 407 | 407 | |
| 408 | 408 | # |
@@ -410,16 +410,16 @@ discard block |
||
| 410 | 410 | # Note: need to recheck the whole tag to disambiguate backtick |
| 411 | 411 | # fences from code spans |
| 412 | 412 | # |
| 413 | - if (preg_match('{^\n?([ ]{0,'.($indent+3).'})(~{3,}|`{3,})[ ]*(?:\.?[-_:a-zA-Z0-9]+|'.$this->id_class_attr_nocatch_re.')?[ ]*\n?$}', $tag, $capture)) { |
|
| 413 | + if (preg_match('{^\n?([ ]{0,'.($indent + 3).'})(~{3,}|`{3,})[ ]*(?:\.?[-_:a-zA-Z0-9]+|'.$this->id_class_attr_nocatch_re.')?[ ]*\n?$}', $tag, $capture)) { |
|
| 414 | 414 | # Fenced code block marker: find matching end marker. |
| 415 | - $fence_indent = strlen($capture[1]); # use captured indent in re |
|
| 416 | - $fence_re = $capture[2]; # use captured fence in re |
|
| 415 | + $fence_indent = strlen($capture[ 1 ]); # use captured indent in re |
|
| 416 | + $fence_re = $capture[ 2 ]; # use captured fence in re |
|
| 417 | 417 | if (preg_match('{^(?>.*\n)*?[ ]{'.($fence_indent).'}'.$fence_re.'[ ]*(?:\n|$)}', $text, |
| 418 | 418 | $matches)) |
| 419 | 419 | { |
| 420 | 420 | # End marker found: pass text unchanged until marker. |
| 421 | - $parsed .= $tag . $matches[0]; |
|
| 422 | - $text = substr($text, strlen($matches[0])); |
|
| 421 | + $parsed .= $tag.$matches[ 0 ]; |
|
| 422 | + $text = substr($text, strlen($matches[ 0 ])); |
|
| 423 | 423 | } |
| 424 | 424 | else { |
| 425 | 425 | # No end marker: just skip it. |
@@ -445,8 +445,8 @@ discard block |
||
| 445 | 445 | $text, $matches)) |
| 446 | 446 | { |
| 447 | 447 | # End marker found: pass text unchanged until marker. |
| 448 | - $parsed .= $tag . $matches[0]; |
|
| 449 | - $text = substr($text, strlen($matches[0])); |
|
| 448 | + $parsed .= $tag.$matches[ 0 ]; |
|
| 449 | + $text = substr($text, strlen($matches[ 0 ])); |
|
| 450 | 450 | } |
| 451 | 451 | else { |
| 452 | 452 | # Unmatched marker: just skip it. |
@@ -459,14 +459,14 @@ discard block |
||
| 459 | 459 | # used as a block tag (tag is alone on it's line). |
| 460 | 460 | # |
| 461 | 461 | else if (preg_match('{^<(?:'.$this->block_tags_re.')\b}', $tag) || |
| 462 | - ( preg_match('{^<(?:'.$this->context_block_tags_re.')\b}', $tag) && |
|
| 462 | + (preg_match('{^<(?:'.$this->context_block_tags_re.')\b}', $tag) && |
|
| 463 | 463 | preg_match($newline_before_re, $parsed) && |
| 464 | - preg_match($newline_after_re, $text) ) |
|
| 464 | + preg_match($newline_after_re, $text)) |
|
| 465 | 465 | ) |
| 466 | 466 | { |
| 467 | 467 | # Need to parse tag and following text using the HTML parser. |
| 468 | 468 | list($block_text, $text) = |
| 469 | - $this->_hashHTMLBlocks_inHTML($tag . $text, "hashBlock", true); |
|
| 469 | + $this->_hashHTMLBlocks_inHTML($tag.$text, "hashBlock", true); |
|
| 470 | 470 | |
| 471 | 471 | # Make sure it stays outside of any paragraph by adding newlines. |
| 472 | 472 | $parsed .= "\n\n$block_text\n\n"; |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | # Need to parse tag and following text using the HTML parser. |
| 482 | 482 | # (don't check for markdown attribute) |
| 483 | 483 | list($block_text, $text) = |
| 484 | - $this->_hashHTMLBlocks_inHTML($tag . $text, "hashClean", false); |
|
| 484 | + $this->_hashHTMLBlocks_inHTML($tag.$text, "hashClean", false); |
|
| 485 | 485 | |
| 486 | 486 | $parsed .= $block_text; |
| 487 | 487 | } |
@@ -496,14 +496,14 @@ discard block |
||
| 496 | 496 | # Increase/decrease nested tag count. |
| 497 | 497 | # |
| 498 | 498 | if ($tag{1} == '/') $depth--; |
| 499 | - else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
| 499 | + else if ($tag{strlen($tag) - 2} != '/') $depth++; |
|
| 500 | 500 | |
| 501 | 501 | if ($depth < 0) { |
| 502 | 502 | # |
| 503 | 503 | # Going out of parent element. Clean up and break so we |
| 504 | 504 | # return to the calling function. |
| 505 | 505 | # |
| 506 | - $text = $tag . $text; |
|
| 506 | + $text = $tag.$text; |
|
| 507 | 507 | break; |
| 508 | 508 | } |
| 509 | 509 | |
@@ -568,18 +568,18 @@ discard block |
||
| 568 | 568 | ) |
| 569 | 569 | }xs'; |
| 570 | 570 | |
| 571 | - $original_text = $text; # Save original text in case of faliure. |
|
| 571 | + $original_text = $text; # Save original text in case of faliure. |
|
| 572 | 572 | |
| 573 | - $depth = 0; # Current depth inside the tag tree. |
|
| 574 | - $block_text = ""; # Temporary text holder for current text. |
|
| 575 | - $parsed = ""; # Parsed text that will be returned. |
|
| 573 | + $depth = 0; # Current depth inside the tag tree. |
|
| 574 | + $block_text = ""; # Temporary text holder for current text. |
|
| 575 | + $parsed = ""; # Parsed text that will be returned. |
|
| 576 | 576 | |
| 577 | 577 | # |
| 578 | 578 | # Get the name of the starting tag. |
| 579 | 579 | # (This pattern makes $base_tag_name_re safe without quoting.) |
| 580 | 580 | # |
| 581 | 581 | if (preg_match('/^<([\w:$]*)\b/', $text, $matches)) |
| 582 | - $base_tag_name_re = $matches[1]; |
|
| 582 | + $base_tag_name_re = $matches[ 1 ]; |
|
| 583 | 583 | |
| 584 | 584 | # |
| 585 | 585 | # Loop through every tag until we find the corresponding closing tag. |
@@ -603,9 +603,9 @@ discard block |
||
| 603 | 603 | return array($original_text{0}, substr($original_text, 1)); |
| 604 | 604 | } |
| 605 | 605 | |
| 606 | - $block_text .= $parts[0]; # Text before current tag. |
|
| 607 | - $tag = $parts[1]; # Tag to handle. |
|
| 608 | - $text = $parts[2]; # Remaining text after current tag. |
|
| 606 | + $block_text .= $parts[ 0 ]; # Text before current tag. |
|
| 607 | + $tag = $parts[ 1 ]; # Tag to handle. |
|
| 608 | + $text = $parts[ 2 ]; # Remaining text after current tag. |
|
| 609 | 609 | |
| 610 | 610 | # |
| 611 | 611 | # Check for: Auto-close tag (like <hr/>) |
@@ -624,7 +624,7 @@ discard block |
||
| 624 | 624 | # |
| 625 | 625 | if (preg_match('{^</?'.$base_tag_name_re.'\b}', $tag)) { |
| 626 | 626 | if ($tag{1} == '/') $depth--; |
| 627 | - else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
| 627 | + else if ($tag{strlen($tag) - 2} != '/') $depth++; |
|
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | # |
@@ -632,20 +632,20 @@ discard block |
||
| 632 | 632 | # |
| 633 | 633 | if ($md_attr && |
| 634 | 634 | preg_match($markdown_attr_re, $tag, $attr_m) && |
| 635 | - preg_match('/^1|block|span$/', $attr_m[2] . $attr_m[3])) |
|
| 635 | + preg_match('/^1|block|span$/', $attr_m[ 2 ].$attr_m[ 3 ])) |
|
| 636 | 636 | { |
| 637 | 637 | # Remove `markdown` attribute from opening tag. |
| 638 | 638 | $tag = preg_replace($markdown_attr_re, '', $tag); |
| 639 | 639 | |
| 640 | 640 | # Check if text inside this tag must be parsed in span mode. |
| 641 | - $this->mode = $attr_m[2] . $attr_m[3]; |
|
| 641 | + $this->mode = $attr_m[ 2 ].$attr_m[ 3 ]; |
|
| 642 | 642 | $span_mode = $this->mode == 'span' || $this->mode != 'block' && |
| 643 | 643 | preg_match('{^<(?:'.$this->contain_span_tags_re.')\b}', $tag); |
| 644 | 644 | |
| 645 | 645 | # Calculate indent before tag. |
| 646 | 646 | if (preg_match('/(?:^|\n)( *?)(?! ).*?$/', $block_text, $matches)) { |
| 647 | 647 | $strlen = $this->utf8_strlen; |
| 648 | - $indent = $strlen($matches[1], 'UTF-8'); |
|
| 648 | + $indent = $strlen($matches[ 1 ], 'UTF-8'); |
|
| 649 | 649 | } else { |
| 650 | 650 | $indent = 0; |
| 651 | 651 | } |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | # Get enclosing tag name for the ParseMarkdown function. |
| 658 | 658 | # (This pattern makes $tag_name_re safe without quoting.) |
| 659 | 659 | preg_match('/^<([\w:$]*)\b/', $tag, $matches); |
| 660 | - $tag_name_re = $matches[1]; |
|
| 660 | + $tag_name_re = $matches[ 1 ]; |
|
| 661 | 661 | |
| 662 | 662 | # Parse the content using the HTML-in-Markdown parser. |
| 663 | 663 | list ($block_text, $text) |
@@ -773,9 +773,9 @@ discard block |
||
| 773 | 773 | return $text; |
| 774 | 774 | } |
| 775 | 775 | protected function _doAnchors_reference_callback($matches) { |
| 776 | - $whole_match = $matches[1]; |
|
| 777 | - $link_text = $matches[2]; |
|
| 778 | - $link_id =& $matches[3]; |
|
| 776 | + $whole_match = $matches[ 1 ]; |
|
| 777 | + $link_text = $matches[ 2 ]; |
|
| 778 | + $link_id = & $matches[ 3 ]; |
|
| 779 | 779 | |
| 780 | 780 | if ($link_id == "") { |
| 781 | 781 | # for shortcut links like [this][] or [this]. |
@@ -786,18 +786,18 @@ discard block |
||
| 786 | 786 | $link_id = strtolower($link_id); |
| 787 | 787 | $link_id = preg_replace('{[ ]?\n}', ' ', $link_id); |
| 788 | 788 | |
| 789 | - if (isset($this->urls[$link_id])) { |
|
| 790 | - $url = $this->urls[$link_id]; |
|
| 789 | + if (isset($this->urls[ $link_id ])) { |
|
| 790 | + $url = $this->urls[ $link_id ]; |
|
| 791 | 791 | $url = $this->encodeURLAttribute($url); |
| 792 | 792 | |
| 793 | 793 | $result = "<a href=\"$url\""; |
| 794 | - if ( isset( $this->titles[$link_id] ) ) { |
|
| 795 | - $title = $this->titles[$link_id]; |
|
| 794 | + if (isset($this->titles[ $link_id ])) { |
|
| 795 | + $title = $this->titles[ $link_id ]; |
|
| 796 | 796 | $title = $this->encodeAttribute($title); |
| 797 | - $result .= " title=\"$title\""; |
|
| 797 | + $result .= " title=\"$title\""; |
|
| 798 | 798 | } |
| 799 | - if (isset($this->ref_attr[$link_id])) |
|
| 800 | - $result .= $this->ref_attr[$link_id]; |
|
| 799 | + if (isset($this->ref_attr[ $link_id ])) |
|
| 800 | + $result .= $this->ref_attr[ $link_id ]; |
|
| 801 | 801 | |
| 802 | 802 | $link_text = $this->runSpanGamut($link_text); |
| 803 | 803 | $result .= ">$link_text</a>"; |
@@ -809,11 +809,11 @@ discard block |
||
| 809 | 809 | return $result; |
| 810 | 810 | } |
| 811 | 811 | protected function _doAnchors_inline_callback($matches) { |
| 812 | - $whole_match = $matches[1]; |
|
| 813 | - $link_text = $this->runSpanGamut($matches[2]); |
|
| 814 | - $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 815 | - $title =& $matches[7]; |
|
| 816 | - $attr = $this->doExtraAttributes("a", $dummy =& $matches[8]); |
|
| 812 | + $whole_match = $matches[ 1 ]; |
|
| 813 | + $link_text = $this->runSpanGamut($matches[ 2 ]); |
|
| 814 | + $url = $matches[ 3 ] == '' ? $matches[ 4 ] : $matches[ 3 ]; |
|
| 815 | + $title = & $matches[ 7 ]; |
|
| 816 | + $attr = $this->doExtraAttributes("a", $dummy = & $matches[ 8 ]); |
|
| 817 | 817 | |
| 818 | 818 | // if the URL was of the form <s p a c e s> it got caught by the HTML |
| 819 | 819 | // tag parser and hashed. Need to reverse the process before using the URL. |
@@ -826,7 +826,7 @@ discard block |
||
| 826 | 826 | $result = "<a href=\"$url\""; |
| 827 | 827 | if (isset($title)) { |
| 828 | 828 | $title = $this->encodeAttribute($title); |
| 829 | - $result .= " title=\"$title\""; |
|
| 829 | + $result .= " title=\"$title\""; |
|
| 830 | 830 | } |
| 831 | 831 | $result .= $attr; |
| 832 | 832 | |
@@ -894,25 +894,25 @@ discard block |
||
| 894 | 894 | return $text; |
| 895 | 895 | } |
| 896 | 896 | protected function _doImages_reference_callback($matches) { |
| 897 | - $whole_match = $matches[1]; |
|
| 898 | - $alt_text = $matches[2]; |
|
| 899 | - $link_id = strtolower($matches[3]); |
|
| 897 | + $whole_match = $matches[ 1 ]; |
|
| 898 | + $alt_text = $matches[ 2 ]; |
|
| 899 | + $link_id = strtolower($matches[ 3 ]); |
|
| 900 | 900 | |
| 901 | 901 | if ($link_id == "") { |
| 902 | 902 | $link_id = strtolower($alt_text); # for shortcut links like ![this][]. |
| 903 | 903 | } |
| 904 | 904 | |
| 905 | 905 | $alt_text = $this->encodeAttribute($alt_text); |
| 906 | - if (isset($this->urls[$link_id])) { |
|
| 907 | - $url = $this->encodeURLAttribute($this->urls[$link_id]); |
|
| 906 | + if (isset($this->urls[ $link_id ])) { |
|
| 907 | + $url = $this->encodeURLAttribute($this->urls[ $link_id ]); |
|
| 908 | 908 | $result = "<img src=\"$url\" alt=\"$alt_text\""; |
| 909 | - if (isset($this->titles[$link_id])) { |
|
| 910 | - $title = $this->titles[$link_id]; |
|
| 909 | + if (isset($this->titles[ $link_id ])) { |
|
| 910 | + $title = $this->titles[ $link_id ]; |
|
| 911 | 911 | $title = $this->encodeAttribute($title); |
| 912 | - $result .= " title=\"$title\""; |
|
| 912 | + $result .= " title=\"$title\""; |
|
| 913 | 913 | } |
| 914 | - if (isset($this->ref_attr[$link_id])) |
|
| 915 | - $result .= $this->ref_attr[$link_id]; |
|
| 914 | + if (isset($this->ref_attr[ $link_id ])) |
|
| 915 | + $result .= $this->ref_attr[ $link_id ]; |
|
| 916 | 916 | $result .= $this->empty_element_suffix; |
| 917 | 917 | $result = $this->hashPart($result); |
| 918 | 918 | } |
@@ -924,18 +924,18 @@ discard block |
||
| 924 | 924 | return $result; |
| 925 | 925 | } |
| 926 | 926 | protected function _doImages_inline_callback($matches) { |
| 927 | - $whole_match = $matches[1]; |
|
| 928 | - $alt_text = $matches[2]; |
|
| 929 | - $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 930 | - $title =& $matches[7]; |
|
| 931 | - $attr = $this->doExtraAttributes("img", $dummy =& $matches[8]); |
|
| 927 | + $whole_match = $matches[ 1 ]; |
|
| 928 | + $alt_text = $matches[ 2 ]; |
|
| 929 | + $url = $matches[ 3 ] == '' ? $matches[ 4 ] : $matches[ 3 ]; |
|
| 930 | + $title = & $matches[ 7 ]; |
|
| 931 | + $attr = $this->doExtraAttributes("img", $dummy = & $matches[ 8 ]); |
|
| 932 | 932 | |
| 933 | 933 | $alt_text = $this->encodeAttribute($alt_text); |
| 934 | 934 | $url = $this->encodeURLAttribute($url); |
| 935 | 935 | $result = "<img src=\"$url\" alt=\"$alt_text\""; |
| 936 | 936 | if (isset($title)) { |
| 937 | 937 | $title = $this->encodeAttribute($title); |
| 938 | - $result .= " title=\"$title\""; # $title already quoted |
|
| 938 | + $result .= " title=\"$title\""; # $title already quoted |
|
| 939 | 939 | } |
| 940 | 940 | $result .= $attr; |
| 941 | 941 | $result .= $this->empty_element_suffix; |
@@ -985,24 +985,24 @@ discard block |
||
| 985 | 985 | return $text; |
| 986 | 986 | } |
| 987 | 987 | protected function _doHeaders_callback_setext($matches) { |
| 988 | - if ($matches[3] == '-' && preg_match('{^- }', $matches[1])) |
|
| 989 | - return $matches[0]; |
|
| 988 | + if ($matches[ 3 ] == '-' && preg_match('{^- }', $matches[ 1 ])) |
|
| 989 | + return $matches[ 0 ]; |
|
| 990 | 990 | |
| 991 | - $level = $matches[3]{0} == '=' ? 1 : 2; |
|
| 991 | + $level = $matches[ 3 ]{0} == '=' ? 1 : 2; |
|
| 992 | 992 | |
| 993 | - $defaultId = is_callable($this->header_id_func) ? call_user_func($this->header_id_func, $matches[1]) : null; |
|
| 993 | + $defaultId = is_callable($this->header_id_func) ? call_user_func($this->header_id_func, $matches[ 1 ]) : null; |
|
| 994 | 994 | |
| 995 | - $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[2], $defaultId); |
|
| 996 | - $block = "<h$level$attr>".$this->runSpanGamut($matches[1])."</h$level>"; |
|
| 997 | - return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 995 | + $attr = $this->doExtraAttributes("h$level", $dummy = & $matches[ 2 ], $defaultId); |
|
| 996 | + $block = "<h$level$attr>".$this->runSpanGamut($matches[ 1 ])."</h$level>"; |
|
| 997 | + return "\n".$this->hashBlock($block)."\n\n"; |
|
| 998 | 998 | } |
| 999 | 999 | protected function _doHeaders_callback_atx($matches) { |
| 1000 | - $level = strlen($matches[1]); |
|
| 1000 | + $level = strlen($matches[ 1 ]); |
|
| 1001 | 1001 | |
| 1002 | - $defaultId = is_callable($this->header_id_func) ? call_user_func($this->header_id_func, $matches[2]) : null; |
|
| 1003 | - $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[3], $defaultId); |
|
| 1004 | - $block = "<h$level$attr>".$this->runSpanGamut($matches[2])."</h$level>"; |
|
| 1005 | - return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 1002 | + $defaultId = is_callable($this->header_id_func) ? call_user_func($this->header_id_func, $matches[ 2 ]) : null; |
|
| 1003 | + $attr = $this->doExtraAttributes("h$level", $dummy = & $matches[ 3 ], $defaultId); |
|
| 1004 | + $block = "<h$level$attr>".$this->runSpanGamut($matches[ 2 ])."</h$level>"; |
|
| 1005 | + return "\n".$this->hashBlock($block)."\n\n"; |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | |
@@ -1068,14 +1068,14 @@ discard block |
||
| 1068 | 1068 | return $text; |
| 1069 | 1069 | } |
| 1070 | 1070 | protected function _doTable_leadingPipe_callback($matches) { |
| 1071 | - $head = $matches[1]; |
|
| 1072 | - $underline = $matches[2]; |
|
| 1073 | - $content = $matches[3]; |
|
| 1071 | + $head = $matches[ 1 ]; |
|
| 1072 | + $underline = $matches[ 2 ]; |
|
| 1073 | + $content = $matches[ 3 ]; |
|
| 1074 | 1074 | |
| 1075 | 1075 | # Remove leading pipe for each row. |
| 1076 | 1076 | $content = preg_replace('/^ *[|]/m', '', $content); |
| 1077 | 1077 | |
| 1078 | - return $this->_doTable_callback(array($matches[0], $head, $underline, $content)); |
|
| 1078 | + return $this->_doTable_callback(array($matches[ 0 ], $head, $underline, $content)); |
|
| 1079 | 1079 | } |
| 1080 | 1080 | protected function _doTable_makeAlignAttr($alignname) |
| 1081 | 1081 | { |
@@ -1086,41 +1086,41 @@ discard block |
||
| 1086 | 1086 | return " class=\"$classname\""; |
| 1087 | 1087 | } |
| 1088 | 1088 | protected function _doTable_callback($matches) { |
| 1089 | - $head = $matches[1]; |
|
| 1090 | - $underline = $matches[2]; |
|
| 1091 | - $content = $matches[3]; |
|
| 1089 | + $head = $matches[ 1 ]; |
|
| 1090 | + $underline = $matches[ 2 ]; |
|
| 1091 | + $content = $matches[ 3 ]; |
|
| 1092 | 1092 | |
| 1093 | 1093 | # Remove any tailing pipes for each line. |
| 1094 | - $head = preg_replace('/[|] *$/m', '', $head); |
|
| 1095 | - $underline = preg_replace('/[|] *$/m', '', $underline); |
|
| 1096 | - $content = preg_replace('/[|] *$/m', '', $content); |
|
| 1094 | + $head = preg_replace('/[|] *$/m', '', $head); |
|
| 1095 | + $underline = preg_replace('/[|] *$/m', '', $underline); |
|
| 1096 | + $content = preg_replace('/[|] *$/m', '', $content); |
|
| 1097 | 1097 | |
| 1098 | 1098 | # Reading alignement from header underline. |
| 1099 | 1099 | $separators = preg_split('/ *[|] */', $underline); |
| 1100 | 1100 | foreach ($separators as $n => $s) { |
| 1101 | 1101 | if (preg_match('/^ *-+: *$/', $s)) |
| 1102 | - $attr[$n] = $this->_doTable_makeAlignAttr('right'); |
|
| 1102 | + $attr[ $n ] = $this->_doTable_makeAlignAttr('right'); |
|
| 1103 | 1103 | else if (preg_match('/^ *:-+: *$/', $s)) |
| 1104 | - $attr[$n] = $this->_doTable_makeAlignAttr('center'); |
|
| 1104 | + $attr[ $n ] = $this->_doTable_makeAlignAttr('center'); |
|
| 1105 | 1105 | else if (preg_match('/^ *:-+ *$/', $s)) |
| 1106 | - $attr[$n] = $this->_doTable_makeAlignAttr('left'); |
|
| 1106 | + $attr[ $n ] = $this->_doTable_makeAlignAttr('left'); |
|
| 1107 | 1107 | else |
| 1108 | - $attr[$n] = ''; |
|
| 1108 | + $attr[ $n ] = ''; |
|
| 1109 | 1109 | } |
| 1110 | 1110 | |
| 1111 | 1111 | # Parsing span elements, including code spans, character escapes, |
| 1112 | 1112 | # and inline HTML tags, so that pipes inside those gets ignored. |
| 1113 | - $head = $this->parseSpan($head); |
|
| 1114 | - $headers = preg_split('/ *[|] */', $head); |
|
| 1115 | - $col_count = count($headers); |
|
| 1116 | - $attr = array_pad($attr, $col_count, ''); |
|
| 1113 | + $head = $this->parseSpan($head); |
|
| 1114 | + $headers = preg_split('/ *[|] */', $head); |
|
| 1115 | + $col_count = count($headers); |
|
| 1116 | + $attr = array_pad($attr, $col_count, ''); |
|
| 1117 | 1117 | |
| 1118 | 1118 | # Write column headers. |
| 1119 | 1119 | $text = "<table>\n"; |
| 1120 | 1120 | $text .= "<thead>\n"; |
| 1121 | 1121 | $text .= "<tr>\n"; |
| 1122 | 1122 | foreach ($headers as $n => $header) |
| 1123 | - $text .= " <th$attr[$n]>".$this->runSpanGamut(trim($header))."</th>\n"; |
|
| 1123 | + $text .= " <th$attr[ $n ]>".$this->runSpanGamut(trim($header))."</th>\n"; |
|
| 1124 | 1124 | $text .= "</tr>\n"; |
| 1125 | 1125 | $text .= "</thead>\n"; |
| 1126 | 1126 | |
@@ -1139,13 +1139,13 @@ discard block |
||
| 1139 | 1139 | |
| 1140 | 1140 | $text .= "<tr>\n"; |
| 1141 | 1141 | foreach ($row_cells as $n => $cell) |
| 1142 | - $text .= " <td$attr[$n]>".$this->runSpanGamut(trim($cell))."</td>\n"; |
|
| 1142 | + $text .= " <td$attr[ $n ]>".$this->runSpanGamut(trim($cell))."</td>\n"; |
|
| 1143 | 1143 | $text .= "</tr>\n"; |
| 1144 | 1144 | } |
| 1145 | 1145 | $text .= "</tbody>\n"; |
| 1146 | 1146 | $text .= "</table>"; |
| 1147 | 1147 | |
| 1148 | - return $this->hashBlock($text) . "\n"; |
|
| 1148 | + return $this->hashBlock($text)."\n"; |
|
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | 1151 | |
@@ -1193,13 +1193,13 @@ discard block |
||
| 1193 | 1193 | } |
| 1194 | 1194 | protected function _doDefLists_callback($matches) { |
| 1195 | 1195 | # Re-usable patterns to match list item bullets and number markers: |
| 1196 | - $list = $matches[1]; |
|
| 1196 | + $list = $matches[ 1 ]; |
|
| 1197 | 1197 | |
| 1198 | 1198 | # Turn double returns into triple returns, so that we can make a |
| 1199 | 1199 | # paragraph for the last item in a list, if necessary: |
| 1200 | 1200 | $result = trim($this->processDefListItems($list)); |
| 1201 | - $result = "<dl>\n" . $result . "\n</dl>"; |
|
| 1202 | - return $this->hashBlock($result) . "\n\n"; |
|
| 1201 | + $result = "<dl>\n".$result."\n</dl>"; |
|
| 1202 | + return $this->hashBlock($result)."\n\n"; |
|
| 1203 | 1203 | } |
| 1204 | 1204 | |
| 1205 | 1205 | |
@@ -1247,31 +1247,31 @@ discard block |
||
| 1247 | 1247 | return $list_str; |
| 1248 | 1248 | } |
| 1249 | 1249 | protected function _processDefListItems_callback_dt($matches) { |
| 1250 | - $terms = explode("\n", trim($matches[1])); |
|
| 1250 | + $terms = explode("\n", trim($matches[ 1 ])); |
|
| 1251 | 1251 | $text = ''; |
| 1252 | 1252 | foreach ($terms as $term) { |
| 1253 | 1253 | $term = $this->runSpanGamut(trim($term)); |
| 1254 | - $text .= "\n<dt>" . $term . "</dt>"; |
|
| 1254 | + $text .= "\n<dt>".$term."</dt>"; |
|
| 1255 | 1255 | } |
| 1256 | - return $text . "\n"; |
|
| 1256 | + return $text."\n"; |
|
| 1257 | 1257 | } |
| 1258 | 1258 | protected function _processDefListItems_callback_dd($matches) { |
| 1259 | - $leading_line = $matches[1]; |
|
| 1260 | - $marker_space = $matches[2]; |
|
| 1261 | - $def = $matches[3]; |
|
| 1259 | + $leading_line = $matches[ 1 ]; |
|
| 1260 | + $marker_space = $matches[ 2 ]; |
|
| 1261 | + $def = $matches[ 3 ]; |
|
| 1262 | 1262 | |
| 1263 | 1263 | if ($leading_line || preg_match('/\n{2,}/', $def)) { |
| 1264 | 1264 | # Replace marker with the appropriate whitespace indentation |
| 1265 | - $def = str_repeat(' ', strlen($marker_space)) . $def; |
|
| 1266 | - $def = $this->runBlockGamut($this->outdent($def . "\n\n")); |
|
| 1267 | - $def = "\n". $def ."\n"; |
|
| 1265 | + $def = str_repeat(' ', strlen($marker_space)).$def; |
|
| 1266 | + $def = $this->runBlockGamut($this->outdent($def."\n\n")); |
|
| 1267 | + $def = "\n".$def."\n"; |
|
| 1268 | 1268 | } |
| 1269 | 1269 | else { |
| 1270 | 1270 | $def = rtrim($def); |
| 1271 | 1271 | $def = $this->runSpanGamut($this->outdent($def)); |
| 1272 | 1272 | } |
| 1273 | 1273 | |
| 1274 | - return "\n<dd>" . $def . "</dd>\n"; |
|
| 1274 | + return "\n<dd>".$def."</dd>\n"; |
|
| 1275 | 1275 | } |
| 1276 | 1276 | |
| 1277 | 1277 | |
@@ -1315,9 +1315,9 @@ discard block |
||
| 1315 | 1315 | return $text; |
| 1316 | 1316 | } |
| 1317 | 1317 | protected function _doFencedCodeBlocks_callback($matches) { |
| 1318 | - $classname =& $matches[2]; |
|
| 1319 | - $attrs =& $matches[3]; |
|
| 1320 | - $codeblock = $matches[4]; |
|
| 1318 | + $classname = & $matches[ 2 ]; |
|
| 1319 | + $attrs = & $matches[ 3 ]; |
|
| 1320 | + $codeblock = $matches[ 4 ]; |
|
| 1321 | 1321 | $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); |
| 1322 | 1322 | $codeblock = preg_replace_callback('/^\n+/', |
| 1323 | 1323 | array($this, '_doFencedCodeBlocks_newlines'), $codeblock); |
@@ -1331,13 +1331,13 @@ discard block |
||
| 1331 | 1331 | } |
| 1332 | 1332 | $pre_attr_str = $this->code_attr_on_pre ? $attr_str : ''; |
| 1333 | 1333 | $code_attr_str = $this->code_attr_on_pre ? '' : $attr_str; |
| 1334 | - $codeblock = "<pre$pre_attr_str><code$code_attr_str>$codeblock</code></pre>"; |
|
| 1334 | + $codeblock = "<pre$pre_attr_str><code$code_attr_str>$codeblock</code></pre>"; |
|
| 1335 | 1335 | |
| 1336 | 1336 | return "\n\n".$this->hashBlock($codeblock)."\n\n"; |
| 1337 | 1337 | } |
| 1338 | 1338 | protected function _doFencedCodeBlocks_newlines($matches) { |
| 1339 | 1339 | return str_repeat("<br$this->empty_element_suffix", |
| 1340 | - strlen($matches[0])); |
|
| 1340 | + strlen($matches[ 0 ])); |
|
| 1341 | 1341 | } |
| 1342 | 1342 | |
| 1343 | 1343 | |
@@ -1385,7 +1385,7 @@ discard block |
||
| 1385 | 1385 | if ($is_p) { |
| 1386 | 1386 | $value = "<p>$value</p>"; |
| 1387 | 1387 | } |
| 1388 | - $grafs[$key] = $value; |
|
| 1388 | + $grafs[ $key ] = $value; |
|
| 1389 | 1389 | } |
| 1390 | 1390 | |
| 1391 | 1391 | # Join grafs in one text, then unhash HTML tags. |
@@ -1428,8 +1428,8 @@ discard block |
||
| 1428 | 1428 | return $text; |
| 1429 | 1429 | } |
| 1430 | 1430 | protected function _stripFootnotes_callback($matches) { |
| 1431 | - $note_id = $this->fn_id_prefix . $matches[1]; |
|
| 1432 | - $this->footnotes[$note_id] = $this->outdent($matches[2]); |
|
| 1431 | + $note_id = $this->fn_id_prefix.$matches[ 1 ]; |
|
| 1432 | + $this->footnotes[ $note_id ] = $this->outdent($matches[ 2 ]); |
|
| 1433 | 1433 | return ''; # String that will replace the block |
| 1434 | 1434 | } |
| 1435 | 1435 | |
@@ -1456,7 +1456,7 @@ discard block |
||
| 1456 | 1456 | if (!empty($this->footnotes_ordered)) { |
| 1457 | 1457 | $text .= "\n\n"; |
| 1458 | 1458 | $text .= "<div class=\"footnotes\">\n"; |
| 1459 | - $text .= "<hr". $this->empty_element_suffix ."\n"; |
|
| 1459 | + $text .= "<hr".$this->empty_element_suffix."\n"; |
|
| 1460 | 1460 | $text .= "<ol>\n\n"; |
| 1461 | 1461 | |
| 1462 | 1462 | $attr = ""; |
@@ -1475,10 +1475,10 @@ discard block |
||
| 1475 | 1475 | while (!empty($this->footnotes_ordered)) { |
| 1476 | 1476 | $footnote = reset($this->footnotes_ordered); |
| 1477 | 1477 | $note_id = key($this->footnotes_ordered); |
| 1478 | - unset($this->footnotes_ordered[$note_id]); |
|
| 1479 | - $ref_count = $this->footnotes_ref_count[$note_id]; |
|
| 1480 | - unset($this->footnotes_ref_count[$note_id]); |
|
| 1481 | - unset($this->footnotes[$note_id]); |
|
| 1478 | + unset($this->footnotes_ordered[ $note_id ]); |
|
| 1479 | + $ref_count = $this->footnotes_ref_count[ $note_id ]; |
|
| 1480 | + unset($this->footnotes_ref_count[ $note_id ]); |
|
| 1481 | + unset($this->footnotes[ $note_id ]); |
|
| 1482 | 1482 | |
| 1483 | 1483 | $footnote .= "\n"; # Need to append newline before parsing. |
| 1484 | 1484 | $footnote = $this->runBlockGamut("$footnote\n"); |
@@ -1495,13 +1495,13 @@ discard block |
||
| 1495 | 1495 | } |
| 1496 | 1496 | # Add backlink to last paragraph; create new paragraph if needed. |
| 1497 | 1497 | if (preg_match('{</p>$}', $footnote)) { |
| 1498 | - $footnote = substr($footnote, 0, -4) . " $backlink</p>"; |
|
| 1498 | + $footnote = substr($footnote, 0, -4)." $backlink</p>"; |
|
| 1499 | 1499 | } else { |
| 1500 | 1500 | $footnote .= "\n\n<p>$backlink</p>"; |
| 1501 | 1501 | } |
| 1502 | 1502 | |
| 1503 | 1503 | $text .= "<li id=\"fn:$note_id\">\n"; |
| 1504 | - $text .= $footnote . "\n"; |
|
| 1504 | + $text .= $footnote."\n"; |
|
| 1505 | 1505 | $text .= "</li>\n\n"; |
| 1506 | 1506 | } |
| 1507 | 1507 | |
@@ -1511,21 +1511,21 @@ discard block |
||
| 1511 | 1511 | return $text; |
| 1512 | 1512 | } |
| 1513 | 1513 | protected function _appendFootnotes_callback($matches) { |
| 1514 | - $node_id = $this->fn_id_prefix . $matches[1]; |
|
| 1514 | + $node_id = $this->fn_id_prefix.$matches[ 1 ]; |
|
| 1515 | 1515 | |
| 1516 | 1516 | # Create footnote marker only if it has a corresponding footnote *and* |
| 1517 | 1517 | # the footnote hasn't been used by another marker. |
| 1518 | - if (isset($this->footnotes[$node_id])) { |
|
| 1519 | - $num =& $this->footnotes_numbers[$node_id]; |
|
| 1518 | + if (isset($this->footnotes[ $node_id ])) { |
|
| 1519 | + $num = & $this->footnotes_numbers[ $node_id ]; |
|
| 1520 | 1520 | if (!isset($num)) { |
| 1521 | 1521 | # Transfer footnote content to the ordered list and give it its |
| 1522 | 1522 | # number |
| 1523 | - $this->footnotes_ordered[$node_id] = $this->footnotes[$node_id]; |
|
| 1524 | - $this->footnotes_ref_count[$node_id] = 1; |
|
| 1523 | + $this->footnotes_ordered[ $node_id ] = $this->footnotes[ $node_id ]; |
|
| 1524 | + $this->footnotes_ref_count[ $node_id ] = 1; |
|
| 1525 | 1525 | $num = $this->footnote_counter++; |
| 1526 | 1526 | $ref_count_mark = ''; |
| 1527 | 1527 | } else { |
| 1528 | - $ref_count_mark = $this->footnotes_ref_count[$node_id] += 1; |
|
| 1528 | + $ref_count_mark = $this->footnotes_ref_count[ $node_id ] += 1; |
|
| 1529 | 1529 | } |
| 1530 | 1530 | |
| 1531 | 1531 | $attr = ""; |
@@ -1549,7 +1549,7 @@ discard block |
||
| 1549 | 1549 | "</sup>"; |
| 1550 | 1550 | } |
| 1551 | 1551 | |
| 1552 | - return "[^".$matches[1]."]"; |
|
| 1552 | + return "[^".$matches[ 1 ]."]"; |
|
| 1553 | 1553 | } |
| 1554 | 1554 | |
| 1555 | 1555 | |
@@ -1571,12 +1571,12 @@ discard block |
||
| 1571 | 1571 | return $text; |
| 1572 | 1572 | } |
| 1573 | 1573 | protected function _stripAbbreviations_callback($matches) { |
| 1574 | - $abbr_word = $matches[1]; |
|
| 1575 | - $abbr_desc = $matches[2]; |
|
| 1574 | + $abbr_word = $matches[ 1 ]; |
|
| 1575 | + $abbr_desc = $matches[ 2 ]; |
|
| 1576 | 1576 | if ($this->abbr_word_re) |
| 1577 | 1577 | $this->abbr_word_re .= '|'; |
| 1578 | 1578 | $this->abbr_word_re .= preg_quote($abbr_word); |
| 1579 | - $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); |
|
| 1579 | + $this->abbr_desciptions[ $abbr_word ] = trim($abbr_desc); |
|
| 1580 | 1580 | return ''; # String that will replace the block |
| 1581 | 1581 | } |
| 1582 | 1582 | |
@@ -1598,9 +1598,9 @@ discard block |
||
| 1598 | 1598 | return $text; |
| 1599 | 1599 | } |
| 1600 | 1600 | protected function _doAbbreviations_callback($matches) { |
| 1601 | - $abbr = $matches[0]; |
|
| 1602 | - if (isset($this->abbr_desciptions[$abbr])) { |
|
| 1603 | - $desc = $this->abbr_desciptions[$abbr]; |
|
| 1601 | + $abbr = $matches[ 0 ]; |
|
| 1602 | + if (isset($this->abbr_desciptions[ $abbr ])) { |
|
| 1603 | + $desc = $this->abbr_desciptions[ $abbr ]; |
|
| 1604 | 1604 | if (empty($desc)) { |
| 1605 | 1605 | return $this->hashPart("<abbr>$abbr</abbr>"); |
| 1606 | 1606 | } else { |
@@ -1608,7 +1608,7 @@ discard block |
||
| 1608 | 1608 | return $this->hashPart("<abbr title=\"$desc\">$abbr</abbr>"); |
| 1609 | 1609 | } |
| 1610 | 1610 | } else { |
| 1611 | - return $matches[0]; |
|
| 1611 | + return $matches[ 0 ]; |
|
| 1612 | 1612 | } |
| 1613 | 1613 | } |
| 1614 | 1614 | } |
@@ -106,8 +106,9 @@ discard block |
||
| 106 | 106 | $this->footnote_counter = 1; |
| 107 | 107 | |
| 108 | 108 | foreach ($this->predef_abbr as $abbr_word => $abbr_desc) { |
| 109 | - if ($this->abbr_word_re) |
|
| 110 | - $this->abbr_word_re .= '|'; |
|
| 109 | + if ($this->abbr_word_re) { |
|
| 110 | + $this->abbr_word_re .= '|'; |
|
| 111 | + } |
|
| 111 | 112 | $this->abbr_word_re .= preg_quote($abbr_word); |
| 112 | 113 | $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); |
| 113 | 114 | } |
@@ -145,7 +146,9 @@ discard block |
||
| 145 | 146 | # In addition, this method also supports supplying a default Id value, |
| 146 | 147 | # which will be used to populate the id attribute in case it was not |
| 147 | 148 | # overridden. |
| 148 | - if (empty($attr) && !$defaultIdValue) return ""; |
|
| 149 | + if (empty($attr) && !$defaultIdValue) { |
|
| 150 | + return ""; |
|
| 151 | + } |
|
| 149 | 152 | |
| 150 | 153 | # Split on components |
| 151 | 154 | preg_match_all('/[#.a-z][-_:a-zA-Z0-9=]+/', $attr, $matches); |
@@ -159,14 +162,18 @@ discard block |
||
| 159 | 162 | if ($element{0} == '.') { |
| 160 | 163 | $classes[] = substr($element, 1); |
| 161 | 164 | } else if ($element{0} == '#') { |
| 162 | - if ($id === false) $id = substr($element, 1); |
|
| 165 | + if ($id === false) { |
|
| 166 | + $id = substr($element, 1); |
|
| 167 | + } |
|
| 163 | 168 | } else if (strpos($element, '=') > 0) { |
| 164 | 169 | $parts = explode('=', $element, 2); |
| 165 | 170 | $attributes[] = $parts[0] . '="' . $parts[1] . '"'; |
| 166 | 171 | } |
| 167 | 172 | } |
| 168 | 173 | |
| 169 | - if (!$id) $id = $defaultIdValue; |
|
| 174 | + if (!$id) { |
|
| 175 | + $id = $defaultIdValue; |
|
| 176 | + } |
|
| 170 | 177 | |
| 171 | 178 | # compose attributes as string |
| 172 | 179 | $attr_str = ""; |
@@ -263,7 +270,9 @@ discard block |
||
| 263 | 270 | # _HashHTMLBlocks_InMarkdown to handle the Markdown syntax within the tag. |
| 264 | 271 | # These two functions are calling each other. It's recursive! |
| 265 | 272 | # |
| 266 | - if ($this->no_markup) return $text; |
|
| 273 | + if ($this->no_markup) { |
|
| 274 | + return $text; |
|
| 275 | + } |
|
| 267 | 276 | |
| 268 | 277 | # |
| 269 | 278 | # Call the HTML-in-Markdown hasher. |
@@ -300,7 +309,9 @@ discard block |
||
| 300 | 309 | # |
| 301 | 310 | # Returns an array of that form: ( processed text , remaining text ) |
| 302 | 311 | # |
| 303 | - if ($text === '') return array('', ''); |
|
| 312 | + if ($text === '') { |
|
| 313 | + return array('', ''); |
|
| 314 | + } |
|
| 304 | 315 | |
| 305 | 316 | # Regex to check for the presense of newlines around a block tag. |
| 306 | 317 | $newline_before_re = '/(?:^\n?|\n\n)*$/'; |
@@ -420,8 +431,7 @@ discard block |
||
| 420 | 431 | # End marker found: pass text unchanged until marker. |
| 421 | 432 | $parsed .= $tag . $matches[0]; |
| 422 | 433 | $text = substr($text, strlen($matches[0])); |
| 423 | - } |
|
| 424 | - else { |
|
| 434 | + } else { |
|
| 425 | 435 | # No end marker: just skip it. |
| 426 | 436 | $parsed .= $tag; |
| 427 | 437 | } |
@@ -447,8 +457,7 @@ discard block |
||
| 447 | 457 | # End marker found: pass text unchanged until marker. |
| 448 | 458 | $parsed .= $tag . $matches[0]; |
| 449 | 459 | $text = substr($text, strlen($matches[0])); |
| 450 | - } |
|
| 451 | - else { |
|
| 460 | + } else { |
|
| 452 | 461 | # Unmatched marker: just skip it. |
| 453 | 462 | $parsed .= $tag; |
| 454 | 463 | } |
@@ -495,8 +504,11 @@ discard block |
||
| 495 | 504 | # |
| 496 | 505 | # Increase/decrease nested tag count. |
| 497 | 506 | # |
| 498 | - if ($tag{1} == '/') $depth--; |
|
| 499 | - else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
| 507 | + if ($tag{1} == '/') { |
|
| 508 | + $depth--; |
|
| 509 | + } else if ($tag{strlen($tag)-2} != '/') { |
|
| 510 | + $depth++; |
|
| 511 | + } |
|
| 500 | 512 | |
| 501 | 513 | if ($depth < 0) { |
| 502 | 514 | # |
@@ -508,8 +520,7 @@ discard block |
||
| 508 | 520 | } |
| 509 | 521 | |
| 510 | 522 | $parsed .= $tag; |
| 511 | - } |
|
| 512 | - else { |
|
| 523 | + } else { |
|
| 513 | 524 | $parsed .= $tag; |
| 514 | 525 | } |
| 515 | 526 | } while ($depth >= 0); |
@@ -527,7 +538,9 @@ discard block |
||
| 527 | 538 | # |
| 528 | 539 | # Returns an array of that form: ( processed text , remaining text ) |
| 529 | 540 | # |
| 530 | - if ($text === '') return array('', ''); |
|
| 541 | + if ($text === '') { |
|
| 542 | + return array('', ''); |
|
| 543 | + } |
|
| 531 | 544 | |
| 532 | 545 | # Regex to match `markdown` attribute inside of a tag. |
| 533 | 546 | $markdown_attr_re = ' |
@@ -578,8 +591,9 @@ discard block |
||
| 578 | 591 | # Get the name of the starting tag. |
| 579 | 592 | # (This pattern makes $base_tag_name_re safe without quoting.) |
| 580 | 593 | # |
| 581 | - if (preg_match('/^<([\w:$]*)\b/', $text, $matches)) |
|
| 582 | - $base_tag_name_re = $matches[1]; |
|
| 594 | + if (preg_match('/^<([\w:$]*)\b/', $text, $matches)) { |
|
| 595 | + $base_tag_name_re = $matches[1]; |
|
| 596 | + } |
|
| 583 | 597 | |
| 584 | 598 | # |
| 585 | 599 | # Loop through every tag until we find the corresponding closing tag. |
@@ -616,15 +630,17 @@ discard block |
||
| 616 | 630 | { |
| 617 | 631 | # Just add the tag to the block as if it was text. |
| 618 | 632 | $block_text .= $tag; |
| 619 | - } |
|
| 620 | - else { |
|
| 633 | + } else { |
|
| 621 | 634 | # |
| 622 | 635 | # Increase/decrease nested tag count. Only do so if |
| 623 | 636 | # the tag's name match base tag's. |
| 624 | 637 | # |
| 625 | 638 | if (preg_match('{^</?'.$base_tag_name_re.'\b}', $tag)) { |
| 626 | - if ($tag{1} == '/') $depth--; |
|
| 627 | - else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
| 639 | + if ($tag{1} == '/') { |
|
| 640 | + $depth--; |
|
| 641 | + } else if ($tag{strlen($tag)-2} != '/') { |
|
| 642 | + $depth++; |
|
| 643 | + } |
|
| 628 | 644 | } |
| 629 | 645 | |
| 630 | 646 | # |
@@ -671,13 +687,17 @@ discard block |
||
| 671 | 687 | } |
| 672 | 688 | |
| 673 | 689 | # Append tag content to parsed text. |
| 674 | - if (!$span_mode) $parsed .= "\n\n$block_text\n\n"; |
|
| 675 | - else $parsed .= "$block_text"; |
|
| 690 | + if (!$span_mode) { |
|
| 691 | + $parsed .= "\n\n$block_text\n\n"; |
|
| 692 | + } else { |
|
| 693 | + $parsed .= "$block_text"; |
|
| 694 | + } |
|
| 676 | 695 | |
| 677 | 696 | # Start over with a new block. |
| 678 | 697 | $block_text = ""; |
| 698 | + } else { |
|
| 699 | + $block_text .= $tag; |
|
| 679 | 700 | } |
| 680 | - else $block_text .= $tag; |
|
| 681 | 701 | } |
| 682 | 702 | |
| 683 | 703 | } while ($depth > 0); |
@@ -705,7 +725,9 @@ discard block |
||
| 705 | 725 | # |
| 706 | 726 | # Turn Markdown link shortcuts into XHTML <a> tags. |
| 707 | 727 | # |
| 708 | - if ($this->in_anchor) return $text; |
|
| 728 | + if ($this->in_anchor) { |
|
| 729 | + return $text; |
|
| 730 | + } |
|
| 709 | 731 | $this->in_anchor = true; |
| 710 | 732 | |
| 711 | 733 | # |
@@ -796,14 +818,14 @@ discard block |
||
| 796 | 818 | $title = $this->encodeAttribute($title); |
| 797 | 819 | $result .= " title=\"$title\""; |
| 798 | 820 | } |
| 799 | - if (isset($this->ref_attr[$link_id])) |
|
| 800 | - $result .= $this->ref_attr[$link_id]; |
|
| 821 | + if (isset($this->ref_attr[$link_id])) { |
|
| 822 | + $result .= $this->ref_attr[$link_id]; |
|
| 823 | + } |
|
| 801 | 824 | |
| 802 | 825 | $link_text = $this->runSpanGamut($link_text); |
| 803 | 826 | $result .= ">$link_text</a>"; |
| 804 | 827 | $result = $this->hashPart($result); |
| 805 | - } |
|
| 806 | - else { |
|
| 828 | + } else { |
|
| 807 | 829 | $result = $whole_match; |
| 808 | 830 | } |
| 809 | 831 | return $result; |
@@ -818,8 +840,9 @@ discard block |
||
| 818 | 840 | // if the URL was of the form <s p a c e s> it got caught by the HTML |
| 819 | 841 | // tag parser and hashed. Need to reverse the process before using the URL. |
| 820 | 842 | $unhashed = $this->unhash($url); |
| 821 | - if ($unhashed != $url) |
|
| 822 | - $url = preg_replace('/^<(.*)>$/', '\1', $unhashed); |
|
| 843 | + if ($unhashed != $url) { |
|
| 844 | + $url = preg_replace('/^<(.*)>$/', '\1', $unhashed); |
|
| 845 | + } |
|
| 823 | 846 | |
| 824 | 847 | $url = $this->encodeURLAttribute($url); |
| 825 | 848 | |
@@ -911,12 +934,12 @@ discard block |
||
| 911 | 934 | $title = $this->encodeAttribute($title); |
| 912 | 935 | $result .= " title=\"$title\""; |
| 913 | 936 | } |
| 914 | - if (isset($this->ref_attr[$link_id])) |
|
| 915 | - $result .= $this->ref_attr[$link_id]; |
|
| 937 | + if (isset($this->ref_attr[$link_id])) { |
|
| 938 | + $result .= $this->ref_attr[$link_id]; |
|
| 939 | + } |
|
| 916 | 940 | $result .= $this->empty_element_suffix; |
| 917 | 941 | $result = $this->hashPart($result); |
| 918 | - } |
|
| 919 | - else { |
|
| 942 | + } else { |
|
| 920 | 943 | # If there's no such link ID, leave intact: |
| 921 | 944 | $result = $whole_match; |
| 922 | 945 | } |
@@ -985,8 +1008,9 @@ discard block |
||
| 985 | 1008 | return $text; |
| 986 | 1009 | } |
| 987 | 1010 | protected function _doHeaders_callback_setext($matches) { |
| 988 | - if ($matches[3] == '-' && preg_match('{^- }', $matches[1])) |
|
| 989 | - return $matches[0]; |
|
| 1011 | + if ($matches[3] == '-' && preg_match('{^- }', $matches[1])) { |
|
| 1012 | + return $matches[0]; |
|
| 1013 | + } |
|
| 990 | 1014 | |
| 991 | 1015 | $level = $matches[3]{0} == '=' ? 1 : 2; |
| 992 | 1016 | |
@@ -1079,8 +1103,9 @@ discard block |
||
| 1079 | 1103 | } |
| 1080 | 1104 | protected function _doTable_makeAlignAttr($alignname) |
| 1081 | 1105 | { |
| 1082 | - if (empty($this->table_align_class_tmpl)) |
|
| 1083 | - return " align=\"$alignname\""; |
|
| 1106 | + if (empty($this->table_align_class_tmpl)) { |
|
| 1107 | + return " align=\"$alignname\""; |
|
| 1108 | + } |
|
| 1084 | 1109 | |
| 1085 | 1110 | $classname = str_replace('%%', $alignname, $this->table_align_class_tmpl); |
| 1086 | 1111 | return " class=\"$classname\""; |
@@ -1098,14 +1123,15 @@ discard block |
||
| 1098 | 1123 | # Reading alignement from header underline. |
| 1099 | 1124 | $separators = preg_split('/ *[|] */', $underline); |
| 1100 | 1125 | foreach ($separators as $n => $s) { |
| 1101 | - if (preg_match('/^ *-+: *$/', $s)) |
|
| 1102 | - $attr[$n] = $this->_doTable_makeAlignAttr('right'); |
|
| 1103 | - else if (preg_match('/^ *:-+: *$/', $s)) |
|
| 1104 | - $attr[$n] = $this->_doTable_makeAlignAttr('center'); |
|
| 1105 | - else if (preg_match('/^ *:-+ *$/', $s)) |
|
| 1106 | - $attr[$n] = $this->_doTable_makeAlignAttr('left'); |
|
| 1107 | - else |
|
| 1108 | - $attr[$n] = ''; |
|
| 1126 | + if (preg_match('/^ *-+: *$/', $s)) { |
|
| 1127 | + $attr[$n] = $this->_doTable_makeAlignAttr('right'); |
|
| 1128 | + } else if (preg_match('/^ *:-+: *$/', $s)) { |
|
| 1129 | + $attr[$n] = $this->_doTable_makeAlignAttr('center'); |
|
| 1130 | + } else if (preg_match('/^ *:-+ *$/', $s)) { |
|
| 1131 | + $attr[$n] = $this->_doTable_makeAlignAttr('left'); |
|
| 1132 | + } else { |
|
| 1133 | + $attr[$n] = ''; |
|
| 1134 | + } |
|
| 1109 | 1135 | } |
| 1110 | 1136 | |
| 1111 | 1137 | # Parsing span elements, including code spans, character escapes, |
@@ -1119,8 +1145,9 @@ discard block |
||
| 1119 | 1145 | $text = "<table>\n"; |
| 1120 | 1146 | $text .= "<thead>\n"; |
| 1121 | 1147 | $text .= "<tr>\n"; |
| 1122 | - foreach ($headers as $n => $header) |
|
| 1123 | - $text .= " <th$attr[$n]>".$this->runSpanGamut(trim($header))."</th>\n"; |
|
| 1148 | + foreach ($headers as $n => $header) { |
|
| 1149 | + $text .= " <th$attr[$n]>".$this->runSpanGamut(trim($header))."</th>\n"; |
|
| 1150 | + } |
|
| 1124 | 1151 | $text .= "</tr>\n"; |
| 1125 | 1152 | $text .= "</thead>\n"; |
| 1126 | 1153 | |
@@ -1138,8 +1165,9 @@ discard block |
||
| 1138 | 1165 | $row_cells = array_pad($row_cells, $col_count, ''); |
| 1139 | 1166 | |
| 1140 | 1167 | $text .= "<tr>\n"; |
| 1141 | - foreach ($row_cells as $n => $cell) |
|
| 1142 | - $text .= " <td$attr[$n]>".$this->runSpanGamut(trim($cell))."</td>\n"; |
|
| 1168 | + foreach ($row_cells as $n => $cell) { |
|
| 1169 | + $text .= " <td$attr[$n]>".$this->runSpanGamut(trim($cell))."</td>\n"; |
|
| 1170 | + } |
|
| 1143 | 1171 | $text .= "</tr>\n"; |
| 1144 | 1172 | } |
| 1145 | 1173 | $text .= "</tbody>\n"; |
@@ -1265,8 +1293,7 @@ discard block |
||
| 1265 | 1293 | $def = str_repeat(' ', strlen($marker_space)) . $def; |
| 1266 | 1294 | $def = $this->runBlockGamut($this->outdent($def . "\n\n")); |
| 1267 | 1295 | $def = "\n". $def ."\n"; |
| 1268 | - } |
|
| 1269 | - else { |
|
| 1296 | + } else { |
|
| 1270 | 1297 | $def = rtrim($def); |
| 1271 | 1298 | $def = $this->runSpanGamut($this->outdent($def)); |
| 1272 | 1299 | } |
@@ -1323,8 +1350,9 @@ discard block |
||
| 1323 | 1350 | array($this, '_doFencedCodeBlocks_newlines'), $codeblock); |
| 1324 | 1351 | |
| 1325 | 1352 | if ($classname != "") { |
| 1326 | - if ($classname{0} == '.') |
|
| 1327 | - $classname = substr($classname, 1); |
|
| 1353 | + if ($classname{0} == '.') { |
|
| 1354 | + $classname = substr($classname, 1); |
|
| 1355 | + } |
|
| 1328 | 1356 | $attr_str = ' class="'.$this->code_class_prefix.$classname.'"'; |
| 1329 | 1357 | } else { |
| 1330 | 1358 | $attr_str = $this->doExtraAttributes($this->code_attr_on_pre ? "pre" : "code", $attrs); |
@@ -1573,8 +1601,9 @@ discard block |
||
| 1573 | 1601 | protected function _stripAbbreviations_callback($matches) { |
| 1574 | 1602 | $abbr_word = $matches[1]; |
| 1575 | 1603 | $abbr_desc = $matches[2]; |
| 1576 | - if ($this->abbr_word_re) |
|
| 1577 | - $this->abbr_word_re .= '|'; |
|
| 1604 | + if ($this->abbr_word_re) { |
|
| 1605 | + $this->abbr_word_re .= '|'; |
|
| 1606 | + } |
|
| 1578 | 1607 | $this->abbr_word_re .= preg_quote($abbr_word); |
| 1579 | 1608 | $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); |
| 1580 | 1609 | return ''; # String that will replace the block |
@@ -194,11 +194,11 @@ |
||
| 194 | 194 | * Call each filter and return array with details of the formatted content. |
| 195 | 195 | * |
| 196 | 196 | * @param string $text the text to filter. |
| 197 | - * @param array $filter array of filters to use. |
|
| 197 | + * @param string[] $filter array of filters to use. |
|
| 198 | 198 | * |
| 199 | 199 | * @throws mos/TextFilter/Exception when filterd does not exists. |
| 200 | 200 | * |
| 201 | - * @return array with the formatted text and additional details. |
|
| 201 | + * @return \stdClass with the formatted text and additional details. |
|
| 202 | 202 | */ |
| 203 | 203 | public function parse($text, $filter) |
| 204 | 204 | { |
@@ -21,13 +21,13 @@ |
||
| 21 | 21 | "nl2br", |
| 22 | 22 | "purify", |
| 23 | 23 | "titlefromh1", |
| 24 | - ]; |
|
| 24 | + ]; |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Current document parsed. |
|
| 30 | - */ |
|
| 28 | + /** |
|
| 29 | + * Current document parsed. |
|
| 30 | + */ |
|
| 31 | 31 | private $current; |
| 32 | 32 | |
| 33 | 33 | |
@@ -66,10 +66,10 @@ discard block |
||
| 66 | 66 | // For each filter, call its function with the $text as parameter. |
| 67 | 67 | foreach ($filter as $key) { |
| 68 | 68 | |
| 69 | - if (!isset($callbacks[$key])) { |
|
| 69 | + if (!isset($callbacks[ $key ])) { |
|
| 70 | 70 | throw new Exception("The filter '$filters' is not a valid filter string due to '$key'."); |
| 71 | 71 | } |
| 72 | - $text = call_user_func_array([$this, $callbacks[$key]], [$text]); |
|
| 72 | + $text = call_user_func_array([ $this, $callbacks[ $key ] ], [ $text ]); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | return $text; |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | if (is_null($this->current->frontmatter)) { |
| 123 | - $this->current->frontmatter = []; |
|
| 123 | + $this->current->frontmatter = [ ]; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | $this->current->frontmatter = array_merge_recursive($this->current->frontmatter, $matter); |
@@ -155,20 +155,20 @@ discard block |
||
| 155 | 155 | switch ($filter) { |
| 156 | 156 | case "jsonfrontmatter": |
| 157 | 157 | $res = $this->jsonFrontMatter($text); |
| 158 | - $this->current->text = $res["text"]; |
|
| 159 | - $this->addToFrontmatter($res["frontmatter"]); |
|
| 158 | + $this->current->text = $res[ "text" ]; |
|
| 159 | + $this->addToFrontmatter($res[ "frontmatter" ]); |
|
| 160 | 160 | break; |
| 161 | 161 | |
| 162 | 162 | case "yamlfrontmatter": |
| 163 | 163 | $res = $this->yamlFrontMatter($text); |
| 164 | - $this->current->text = $res["text"]; |
|
| 165 | - $this->addToFrontmatter($res["frontmatter"]); |
|
| 164 | + $this->current->text = $res[ "text" ]; |
|
| 165 | + $this->addToFrontmatter($res[ "frontmatter" ]); |
|
| 166 | 166 | break; |
| 167 | 167 | |
| 168 | 168 | case "titlefromh1": |
| 169 | 169 | $title = $this->getTitleFromFirstH1($text); |
| 170 | 170 | $this->current->text = $text; |
| 171 | - $this->addToFrontmatter(["title" => $title]); |
|
| 171 | + $this->addToFrontmatter([ "title" => $title ]); |
|
| 172 | 172 | break; |
| 173 | 173 | |
| 174 | 174 | case "bbcode": |
@@ -178,8 +178,8 @@ discard block |
||
| 178 | 178 | case "nl2br": |
| 179 | 179 | case "purify": |
| 180 | 180 | $this->current->text = call_user_func_array( |
| 181 | - [$this, $callbacks[$filter]], |
|
| 182 | - [$text] |
|
| 181 | + [ $this, $callbacks[ $filter ] ], |
|
| 182 | + [ $text ] |
|
| 183 | 183 | ); |
| 184 | 184 | break; |
| 185 | 185 | |
@@ -239,11 +239,11 @@ discard block |
||
| 239 | 239 | |
| 240 | 240 | $frontmatter = substr($text, $start + $tokenLength, $length); |
| 241 | 241 | $textStart = substr($text, 0, $start); |
| 242 | - $text = $textStart . substr($text, $stop + $tokenLength); |
|
| 242 | + $text = $textStart.substr($text, $stop + $tokenLength); |
|
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - return [$text, $frontmatter]; |
|
| 246 | + return [ $text, $frontmatter ]; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | list($text, $frontmatter) = $this->extractFrontMatter($text, $needle, $needle); |
| 289 | 289 | |
| 290 | 290 | if (function_exists("yaml_parse") && !empty($frontmatter)) { |
| 291 | - $frontmatter = yaml_parse($needle . $frontmatter); |
|
| 291 | + $frontmatter = yaml_parse($needle.$frontmatter); |
|
| 292 | 292 | |
| 293 | 293 | if ($frontmatter === false) { |
| 294 | 294 | throw new Exception("Failed parsing YAML frontmatter."); |
@@ -312,11 +312,11 @@ discard block |
||
| 312 | 312 | */ |
| 313 | 313 | public function getTitleFromFirstH1($text) |
| 314 | 314 | { |
| 315 | - $matches = []; |
|
| 315 | + $matches = [ ]; |
|
| 316 | 316 | $title = null; |
| 317 | 317 | |
| 318 | 318 | if (preg_match("#<h1.*?>(.*)</h1>#", $text, $matches)) { |
| 319 | - $title = strip_tags($matches[1]); |
|
| 319 | + $title = strip_tags($matches[ 1 ]); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | return $title; |
@@ -371,8 +371,8 @@ discard block |
||
| 371 | 371 | { |
| 372 | 372 | return preg_replace_callback( |
| 373 | 373 | '#\b(?<![href|src]=[\'"])https?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', |
| 374 | - function ($matches) { |
|
| 375 | - return "<a href='{$matches[0]}'>{$matches[0]}</a>"; |
|
| 374 | + function($matches) { |
|
| 375 | + return "<a href='{$matches[ 0 ]}'>{$matches[ 0 ]}</a>"; |
|
| 376 | 376 | }, |
| 377 | 377 | $text |
| 378 | 378 | ); |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | */ |
| 390 | 390 | public function purify($text) |
| 391 | 391 | { |
| 392 | - $config = \HTMLPurifier_Config::createDefault(); |
|
| 392 | + $config = \HTMLPurifier_Config::createDefault(); |
|
| 393 | 393 | $config->set("Cache.DefinitionImpl", null); |
| 394 | 394 | //$config->set('Cache.SerializerPath', '/home/user/absolute/path'); |
| 395 | 395 | |
@@ -443,15 +443,15 @@ discard block |
||
| 443 | 443 | |
| 444 | 444 | return preg_replace_callback( |
| 445 | 445 | $patterns, |
| 446 | - function ($matches) { |
|
| 447 | - switch ($matches[1]) { |
|
| 446 | + function($matches) { |
|
| 447 | + switch ($matches[ 1 ]) { |
|
| 448 | 448 | |
| 449 | 449 | case 'FIGURE': |
| 450 | - return self::ShortCodeFigure($matches[2]); |
|
| 450 | + return self::ShortCodeFigure($matches[ 2 ]); |
|
| 451 | 451 | break; |
| 452 | 452 | |
| 453 | 453 | default: |
| 454 | - return "{$matches[1]} is unknown shortcode."; |
|
| 454 | + return "{$matches[ 1 ]} is unknown shortcode."; |
|
| 455 | 455 | } |
| 456 | 456 | }, |
| 457 | 457 | $text |
@@ -472,14 +472,14 @@ discard block |
||
| 472 | 472 | preg_match_all('/[a-zA-Z0-9]+="[^"]+"|\S+/', $options, $matches); |
| 473 | 473 | |
| 474 | 474 | $res = array(); |
| 475 | - foreach ($matches[0] as $match) { |
|
| 475 | + foreach ($matches[ 0 ] as $match) { |
|
| 476 | 476 | $pos = strpos($match, '='); |
| 477 | 477 | if ($pos === false) { |
| 478 | - $res[$match] = true; |
|
| 478 | + $res[ $match ] = true; |
|
| 479 | 479 | } else { |
| 480 | 480 | $key = substr($match, 0, $pos); |
| 481 | - $val = trim(substr($match, $pos+1), '"'); |
|
| 482 | - $res[$key] = $val; |
|
| 481 | + $val = trim(substr($match, $pos + 1), '"'); |
|
| 482 | + $res[ $key ] = $val; |
|
| 483 | 483 | } |
| 484 | 484 | } |
| 485 | 485 | |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | public static function shortCodeFigure($options) |
| 501 | 501 | { |
| 502 | 502 | // Merge incoming options with default and expose as variables |
| 503 | - $options= array_merge( |
|
| 503 | + $options = array_merge( |
|
| 504 | 504 | [ |
| 505 | 505 | 'id' => null, |
| 506 | 506 | 'class' => null, |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | public static function loadClassLoader($class) |
| 10 | 10 | { |
| 11 | 11 | if ('Composer\Autoload\ClassLoader' === $class) { |
| 12 | - require __DIR__ . '/ClassLoader.php'; |
|
| 12 | + require __DIR__.'/ClassLoader.php'; |
|
| 13 | 13 | } |
| 14 | 14 | } |
| 15 | 15 | |
@@ -23,24 +23,24 @@ discard block |
||
| 23 | 23 | self::$loader = $loader = new \Composer\Autoload\ClassLoader(); |
| 24 | 24 | spl_autoload_unregister(array('ComposerAutoloaderInit62f39d7a932289837b43d6101406a178', 'loadClassLoader')); |
| 25 | 25 | |
| 26 | - $map = require __DIR__ . '/autoload_namespaces.php'; |
|
| 26 | + $map = require __DIR__.'/autoload_namespaces.php'; |
|
| 27 | 27 | foreach ($map as $namespace => $path) { |
| 28 | 28 | $loader->set($namespace, $path); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - $map = require __DIR__ . '/autoload_psr4.php'; |
|
| 31 | + $map = require __DIR__.'/autoload_psr4.php'; |
|
| 32 | 32 | foreach ($map as $namespace => $path) { |
| 33 | 33 | $loader->setPsr4($namespace, $path); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - $classMap = require __DIR__ . '/autoload_classmap.php'; |
|
| 36 | + $classMap = require __DIR__.'/autoload_classmap.php'; |
|
| 37 | 37 | if ($classMap) { |
| 38 | 38 | $loader->addClassMap($classMap); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | $loader->register(true); |
| 42 | 42 | |
| 43 | - $includeFiles = require __DIR__ . '/autoload_files.php'; |
|
| 43 | + $includeFiles = require __DIR__.'/autoload_files.php'; |
|
| 44 | 44 | foreach ($includeFiles as $fileIdentifier => $file) { |
| 45 | 45 | composerRequire62f39d7a932289837b43d6101406a178($fileIdentifier, $file); |
| 46 | 46 | } |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | function composerRequire62f39d7a932289837b43d6101406a178($fileIdentifier, $file) |
| 53 | 53 | { |
| 54 | - if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { |
|
| 54 | + if (empty($GLOBALS[ '__composer_autoload_files' ][ $fileIdentifier ])) { |
|
| 55 | 55 | require $file; |
| 56 | 56 | |
| 57 | - $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; |
|
| 57 | + $GLOBALS[ '__composer_autoload_files' ][ $fileIdentifier ] = true; |
|
| 58 | 58 | } |
| 59 | 59 | } |
@@ -6,8 +6,8 @@ |
||
| 6 | 6 | $baseDir = dirname($vendorDir); |
| 7 | 7 | |
| 8 | 8 | return array( |
| 9 | - 'petlid\\' => array($baseDir . '/src'), |
|
| 10 | - 'Mos\\TextFilter\\' => array($vendorDir . '/mos/ctextfilter/src/TextFilter'), |
|
| 11 | - 'Mos\\' => array($vendorDir . '/mos/cform/src'), |
|
| 12 | - 'Anax\\' => array($vendorDir . '/anax/mvc/src'), |
|
| 9 | + 'petlid\\' => array($baseDir.'/src'), |
|
| 10 | + 'Mos\\TextFilter\\' => array($vendorDir.'/mos/ctextfilter/src/TextFilter'), |
|
| 11 | + 'Mos\\' => array($vendorDir.'/mos/cform/src'), |
|
| 12 | + 'Anax\\' => array($vendorDir.'/anax/mvc/src'), |
|
| 13 | 13 | ); |