1<?php 2/** 3* DokuWiki Plugin dirtylittlehelper (Syntax Component) 4* 5* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6* @author KalleAPunkt 7*/ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) { 11die(); 12} 13 14class syntax_plugin_dirtylittlehelper_divhtml extends DokuWiki_Syntax_Plugin 15{ 16 var $dlh_handle = ''; 17 18 /** 19 * @return string Syntax mode type 20 */ 21 public function getType() 22 { 23 return 'substition'; 24 } 25 26 /** 27 * @return string Paragraph type 28 */ 29 public function getPType() 30 { 31 return 'normal'; 32 } 33 34 /** 35 * @return int Sort order - Low numbers go before high numbers 36 */ 37 public function getSort() 38 { 39 return 150; 40 } 41 42 /** 43 * Connect lookup pattern to lexer. 44 * 45 * @param string $mode Parser mode 46 */ 47 public function connectTo($mode) 48 { 49 $this->Lexer->addEntryPattern('\<dlh\.div\.html[^\>]*\>',$mode,'plugin_dirtylittlehelper_'.$this->getPluginComponent()); 50 } 51 52 53 public function postConnect() 54 { 55 $this->Lexer->addExitPattern('\<\/dlh\.div\.html\>','plugin_dirtylittlehelper_'.$this->getPluginComponent()); 56 57 } 58 59 60 61 62 /** 63 * Handle matches of the DLH syntax 64 * 65 * @param string $match The match of the syntax 66 * @param int $state The state of the handler 67 * @param int $pos The position in the document 68 * @param Doku_Handler $handler The handler 69 * 70 * @return array Data for the renderer 71 */ 72 public function handle($match, $state, $pos, Doku_Handler $handler) 73 { 74 75 switch ($state) { 76 77 case DOKU_LEXER_ENTER: 78 if( substr($match,0,3) =='<dl'){ 79 return array($state, 'BEGIN',$match); 80 } 81 82 case DOKU_LEXER_UNMATCHED : 83 return array($state, 'UNMATCHED', $match); 84 85 case DOKU_LEXER_EXIT : 86 if( substr($match,0,3) =='</d'){ 87 return array($state, '/END',$match); 88 } 89 } 90 return false; 91 92 } //handle 93 94 95 /** 96 * Render xhtml output or metadata 97 * 98 * @param string $mode Renderer mode (supported modes: xhtml) 99 * @param Doku_Renderer $renderer The renderer 100 * @param array $data The data from the handler() function 101 * 102 * @return bool If rendering was successful. 103 */ 104 public function render($mode, Doku_Renderer $renderer, $data) 105 { 106 if ($mode == 'xhtml') { 107 108 if($data[1]=='BEGIN'){ 109 // securityLevel loose allows more advanced functionality such as subgraphs to run. 110 // @todo: this should be an option in the interface. 111 $renderer->doc .= str_replace('<dlh.div.html','<div',$data[2]);; 112 return true; 113 114 }elseif($data[1]=='/END'){ 115 $renderer->doc .= "</div>"; 116 return true; 117 118 119 }elseif($data[1]=='UNMATCHED'){ 120 $renderer->doc .= $data[2]; 121 return true; 122 } 123 124 return false; 125 126 127 } //mode xhtml 128 129 return false; 130 131 } //function render 132 133 134} //class 135 136 137 138 139 140 141