1<?php 2 3/** 4 * Plugin QnA: Header syntax 5 * 6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 7 * @author Mykola Ostrovskyy <dwpforge@gmail.com> 8 */ 9 10/* Must be run within Dokuwiki */ 11if(!defined('DOKU_INC')) die(); 12 13if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); 14require_once(DOKU_PLUGIN . 'syntax.php'); 15 16class syntax_plugin_qna_header extends DokuWiki_Syntax_Plugin { 17 18 private $mode; 19 20 /** 21 * Constructor 22 */ 23 public function __construct() { 24 $this->mode = substr(get_class($this), 7); 25 } 26 27 /** 28 * What kind of syntax are we? 29 */ 30 public function getType() { 31 return 'baseonly'; 32 } 33 34 public function getPType() { 35 return 'block'; 36 } 37 38 /** 39 * Where to sort in? 40 */ 41 public function getSort() { 42 return 50; 43 } 44 45 /** 46 * 47 */ 48 public function connectTo($mode) { 49 $this->Lexer->addSpecialPattern('[ \t]*=\?={1,4}[^=\n][^\n]+={3,}[ \t]*(?=\n)', $mode, $this->mode); 50 } 51 52 /** 53 * 54 */ 55 function handle($match, $state, $pos, Doku_Handler $handler) { 56 if ($state == DOKU_LEXER_SPECIAL) { 57 $match = preg_replace('/^(\s*=)\?/', '$1=', $match); 58 59 $handler->header($match, $state, $pos); 60 61 $data = array('dummy'); 62 } 63 else { 64 $data = false; 65 } 66 67 return $data; 68 } 69 70 /** 71 * 72 */ 73 function render($mode, Doku_Renderer $renderer, $data) { 74 if ($mode == 'xhtml') { 75 switch ($data[0]) { 76 case 'open': 77 $renderer->doc .= DOKU_LF . '<div class="qna-header">'; 78 break; 79 80 case 'close': 81 $renderer->doc .= '</div>' . DOKU_LF; 82 break; 83 } 84 85 return true; 86 } 87 elseif ($mode == 'metadata') { 88 if ($data[0] == 'open') { 89 $meta['title'] = $data[1]; 90 $meta['id'] = $data[2]; 91 $meta['level'] = $data[3]; 92 $meta['class'] = 'header'; 93 94 $renderer->meta['description']['tableofquestions'][] = $meta; 95 } 96 97 return true; 98 } 99 100 return false; 101 } 102} 103