Skip to content
Snippets Groups Projects
Commit 5587e44c authored by chris's avatar chris
Browse files

fix for bug #701, lists in footnotes in lists

added Doku_Handler_Nest class & "nest" render instruction
These allows render instructions to be nested within the "nest" render instruction,
isolating them from the outer list of render instructions.

Not being able to do this is a particular problem for the current Doku_Handler_* classes
as they process the list of intructions generated during their life without any recognition
that some of the instructions may not belong to them being nested within another syntax
mode.

This also makes it easier for plugins to generate cacheable nested instructions rather than
using the expensive p_render() function which has to create a new renderer.

darcs-hash:20060804220100-9b6ab-ccd051e287af45afacdb1efecb8d9beb376276cb.gz
parent 03c4aec3
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,7 @@ class Doku_Handler {
function _finalize(){
$this->CallWriter->finalise();
$this->CallWriter->finalise();
if ( $this->status['section'] ) {
$last_call = end($this->calls);
......@@ -191,7 +191,23 @@ class Doku_Handler {
function footnote($match, $state, $pos) {
$this->_nestingTag($match, $state, $pos, 'footnote');
// $this->_nestingTag($match, $state, $pos, 'footnote');
switch ( $state ) {
case DOKU_LEXER_ENTER:
$ReWriter = & new Doku_Handler_Nest($this->CallWriter,'footnote_close');
$this->CallWriter = & $ReWriter;
$this->_addCall('footnote_open', array($match), $pos);
break;
case DOKU_LEXER_EXIT:
$this->_addCall('footnote_close', array(), $pos);
$this->CallWriter->process();
$ReWriter = & $this->CallWriter;
$this->CallWriter = & $ReWriter->CallWriter;
break;
case DOKU_LEXER_UNMATCHED:
$this->_addCall('cdata', array($match), $pos);
break;
}
return TRUE;
}
......@@ -677,6 +693,54 @@ class Doku_Handler_CallWriter {
}
//------------------------------------------------------------------------
/**
* Generic call writer class to handle nesting of rendering instructions
* within a render instruction. Also see nest() method of renderer base class
*
* @author Chris Smith <chris@jalakai.co.uk>
*/
class Doku_Handler_Nest {
var $CallWriter;
var $calls = array();
var $closingInstruction;
/**
* constructor
*
* @param object $CallWriter the renderers current call writer
* @param string $close closing instruction name, this is required to properly terminate the
* syntax mode if the document ends without a closing pattern
*/
function Doku_Handler_Nest(& $CallWriter, $close="nest_close") {
$this->CallWriter = & $CallWriter;
$this->closingInstruction = $close;
}
function writeCall($call) {
$this->calls[] = $call;
}
function writeCalls($calls) {
$this->calls = array_merge($this->calls, $calls);
}
function finalise() {
$last_call = end($this->calls);
$this->writeCall(array($this->closingInstruction,array(), $last_call[2]));
$this->process();
$this->CallWriter->finalise();
}
function process() {
$first_call = reset($this->calls);
$this->CallWriter->writeCall(array("nest", array($this->calls), $first_call[2]));
}
}
class Doku_Handler_List {
var $CallWriter;
......
<?php
/**
* Renderer for XHTML output
* Renderer output base class
*
* @author Harry Fuecks <hfuecks@gmail.com>
* @author Andreas Gohr <andi@splitbrain.org>
......@@ -35,6 +35,23 @@ class Doku_Renderer {
}
}
/**
* handle nested render instructions
* this method (and nest_close method) should not be overloaded in actual renderer output classes
*/
function nest($instructions) {
foreach ( $instructions as $instruction ) {
// execute the callback against ourself
call_user_func_array(array(&$this, $instruction[0]),$instruction[1]);
}
}
// dummy closing instruction issued by Doku_Handler_Nest, normally the syntax mode should
// override this instruction when instantiating Doku_Handler_Nest - however plugins will not
// be able to - as their instructions require data.
function nest_close() {}
function document_start() {}
function document_end() {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment