summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorChris Smith <chris.eureka@jalakai.co.uk>2008-03-12 01:02:48 +0100
committerChris Smith <chris.eureka@jalakai.co.uk>2008-03-12 01:02:48 +0100
commit41624b31db8cad77ed1ee250631162613a1ca22b (patch)
tree1e6dc1b203282a0adffe4a3415e82d874158ba65 /inc
parent630e442cc677b713c16df6060adfe9107160ff6b (diff)
downloadrpg-41624b31db8cad77ed1ee250631162613a1ca22b.tar.gz
rpg-41624b31db8cad77ed1ee250631162613a1ca22b.tar.bz2
Update handler to merge consecutive 'cdata' instructions (incl. test case updates)
This patch is the second in the series designed to make it easier for DW to allow plugins to modify the standard handling of line-breaks. Like the first this patch doesn't alter line-break behaviour at all, but introduces improvements that reduce to a minimum the number of 'cdata' instructions generated by the handler. darcs-hash:20080312000248-f07c6-f6ce1b5aac43a52cbe31215c517b048679ae20a7.gz
Diffstat (limited to 'inc')
-rw-r--r--inc/parser/handler.php32
1 files changed, 27 insertions, 5 deletions
diff --git a/inc/parser/handler.php b/inc/parser/handler.php
index 9011554bc..61c143bae 100644
--- a/inc/parser/handler.php
+++ b/inc/parser/handler.php
@@ -789,9 +789,24 @@ class Doku_Handler_Nest {
}
function process() {
+ // merge consecutive cdata
+ $unmerged_calls = $this->calls;
+ $this->calls = array();
+
+ foreach ($unmerged_calls as $call) $this->addCall($call);
+
$first_call = reset($this->calls);
$this->CallWriter->writeCall(array("nest", array($this->calls), $first_call[2]));
}
+
+ function addCall($call) {
+ $key = count($this->calls);
+ if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) {
+ $this->calls[$key-1][1][0] .= $call[1][0];
+ } else {
+ $this->calls[] = $call;
+ }
+ }
}
class Doku_Handler_List {
@@ -1060,7 +1075,6 @@ class Doku_Handler_Quote {
// Probably not needed but just in case...
function writeCalls($calls) {
$this->calls = array_merge($this->calls, $calls);
-# $this->CallWriter->writeCalls($this->calls);
}
function finalise() {
@@ -1156,7 +1170,6 @@ class Doku_Handler_Table {
// Probably not needed but just in case...
function writeCalls($calls) {
$this->calls = array_merge($this->calls, $calls);
-# $this->CallWriter->writeCalls($this->calls);
}
function finalise() {
@@ -1577,7 +1590,7 @@ class Doku_Handler_Block {
}else{
//if this is just a single eol make a space from it
- $this->calls[] = array('cdata',array(DOKU_PARSER_EOL), $call[2]);
+ $this->addCall(array('cdata',array(DOKU_PARSER_EOL), $call[2]));
}
}
@@ -1623,7 +1636,7 @@ class Doku_Handler_Block {
}
if ( $storeCall ) {
- $this->calls[] = $call;
+ $this->addCall($call);
}
}
@@ -1640,7 +1653,7 @@ class Doku_Handler_Block {
$this->atStart = false;
$this->inParagraph = true;
} else {
- $this->calls[] = $call;
+ $this->addCall($call);
$this->atStart = false;
}
@@ -1677,6 +1690,15 @@ class Doku_Handler_Block {
$this->atStart = $state[0];
$this->inParagraph = $state[1];
}
+
+ function addCall($call) {
+ $key = count($this->calls);
+ if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) {
+ $this->calls[$key-1][1][0] .= $call[1][0];
+ } else {
+ $this->calls[] = $call;
+ }
+ }
}
//Setup VIM: ex: et ts=4 enc=utf-8 :