From d74aace9ed8079a5a2430f3c0cc56ff39934279b Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 28 Jul 2005 02:55:22 +0200 Subject: footnote fix: almagamate identical footnotes, insitu footnote popups darcs-hash:20050728005522-50fdc-f359021d5bcf602c2c403d37852196d5eeb4d473.gz --- inc/parser/xhtml.php | 59 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 12 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 81f0b2dca..2fd5844d0 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -51,8 +51,34 @@ class Doku_Renderer_xhtml extends Doku_Renderer { if ( count ($this->footnotes) > 0 ) { $this->doc .= '
'.DOKU_LF; + + $id = 0; foreach ( $this->footnotes as $footnote ) { - $this->doc .= $footnote; + $id++; // the number of the current footnote + + // check its not a placeholder that indicates actual footnote text is elsewhere + if (substr($footnote, 0, 5) != "@@FNT") { + + // open the footnote and set the anchor and backlink + $this->doc .= '
'; + $this->doc .= ''; + $this->doc .= $id.') '.DOKU_LF; + + // get any other footnotes that use the same markup + $alt = array_keys($this->footnotes, "@@FNT$id"); + + if (count($alt)) { + foreach ($alt as $ref) { + // set anchor and backlink for the other footnotes + $this->doc .= ', '; + $this->doc .= ($ref+1).') '.DOKU_LF; + } + } + + // add footnote markup and close this footnote + $this->doc .= $footnote; + $this->doc .= '
' . DOKU_LF; + } } $this->doc .= '
'.DOKU_LF; } @@ -209,23 +235,16 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * Callback for footnote start syntax * * All following content will go to the footnote instead of - * the document. To achive this the previous rendered content + * the document. To achieve this the previous rendered content * is moved to $store and $doc is cleared * * @author Andreas Gohr */ function footnote_open() { - #$id = $this->_newFootnoteId(); - $id = count($this->footnotes)+1; - $this->doc .= ''.$id.')'; // move current content to store and record footnote $this->store = $this->doc; $this->doc = ''; - - $this->doc .= '
'; - $this->doc .= ''; - $this->doc .= $id.') '.DOKU_LF; } /** @@ -237,12 +256,28 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * @author Andreas Gohr */ function footnote_close() { - $this->doc .= '
' . DOKU_LF; - // put recorded footnote into the stack and restore old content - $this->footnotes[count($this->footnotes)] = $this->doc; + // recover footnote into the stack and restore old content + $footnote = $this->doc; $this->doc = $this->store; $this->store = ''; + + // check to see if this footnote has been seen before + $i = array_search($footnote, $this->footnotes); + + if ($i === false) { + // its a new footnote, add it to the $footnotes array + $id = count($this->footnotes)+1; + $this->footnotes[count($this->footnotes)] = $footnote; + } else { + // seen this one before, translate the index to an id and save a placeholder + $i++; + $id = count($this->footnotes)+1; + $this->footnotes[count($this->footnotes)] = "@@FNT".($i); + } + + // output the footnote reference and link, incl. onmouseover for insitu footnote popup + $this->doc .= ''.$id.')'; } function listu_open() { -- cgit v1.2.3