summaryrefslogtreecommitdiff
path: root/inc/parser
diff options
context:
space:
mode:
authorDanny Lin <danny0838@pchome.com.tw>2011-01-26 08:33:01 +0800
committerDanny Lin <danny0838@pchome.com.tw>2011-01-26 08:33:01 +0800
commitb5a0b131e99eb6028e5ca5fed9c798982cdfe168 (patch)
treebb169eb648feed020129b348b5352f596625021e /inc/parser
parent08162f005f3ced0555de590dc1a53155af99d998 (diff)
downloadrpg-b5a0b131e99eb6028e5ca5fed9c798982cdfe168.tar.gz
rpg-b5a0b131e99eb6028e5ca5fed9c798982cdfe168.tar.bz2
First attempt to improve rewrite blocks; also eliminates post-paragraph starting single linebreaks.
Diffstat (limited to 'inc/parser')
-rw-r--r--inc/parser/handler.php124
1 files changed, 49 insertions, 75 deletions
diff --git a/inc/parser/handler.php b/inc/parser/handler.php
index 4d0b56b44..3bd3a3b3c 100644
--- a/inc/parser/handler.php
+++ b/inc/parser/handler.php
@@ -1489,6 +1489,11 @@ class Doku_Handler_Block {
}
}
+ function openParagraph($pos){
+ $this->calls[] = array('p_open',array(), $pos);
+ $this->inParagraph = true;
+ }
+
/**
* Close a paragraph if needed
*
@@ -1548,7 +1553,7 @@ class Doku_Handler_Block {
$this->closeParagraph($call[2]);
}
$this->calls[] = $call;
-
+ $this->skipEolKey = $key+1;
continue;
}
@@ -1561,104 +1566,73 @@ class Doku_Handler_Block {
if ($this->removeFromStack()) {
$this->calls[] = array('p_open',array(), $call[2]);
}
+ $this->skipEolKey = $key+1;
continue;
}
- if ( !$this->atStart ) {
-
- if ( $cname == 'eol' ) {
-
- // Check this isn't an eol instruction to skip...
- if ( $this->skipEolKey != $key ) {
- // Look to see if the next instruction is an EOL
- if ( isset($calls[$key+1]) && $calls[$key+1][0] == 'eol' ) {
-
- if ( $this->inParagraph ) {
- //$this->calls[] = array('p_close',array(), $call[2]);
- $this->closeParagraph($call[2]);
- }
-
- $this->calls[] = array('p_open',array(), $call[2]);
- $this->inParagraph = true;
-
-
- // Mark the next instruction for skipping
- $this->skipEolKey = $key+1;
-
- }else{
- //if this is just a single eol make a space from it
- $this->addCall(array('cdata',array(DOKU_PARSER_EOL), $call[2]));
- }
- }
+ // Always opens a paragraph on stack start
+ // If this is a block start, it will soon be closed later
+ if ( $this->atStart ) {
+ $this->openParagraph($call[2]);
+ $this->atStart = false;
+ $this->skipEolKey = $key;
+ }
+ if ( $cname == 'eol' ) {
- } else {
+ // Check this isn't an eol instruction to skip...
+ if ( $this->skipEolKey != $key ) {
+ // Look to see if the next instruction is an EOL
+ if ( isset($calls[$key+1]) && $calls[$key+1][0] == 'eol' ) {
- $storeCall = true;
- if ( $this->inParagraph && (in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open))) {
- $this->closeParagraph($call[2]);
- $this->calls[] = $call;
- $storeCall = false;
- }
-
- if ( in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) {
if ( $this->inParagraph ) {
$this->closeParagraph($call[2]);
}
- if ( $storeCall ) {
- $this->calls[] = $call;
- $storeCall = false;
- }
-
- // This really sucks and suggests this whole class sucks but...
- if ( isset($calls[$key+1])) {
- $cname_plusone = $calls[$key+1][0];
- if ($cname_plusone == 'plugin') {
- $cname_plusone = 'plugin'.$calls[$key+1][1][0];
-
- // plugin test, true if plugin has a state which precludes it requiring blockOpen or blockClose
- $plugin_plusone = true;
- $plugin_test = ($call[$key+1][1][2] == DOKU_LEXER_MATCHED) || ($call[$key+1][1][2] == DOKU_LEXER_MATCHED);
- } else {
- $plugin_plusone = false;
- }
- if ((!in_array($cname_plusone, $this->blockOpen) && !in_array($cname_plusone, $this->blockClose)) ||
- ($plugin_plusone && $plugin_test)
- ) {
-
- $this->calls[] = array('p_open',array(), $call[2]);
- $this->inParagraph = true;
- }
- }
- }
-
- if ( $storeCall ) {
- $this->addCall($call);
+ $this->openParagraph($call[2]);
+ // Mark the next instruction for skipping
+ $this->skipEolKey = $key+1;
+ } else {
+ //if this is just a single eol make a space from it
+ $this->addCall(array('cdata',array(DOKU_PARSER_EOL), $call[2]));
}
-
+ } else {
+ $this->skipEolKey = $key+1;
}
} else {
- // Unless there's already a block at the start, start a paragraph
- if ( !in_array($cname,$this->blockOpen) ) {
- $this->calls[] = array('p_open',array(), $call[2]);
- if ( $call[0] != 'eol' ) {
+ $storeCall = true;
+ if ( $this->inParagraph && (in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open))) {
+ $this->closeParagraph($call[2]);
+ $this->calls[] = $call;
+ $storeCall = false;
+ // Mark next eol(s) for skipping
+ $this->skipEolKey = $key+1;
+ }
+
+ if ( in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) {
+ if ( $this->inParagraph ) {
+ $this->closeParagraph($call[2]);
+ }
+ if ( $storeCall ) {
$this->calls[] = $call;
+ $storeCall = false;
}
- $this->atStart = false;
- $this->inParagraph = true;
- } else {
+ $this->openParagraph($call[2]);
+ // Mark next eol(s) for skipping
+ $this->skipEolKey = $key+1;
+ }
+ if ( $storeCall ) {
$this->addCall($call);
- $this->atStart = false;
}
-
}
}
if ( $this->inParagraph ) {
+ $call = end($this->calls);
+ $cname = $call[0];
if ( $cname == 'p_open' ) {
// Ditch the last call
array_pop($this->calls);