From 41624b31db8cad77ed1ee250631162613a1ca22b Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 12 Mar 2008 01:02:48 +0100 Subject: 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 --- inc/parser/handler.php | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'inc/parser/handler.php') 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 : -- cgit v1.2.3