1<?php 2/** 3 * Renderer to support header2 syntax 4 */ 5 6if(!defined('DOKU_INC')) die(); 7if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 8 9require_once DOKU_INC . 'inc/parser/xhtml.php'; 10 11/** 12 * The Renderer 13 */ 14class renderer_plugin_header2 extends Doku_Renderer_xhtml { 15 16 function canRender($format) { 17 // Only needed in previous wiki versions for compatibility 18 global $updateVersion; 19 if ($updateVersion>=38) return false; 20 21 return ($format=='xhtml'); 22 } 23 24 /** 25 * $sectionedits is private and cannot be accessed by plugins, 26 * so this dirty hack is required 27 * 28 * Get rid of this renderer if it's fixed... 29 */ 30 public $sectionedits = array(); // A stack of section edit data 31 32 /** 33 * Copied from xhtml.php, no change 34 */ 35 public function startSectionEdit($start, $type, $title = null) { 36 static $lastsecid = 0; 37 $this->sectionedits[] = array(++$lastsecid, $start, $type, $title); 38 return 'sectionedit' . $lastsecid; 39 } 40 41 public function finishSectionEdit($end = null) { 42 list($id, $start, $type, $title) = array_pop($this->sectionedits); 43 if (!is_null($end) && $end <= $start) { 44 return; 45 } 46 $this->doc .= "<!-- EDIT$id " . strtoupper($type) . ' '; 47 if (!is_null($title)) { 48 $this->doc .= '"' . str_replace('"', '', $title) . '" '; 49 } 50 $this->doc .= "[$start-" . (is_null($end) ? '' : $end) . '] -->'; 51 } 52 53 function document_end() { 54 // Finish open section edits. 55 while (count($this->sectionedits) > 0) { 56 if ($this->sectionedits[count($this->sectionedits) - 1][1] <= 1) { 57 // If there is only one section, do not write a section edit 58 // marker. 59 array_pop($this->sectionedits); 60 } else { 61 $this->finishSectionEdit(); 62 } 63 } 64 65 if ( count ($this->footnotes) > 0 ) { 66 $this->doc .= '<div class="footnotes">'.DOKU_LF; 67 68 $id = 0; 69 foreach ( $this->footnotes as $footnote ) { 70 $id++; // the number of the current footnote 71 72 // check its not a placeholder that indicates actual footnote text is elsewhere 73 if (substr($footnote, 0, 5) != "@@FNT") { 74 75 // open the footnote and set the anchor and backlink 76 $this->doc .= '<div class="fn">'; 77 $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" name="fn__'.$id.'" class="fn_bot">'; 78 $this->doc .= $id.')</a></sup> '.DOKU_LF; 79 80 // get any other footnotes that use the same markup 81 $alt = array_keys($this->footnotes, "@@FNT$id"); 82 83 if (count($alt)) { 84 foreach ($alt as $ref) { 85 // set anchor and backlink for the other footnotes 86 $this->doc .= ', <sup><a href="#fnt__'.($ref+1).'" id="fn__'.($ref+1).'" name="fn__'.($ref+1).'" class="fn_bot">'; 87 $this->doc .= ($ref+1).')</a></sup> '.DOKU_LF; 88 } 89 } 90 91 // add footnote markup and close this footnote 92 $this->doc .= $footnote; 93 $this->doc .= '</div>' . DOKU_LF; 94 } 95 } 96 $this->doc .= '</div>'.DOKU_LF; 97 } 98 99 // Prepare the TOC 100 global $conf; 101 if($this->info['toc'] && is_array($this->toc) && $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']){ 102 global $TOC; 103 $TOC = $this->toc; 104 } 105 106 // make sure there are no empty paragraphs 107 $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc); 108 } 109} 110 111//Setup VIM: ex: et ts=4 enc=utf-8 : 112