1<?php 2 3/** 4 * DokuWiki Plugin latexit (Syntax Component) 5 * 6 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 7 * @author Andreas Gohr <gohr@cosmocode.de> 8 */ 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12/** 13 * Syntax component 14 * 15 * Allows per document reconfiguration 16 */ 17class syntax_plugin_latexit_config extends DokuWiki_Syntax_Plugin { 18 19 /** 20 * @return string Syntax mode type 21 */ 22 public function getType() { 23 return 'substition'; 24 } 25 26 /** 27 * @return int Sort order - Low numbers go before high numbers 28 */ 29 public function getSort() { 30 return 300; 31 } 32 33 /** 34 * Connect lookup pattern to lexer. 35 * 36 * @param string $mode Parser mode 37 */ 38 public function connectTo($mode) { 39 $this->Lexer->addSpecialPattern('{{latexit[:>].+?}}', $mode, 'plugin_latexit_config'); 40 } 41 42 /** 43 * Handle matches of the latexit syntax 44 * 45 * @param string $match The match of the syntax 46 * @param int $state The state of the handler 47 * @param int $pos The position in the document 48 * @param Doku_Handler $handler The handler 49 * @return array Data for the renderer 50 */ 51 public function handle($match, $state, $pos, Doku_Handler $handler) { 52 list($key, $val) = explode(' ', trim(substr($match, 10, -2)), 2); 53 $key = trim($key); 54 $val = trim($val); 55 56 return array($key, $val); 57 } 58 59 /** 60 * Store config in metadata 61 * 62 * @param string $mode Renderer mode (supported modes: xhtml) 63 * @param Doku_Renderer $renderer The renderer 64 * @param array $data The data from the handler() function 65 * @return bool If rendering was successful. 66 */ 67 public function render($mode, Doku_Renderer $renderer, $data) { 68 if($mode != 'metadata') return false; 69 70 list($key, $val) = $data; 71 $renderer->meta['plugin_latexit'][$key] = $val; 72 } 73}