Skip to content
This repository
Browse code

First attempt to improve rewrite blocks; also eliminates post-paragra…

…ph starting single linebreaks.
  • Loading branch information...
commit b5a0b131e99eb6028e5ca5fed9c798982cdfe168 1 parent 08162f0
authored January 26, 2011

Showing 1 changed file with 49 additions and 75 deletions. Show diff stats Hide diff stats

  1. 124  inc/parser/handler.php
124  inc/parser/handler.php
@@ -1489,6 +1489,11 @@ function Doku_Handler_Block(){
1489 1489
         }
1490 1490
     }
1491 1491
 
  1492
+    function openParagraph($pos){
  1493
+        $this->calls[] = array('p_open',array(), $pos);
  1494
+        $this->inParagraph = true;
  1495
+    }
  1496
+
1492 1497
     /**
1493 1498
      * Close a paragraph if needed
1494 1499
      *
@@ -1548,7 +1553,7 @@ function process($calls) {
1548 1553
                     $this->closeParagraph($call[2]);
1549 1554
                 }
1550 1555
                 $this->calls[] = $call;
1551  
-
  1556
+                $this->skipEolKey = $key+1;
1552 1557
                 continue;
1553 1558
             }
1554 1559
 
@@ -1561,104 +1566,73 @@ function process($calls) {
1561 1566
                 if ($this->removeFromStack()) {
1562 1567
                     $this->calls[] = array('p_open',array(), $call[2]);
1563 1568
                 }
  1569
+                $this->skipEolKey = $key+1;
1564 1570
                 continue;
1565 1571
             }
1566 1572
 
1567  
-            if ( !$this->atStart ) {
1568  
-
1569  
-                if ( $cname == 'eol' ) {
1570  
-
1571  
-                    // Check this isn't an eol instruction to skip...
1572  
-                    if ( $this->skipEolKey != $key ) {
1573  
-                        // Look to see if the next instruction is an EOL
1574  
-                        if ( isset($calls[$key+1]) && $calls[$key+1][0] == 'eol' ) {
1575  
-
1576  
-                            if ( $this->inParagraph ) {
1577  
-                                //$this->calls[] = array('p_close',array(), $call[2]);
1578  
-                                $this->closeParagraph($call[2]);
1579  
-                            }
1580  
-
1581  
-                            $this->calls[] = array('p_open',array(), $call[2]);
1582  
-                            $this->inParagraph = true;
1583  
-
1584  
-
1585  
-                            // Mark the next instruction for skipping
1586  
-                            $this->skipEolKey = $key+1;
1587  
-
1588  
-                        }else{
1589  
-                            //if this is just a single eol make a space from it
1590  
-                            $this->addCall(array('cdata',array(DOKU_PARSER_EOL), $call[2]));
1591  
-                        }
1592  
-                    }
  1573
+            // Always opens a paragraph on stack start
  1574
+            // If this is a block start, it will soon be closed later
  1575
+            if ( $this->atStart ) {
  1576
+                $this->openParagraph($call[2]);
  1577
+                $this->atStart = false;
  1578
+                $this->skipEolKey = $key;
  1579
+            }
1593 1580
 
  1581
+            if ( $cname == 'eol' ) {
1594 1582
 
1595  
-                } else {
  1583
+                // Check this isn't an eol instruction to skip...
  1584
+                if ( $this->skipEolKey != $key ) {
  1585
+                    // Look to see if the next instruction is an EOL
  1586
+                    if ( isset($calls[$key+1]) && $calls[$key+1][0] == 'eol' ) {
1596 1587
 
1597  
-                    $storeCall = true;
1598  
-                    if ( $this->inParagraph && (in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open))) {
1599  
-                        $this->closeParagraph($call[2]);
1600  
-                        $this->calls[] = $call;
1601  
-                        $storeCall = false;
1602  
-                    }
1603  
-
1604  
-                    if ( in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) {
1605 1588
                         if ( $this->inParagraph ) {
1606 1589
                             $this->closeParagraph($call[2]);
1607 1590
                         }
1608  
-                        if ( $storeCall ) {
1609  
-                            $this->calls[] = $call;
1610  
-                            $storeCall = false;
1611  
-                        }
1612  
-
1613  
-                        // This really sucks and suggests this whole class sucks but...
1614  
-                        if ( isset($calls[$key+1])) {
1615  
-                            $cname_plusone = $calls[$key+1][0];
1616  
-                            if ($cname_plusone == 'plugin') {
1617  
-                                $cname_plusone = 'plugin'.$calls[$key+1][1][0];
1618  
-
1619  
-                                // plugin test, true if plugin has a state which precludes it requiring blockOpen or blockClose
1620  
-                                $plugin_plusone = true;
1621  
-                                $plugin_test = ($call[$key+1][1][2] == DOKU_LEXER_MATCHED) || ($call[$key+1][1][2] == DOKU_LEXER_MATCHED);
1622  
-                            } else {
1623  
-                                $plugin_plusone = false;
1624  
-                            }
1625  
-                            if ((!in_array($cname_plusone, $this->blockOpen) && !in_array($cname_plusone, $this->blockClose)) ||
1626  
-                                ($plugin_plusone && $plugin_test)
1627  
-                                ) {
1628  
-
1629  
-                                $this->calls[] = array('p_open',array(), $call[2]);
1630  
-                                $this->inParagraph = true;
1631  
-                            }
1632  
-                        }
1633  
-                    }
1634  
-
1635  
-                    if ( $storeCall ) {
1636  
-                        $this->addCall($call);
  1591
+                        $this->openParagraph($call[2]);
  1592
+                        // Mark the next instruction for skipping
  1593
+                        $this->skipEolKey = $key+1;
  1594
+                    } else {
  1595
+                        //if this is just a single eol make a space from it
  1596
+                        $this->addCall(array('cdata',array(DOKU_PARSER_EOL), $call[2]));
1637 1597
                     }
1638  
-
  1598
+                } else {
  1599
+                    $this->skipEolKey = $key+1;
1639 1600
                 }
1640 1601
 
1641 1602
 
1642 1603
             } else {
1643 1604
 
1644  
-                // Unless there's already a block at the start, start a paragraph
1645  
-                if ( !in_array($cname,$this->blockOpen) ) {
1646  
-                    $this->calls[] = array('p_open',array(), $call[2]);
1647  
-                    if ( $call[0] != 'eol' ) {
  1605
+                $storeCall = true;
  1606
+                if ( $this->inParagraph && (in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open))) {
  1607
+                    $this->closeParagraph($call[2]);
  1608
+                    $this->calls[] = $call;
  1609
+                    $storeCall = false;
  1610
+                    // Mark next eol(s) for skipping
  1611
+                    $this->skipEolKey = $key+1;
  1612
+                }
  1613
+
  1614
+                if ( in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) {
  1615
+                    if ( $this->inParagraph ) {
  1616
+                        $this->closeParagraph($call[2]);
  1617
+                    }
  1618
+                    if ( $storeCall ) {
1648 1619
                         $this->calls[] = $call;
  1620
+                        $storeCall = false;
1649 1621
                     }
1650  
-                    $this->atStart = false;
1651  
-                    $this->inParagraph = true;
1652  
-                } else {
  1622
+                    $this->openParagraph($call[2]);
  1623
+                    // Mark next eol(s) for skipping
  1624
+                    $this->skipEolKey = $key+1;
  1625
+                }
  1626
+                if ( $storeCall ) {
1653 1627
                     $this->addCall($call);
1654  
-                    $this->atStart = false;
1655 1628
                 }
1656  
-
1657 1629
             }
1658 1630
 
1659 1631
         }
1660 1632
 
1661 1633
         if ( $this->inParagraph ) {
  1634
+            $call = end($this->calls);
  1635
+            $cname = $call[0];
1662 1636
             if ( $cname == 'p_open' ) {
1663 1637
                 // Ditch the last call
1664 1638
                 array_pop($this->calls);

0 notes on commit b5a0b13

Please sign in to comment.
Something went wrong with that request. Please try again.