summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inc/parser/handler.php68
-rw-r--r--inc/parser/renderer.php19
2 files changed, 84 insertions, 3 deletions
diff --git a/inc/parser/handler.php b/inc/parser/handler.php
index 602ef1b6d..612534eea 100644
--- a/inc/parser/handler.php
+++ b/inc/parser/handler.php
@@ -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;
diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php
index 931be6ceb..f9dcaab7b 100644
--- a/inc/parser/renderer.php
+++ b/inc/parser/renderer.php
@@ -1,6 +1,6 @@
<?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() {}