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_details extends DokuWiki_Syntax_Plugin { 15 protected $entry_pattern = '<details(?:\s+open)?\s*?>(?=.*?</details>)'; 16 protected $exit_pattern = '</details>'; 17 18 /** 19 * @return string Syntax mode type 20 */ 21 public function getType() 22 { 23 return 'container'; 24 } 25 26 /** 27 * @param string $mode The mode to check 28 * @return bool Whether $mode is allowed within this mode 29 */ 30 31 function accepts($mode) { 32 if ($mode == substr(get_class($this), 7)) return true; 33 return parent::accepts($mode); 34 } 35 36 /** 37 * @return string|array(string) Allowed syntax mode types 38 */ 39 public function getAllowedTypes() 40 { 41 return array('container', 'baseonly', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); 42 } 43 44 /** 45 * @return string Paragraph type 46 */ 47 public function getPType() 48 { 49 return 'stack'; 50 } 51 52 /** 53 * @return int Sort order - Low numbers go before high numbers 54 */ 55 public function getSort() 56 { 57 return 195; // cf. Doku_Parser_Mode_html 190 58 } 59 60 /** 61 * Connect lookup pattern to lexer. 62 * 63 * @param string $mode Parser mode 64 */ 65 public function connectTo($mode) 66 { 67 $this->Lexer->addEntryPattern($this->entry_pattern, $mode, 'plugin_htmldetailstag_details'); 68 } 69 70 public function postConnect() 71 { 72 $this->Lexer->addExitPattern($this->exit_pattern, 'plugin_htmldetailstag_details'); 73 } 74 75 /** 76 * Handle matches of the htmldetailstag syntax 77 * 78 * @param string $match The match of the syntax 79 * @param int $state The state of the handler 80 * @param int $pos The position in the document 81 * @param Doku_Handler $handler The handler 82 * 83 * @return array Data for the renderer 84 */ 85 public function handle($match, $state, $pos, Doku_Handler $handler) 86 { 87 $data = array($match, $state); 88 return $data; 89 } 90 91 /** 92 * Render xhtml output or metadata 93 * 94 * @param string $mode Renderer mode (supported modes: xhtml) 95 * @param Doku_Renderer $renderer The renderer 96 * @param array $data The data from the handler() function 97 * 98 * @return bool If rendering was successful. 99 */ 100 public function render($mode, Doku_Renderer $renderer, $data) 101 { 102 if ($mode !== 'xhtml') { 103 return false; 104 } 105 106 list($match, $state) = $data; 107 switch ($state) { 108 case DOKU_LEXER_ENTER: 109 $renderer->doc .= $match; 110 break; 111 case DOKU_LEXER_UNMATCHED: 112 $renderer->doc .= $renderer->_xmlEntities($match); 113 break; 114 case DOKU_LEXER_EXIT: 115 $renderer->doc .= $match; 116 break; 117 } 118 return true; 119 } 120} 121 122