@@ -170,8 +170,9 @@ discard block |
||
170 | 170 | $this->footnotes_assembled = null; |
171 | 171 | |
172 | 172 | foreach ($this->predef_abbr as $abbr_word => $abbr_desc) { |
173 | - if ($this->abbr_word_re) |
|
174 | - $this->abbr_word_re .= '|'; |
|
173 | + if ($this->abbr_word_re) { |
|
174 | + $this->abbr_word_re .= '|'; |
|
175 | + } |
|
175 | 176 | $this->abbr_word_re .= preg_quote($abbr_word); |
176 | 177 | $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); |
177 | 178 | } |
@@ -188,8 +189,9 @@ discard block |
||
188 | 189 | $this->abbr_desciptions = array(); |
189 | 190 | $this->abbr_word_re = ''; |
190 | 191 | |
191 | - if ( ! $this->omit_footnotes ) |
|
192 | - $this->footnotes_assembled = null; |
|
192 | + if ( ! $this->omit_footnotes ) { |
|
193 | + $this->footnotes_assembled = null; |
|
194 | + } |
|
193 | 195 | |
194 | 196 | parent::teardown(); |
195 | 197 | } |
@@ -227,7 +229,9 @@ discard block |
||
227 | 229 | * @return string |
228 | 230 | */ |
229 | 231 | protected function doExtraAttributes($tag_name, $attr, $defaultIdValue = null, $classes = array()) { |
230 | - if (empty($attr) && !$defaultIdValue && empty($classes)) return ""; |
|
232 | + if (empty($attr) && !$defaultIdValue && empty($classes)) { |
|
233 | + return ""; |
|
234 | + } |
|
231 | 235 | |
232 | 236 | // Split on components |
233 | 237 | preg_match_all('/[#.a-z][-_:a-zA-Z0-9=]+/', $attr, $matches); |
@@ -240,14 +244,18 @@ discard block |
||
240 | 244 | if ($element{0} == '.') { |
241 | 245 | $classes[] = substr($element, 1); |
242 | 246 | } else if ($element{0} == '#') { |
243 | - if ($id === false) $id = substr($element, 1); |
|
247 | + if ($id === false) { |
|
248 | + $id = substr($element, 1); |
|
249 | + } |
|
244 | 250 | } else if (strpos($element, '=') > 0) { |
245 | 251 | $parts = explode('=', $element, 2); |
246 | 252 | $attributes[] = $parts[0] . '="' . $parts[1] . '"'; |
247 | 253 | } |
248 | 254 | } |
249 | 255 | |
250 | - if (!$id) $id = $defaultIdValue; |
|
256 | + if (!$id) { |
|
257 | + $id = $defaultIdValue; |
|
258 | + } |
|
251 | 259 | |
252 | 260 | // Compose attributes as string |
253 | 261 | $attr_str = ""; |
@@ -414,7 +422,9 @@ discard block |
||
414 | 422 | $enclosing_tag_re = '', $span = false) |
415 | 423 | { |
416 | 424 | |
417 | - if ($text === '') return array('', ''); |
|
425 | + if ($text === '') { |
|
426 | + return array('', ''); |
|
427 | + } |
|
418 | 428 | |
419 | 429 | // Regex to check for the presense of newlines around a block tag. |
420 | 430 | $newline_before_re = '/(?:^\n?|\n\n)*$/'; |
@@ -526,8 +536,7 @@ discard block |
||
526 | 536 | // End marker found: pass text unchanged until marker. |
527 | 537 | $parsed .= $tag . $matches[0]; |
528 | 538 | $text = substr($text, strlen($matches[0])); |
529 | - } |
|
530 | - else { |
|
539 | + } else { |
|
531 | 540 | // No end marker: just skip it. |
532 | 541 | $parsed .= $tag; |
533 | 542 | } |
@@ -549,8 +558,7 @@ discard block |
||
549 | 558 | // End marker found: pass text unchanged until marker. |
550 | 559 | $parsed .= $tag . $matches[0]; |
551 | 560 | $text = substr($text, strlen($matches[0])); |
552 | - } |
|
553 | - else { |
|
561 | + } else { |
|
554 | 562 | // Unmatched marker: just skip it. |
555 | 563 | $parsed .= $tag; |
556 | 564 | } |
@@ -589,8 +597,11 @@ discard block |
||
589 | 597 | preg_match('{^</?(?:' . $enclosing_tag_re . ')\b}', $tag)) |
590 | 598 | { |
591 | 599 | // Increase/decrease nested tag count. |
592 | - if ($tag{1} == '/') $depth--; |
|
593 | - else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
600 | + if ($tag{1} == '/') { |
|
601 | + $depth--; |
|
602 | + } else if ($tag{strlen($tag)-2} != '/') { |
|
603 | + $depth++; |
|
604 | + } |
|
594 | 605 | |
595 | 606 | if ($depth < 0) { |
596 | 607 | // Going out of parent element. Clean up and break so we |
@@ -600,8 +611,7 @@ discard block |
||
600 | 611 | } |
601 | 612 | |
602 | 613 | $parsed .= $tag; |
603 | - } |
|
604 | - else { |
|
614 | + } else { |
|
605 | 615 | $parsed .= $tag; |
606 | 616 | } |
607 | 617 | } while ($depth >= 0); |
@@ -624,7 +634,9 @@ discard block |
||
624 | 634 | * @return array |
625 | 635 | */ |
626 | 636 | protected function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { |
627 | - if ($text === '') return array('', ''); |
|
637 | + if ($text === '') { |
|
638 | + return array('', ''); |
|
639 | + } |
|
628 | 640 | |
629 | 641 | // Regex to match `markdown` attribute inside of a tag. |
630 | 642 | $markdown_attr_re = ' |
@@ -673,8 +685,9 @@ discard block |
||
673 | 685 | |
674 | 686 | // Get the name of the starting tag. |
675 | 687 | // (This pattern makes $base_tag_name_re safe without quoting.) |
676 | - if (preg_match('/^<([\w:$]*)\b/', $text, $matches)) |
|
677 | - $base_tag_name_re = $matches[1]; |
|
688 | + if (preg_match('/^<([\w:$]*)\b/', $text, $matches)) { |
|
689 | + $base_tag_name_re = $matches[1]; |
|
690 | + } |
|
678 | 691 | |
679 | 692 | // Loop through every tag until we find the corresponding closing tag. |
680 | 693 | do { |
@@ -703,13 +716,15 @@ discard block |
||
703 | 716 | { |
704 | 717 | // Just add the tag to the block as if it was text. |
705 | 718 | $block_text .= $tag; |
706 | - } |
|
707 | - else { |
|
719 | + } else { |
|
708 | 720 | // Increase/decrease nested tag count. Only do so if |
709 | 721 | // the tag's name match base tag's. |
710 | 722 | if (preg_match('{^</?' . $base_tag_name_re . '\b}', $tag)) { |
711 | - if ($tag{1} == '/') $depth--; |
|
712 | - else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
723 | + if ($tag{1} == '/') { |
|
724 | + $depth--; |
|
725 | + } else if ($tag{strlen($tag)-2} != '/') { |
|
726 | + $depth++; |
|
727 | + } |
|
713 | 728 | } |
714 | 729 | |
715 | 730 | // Check for `markdown="1"` attribute and handle it. |
@@ -754,13 +769,17 @@ discard block |
||
754 | 769 | } |
755 | 770 | |
756 | 771 | // Append tag content to parsed text. |
757 | - if (!$span_mode) $parsed .= "\n\n$block_text\n\n"; |
|
758 | - else $parsed .= "$block_text"; |
|
772 | + if (!$span_mode) { |
|
773 | + $parsed .= "\n\n$block_text\n\n"; |
|
774 | + } else { |
|
775 | + $parsed .= "$block_text"; |
|
776 | + } |
|
759 | 777 | |
760 | 778 | // Start over with a new block. |
761 | 779 | $block_text = ""; |
780 | + } else { |
|
781 | + $block_text .= $tag; |
|
762 | 782 | } |
763 | - else $block_text .= $tag; |
|
764 | 783 | } |
765 | 784 | |
766 | 785 | } while ($depth > 0); |
@@ -881,14 +900,14 @@ discard block |
||
881 | 900 | $title = $this->encodeAttribute($title); |
882 | 901 | $result .= " title=\"$title\""; |
883 | 902 | } |
884 | - if (isset($this->ref_attr[$link_id])) |
|
885 | - $result .= $this->ref_attr[$link_id]; |
|
903 | + if (isset($this->ref_attr[$link_id])) { |
|
904 | + $result .= $this->ref_attr[$link_id]; |
|
905 | + } |
|
886 | 906 | |
887 | 907 | $link_text = $this->runSpanGamut($link_text); |
888 | 908 | $result .= ">$link_text</a>"; |
889 | 909 | $result = $this->hashPart($result); |
890 | - } |
|
891 | - else { |
|
910 | + } else { |
|
892 | 911 | $result = $whole_match; |
893 | 912 | } |
894 | 913 | return $result; |
@@ -909,8 +928,9 @@ discard block |
||
909 | 928 | // if the URL was of the form <s p a c e s> it got caught by the HTML |
910 | 929 | // tag parser and hashed. Need to reverse the process before using the URL. |
911 | 930 | $unhashed = $this->unhash($url); |
912 | - if ($unhashed != $url) |
|
913 | - $url = preg_replace('/^<(.*)>$/', '\1', $unhashed); |
|
931 | + if ($unhashed != $url) { |
|
932 | + $url = preg_replace('/^<(.*)>$/', '\1', $unhashed); |
|
933 | + } |
|
914 | 934 | |
915 | 935 | $url = $this->encodeURLAttribute($url); |
916 | 936 | |
@@ -1005,12 +1025,12 @@ discard block |
||
1005 | 1025 | $title = $this->encodeAttribute($title); |
1006 | 1026 | $result .= " title=\"$title\""; |
1007 | 1027 | } |
1008 | - if (isset($this->ref_attr[$link_id])) |
|
1009 | - $result .= $this->ref_attr[$link_id]; |
|
1028 | + if (isset($this->ref_attr[$link_id])) { |
|
1029 | + $result .= $this->ref_attr[$link_id]; |
|
1030 | + } |
|
1010 | 1031 | $result .= $this->empty_element_suffix; |
1011 | 1032 | $result = $this->hashPart($result); |
1012 | - } |
|
1013 | - else { |
|
1033 | + } else { |
|
1014 | 1034 | // If there's no such link ID, leave intact: |
1015 | 1035 | $result = $whole_match; |
1016 | 1036 | } |
@@ -1227,14 +1247,15 @@ discard block |
||
1227 | 1247 | // Reading alignement from header underline. |
1228 | 1248 | $separators = preg_split('/ *[|] */', $underline); |
1229 | 1249 | foreach ($separators as $n => $s) { |
1230 | - if (preg_match('/^ *-+: *$/', $s)) |
|
1231 | - $attr[$n] = $this->_doTable_makeAlignAttr('right'); |
|
1232 | - else if (preg_match('/^ *:-+: *$/', $s)) |
|
1233 | - $attr[$n] = $this->_doTable_makeAlignAttr('center'); |
|
1234 | - else if (preg_match('/^ *:-+ *$/', $s)) |
|
1235 | - $attr[$n] = $this->_doTable_makeAlignAttr('left'); |
|
1236 | - else |
|
1237 | - $attr[$n] = ''; |
|
1250 | + if (preg_match('/^ *-+: *$/', $s)) { |
|
1251 | + $attr[$n] = $this->_doTable_makeAlignAttr('right'); |
|
1252 | + } else if (preg_match('/^ *:-+: *$/', $s)) { |
|
1253 | + $attr[$n] = $this->_doTable_makeAlignAttr('center'); |
|
1254 | + } else if (preg_match('/^ *:-+ *$/', $s)) { |
|
1255 | + $attr[$n] = $this->_doTable_makeAlignAttr('left'); |
|
1256 | + } else { |
|
1257 | + $attr[$n] = ''; |
|
1258 | + } |
|
1238 | 1259 | } |
1239 | 1260 | |
1240 | 1261 | // Parsing span elements, including code spans, character escapes, |
@@ -1248,8 +1269,9 @@ discard block |
||
1248 | 1269 | $text = "<table>\n"; |
1249 | 1270 | $text .= "<thead>\n"; |
1250 | 1271 | $text .= "<tr>\n"; |
1251 | - foreach ($headers as $n => $header) |
|
1252 | - $text .= " <th$attr[$n]>" . $this->runSpanGamut(trim($header)) . "</th>\n"; |
|
1272 | + foreach ($headers as $n => $header) { |
|
1273 | + $text .= " <th$attr[$n]>" . $this->runSpanGamut(trim($header)) . "</th>\n"; |
|
1274 | + } |
|
1253 | 1275 | $text .= "</tr>\n"; |
1254 | 1276 | $text .= "</thead>\n"; |
1255 | 1277 | |
@@ -1267,8 +1289,9 @@ discard block |
||
1267 | 1289 | $row_cells = array_pad($row_cells, $col_count, ''); |
1268 | 1290 | |
1269 | 1291 | $text .= "<tr>\n"; |
1270 | - foreach ($row_cells as $n => $cell) |
|
1271 | - $text .= " <td$attr[$n]>" . $this->runSpanGamut(trim($cell)) . "</td>\n"; |
|
1292 | + foreach ($row_cells as $n => $cell) { |
|
1293 | + $text .= " <td$attr[$n]>" . $this->runSpanGamut(trim($cell)) . "</td>\n"; |
|
1294 | + } |
|
1272 | 1295 | $text .= "</tr>\n"; |
1273 | 1296 | } |
1274 | 1297 | $text .= "</tbody>\n"; |
@@ -1415,8 +1438,7 @@ discard block |
||
1415 | 1438 | $def = str_repeat(' ', strlen($marker_space)) . $def; |
1416 | 1439 | $def = $this->runBlockGamut($this->outdent($def . "\n\n")); |
1417 | 1440 | $def = "\n". $def ."\n"; |
1418 | - } |
|
1419 | - else { |
|
1441 | + } else { |
|
1420 | 1442 | $def = rtrim($def); |
1421 | 1443 | $def = $this->runSpanGamut($this->outdent($def)); |
1422 | 1444 | } |
@@ -1491,8 +1513,9 @@ discard block |
||
1491 | 1513 | |
1492 | 1514 | $classes = array(); |
1493 | 1515 | if ($classname != "") { |
1494 | - if ($classname{0} == '.') |
|
1495 | - $classname = substr($classname, 1); |
|
1516 | + if ($classname{0} == '.') { |
|
1517 | + $classname = substr($classname, 1); |
|
1518 | + } |
|
1496 | 1519 | $classes[] = $this->code_class_prefix . $classname; |
1497 | 1520 | } |
1498 | 1521 | $attr_str = $this->doExtraAttributes($this->code_attr_on_pre ? "pre" : "code", $attrs, null, $classes); |
@@ -776,8 +776,9 @@ |
||
776 | 776 | // tag parser and hashed. Need to reverse the process before using |
777 | 777 | // the URL. |
778 | 778 | $unhashed = $this->unhash($url); |
779 | - if ($unhashed != $url) |
|
780 | - $url = preg_replace('/^<(.*)>$/', '\1', $unhashed); |
|
779 | + if ($unhashed != $url) { |
|
780 | + $url = preg_replace('/^<(.*)>$/', '\1', $unhashed); |
|
781 | + } |
|
781 | 782 | |
782 | 783 | $url = $this->encodeURLAttribute($url); |
783 | 784 |