1<?php 2/** 3 * DokuWiki Plugin htmldetailstag (Syntax Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Sascha Klawohn <sideboard@revolutionarts.de> 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) { 11 die(); 12} 13 14class syntax_plugin_htmldetailstag_summary extends DokuWiki_Syntax_Plugin 15{ 16 /** 17 * @return string Syntax mode type 18 */ 19 public function getType() 20 { 21 return 'container'; 22 } 23 24 /** 25 * @return string|array(string) Allowed syntax mode types 26 */ 27 public function getAllowedTypes() 28 { 29 return array('container', 'baseonly', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); 30 } 31 32 /** 33 * @return string Paragraph type 34 */ 35 public function getPType() 36 { 37 return 'block'; 38 } 39 40 /** 41 * @return int Sort order - Low numbers go before high numbers 42 */ 43 public function getSort() 44 { 45 return 195; // cf. Doku_Parser_Mode_html 190 46 } 47 48 /** 49 * Connect lookup pattern to lexer. 50 * 51 * @param string $mode Parser mode 52 */ 53 public function connectTo($mode) 54 { 55 $this->Lexer->addEntryPattern('<summary>(?=.*?</summary>)', $mode, 'plugin_htmldetailstag_summary'); 56 } 57 58 public function postConnect() 59 { 60 $this->Lexer->addExitPattern('</summary>', 'plugin_htmldetailstag_summary'); 61 } 62 63 /** 64 * Handle matches of the htmldetailstag syntax 65 * 66 * @param string $match The match of the syntax 67 * @param int $state The state of the handler 68 * @param int $pos The position in the document 69 * @param Doku_Handler $handler The handler 70 * 71 * @return array Data for the renderer 72 */ 73 public function handle($match, $state, $pos, Doku_Handler $handler) 74 { 75 $data = array($match, $state); 76 return $data; 77 } 78 79 /** 80 * Render xhtml output or metadata 81 * 82 * @param string $mode Renderer mode (supported modes: xhtml) 83 * @param Doku_Renderer $renderer The renderer 84 * @param array $data The data from the handler() function 85 * 86 * @return bool If rendering was successful. 87 */ 88 public function render($mode, Doku_Renderer $renderer, $data) 89 { 90 if ($mode !== 'xhtml') { 91 return false; 92 } 93 94 list($match, $state) = $data; 95 switch ($state) { 96 case DOKU_LEXER_ENTER: 97 $renderer->doc .= "<summary>"; 98 break; 99 case DOKU_LEXER_UNMATCHED: 100 $renderer->doc .= $renderer->_xmlEntities($match); 101 break; 102 case DOKU_LEXER_EXIT: 103 $renderer->doc .= "</summary>"; 104 break; 105 } 106 return true; 107 } 108} 109 110