1<?php 2 3// implementation of 4// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/cite 5 6// must be run within Dokuwiki 7use ComboStrap\PluginUtility; 8use ComboStrap\TagAttributes; 9 10require_once(__DIR__ . '/../ComboStrap/StringUtility.php'); 11 12if (!defined('DOKU_INC')) die(); 13 14 15class syntax_plugin_combo_cite extends DokuWiki_Syntax_Plugin 16{ 17 const TAG = "cite"; 18 19 20 function getType() 21 { 22 return 'container'; 23 } 24 25 /** 26 * How Dokuwiki will add P element 27 * 28 * * 'normal' - The plugin can be used inside paragraphs 29 * * 'block' - Open paragraphs need to be closed before plugin output - block should not be inside paragraphs 30 * * 'stack' - Special case. Plugin wraps other paragraphs. - Stacks can contain paragraphs 31 * 32 * @see DokuWiki_Syntax_Plugin::getPType() 33 */ 34 function getPType() 35 { 36 return 'normal'; 37 } 38 39 /** 40 * @return array 41 * Allow which kind of plugin inside 42 * 43 * No one of array('baseonly','container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs') 44 * because we manage self the content and we call self the parser 45 * 46 * Return an array of one or more of the mode types {@link $PARSER_MODES} in Parser.php 47 */ 48 function getAllowedTypes() 49 { 50 return array('baseonly', 'container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); 51 } 52 53 function getSort() 54 { 55 /** 56 * Should be less than the cite syntax plugin 57 **/ 58 return 200; 59 } 60 61 62 function connectTo($mode) 63 { 64 65 $pattern = PluginUtility::getContainerTagPattern(self::TAG); 66 $this->Lexer->addEntryPattern($pattern, $mode, PluginUtility::getModeFromTag($this->getPluginComponent())); 67 68 } 69 70 71 function postConnect() 72 { 73 74 $this->Lexer->addExitPattern('</' . syntax_plugin_combo_cite::TAG . '>', PluginUtility::getModeFromTag($this->getPluginComponent())); 75 76 } 77 78 /** 79 * 80 * The handle function goal is to parse the matched syntax through the pattern function 81 * and to return the result for use in the renderer 82 * This result is always cached until the page is modified. 83 * @param string $match 84 * @param int $state 85 * @param int $pos - byte position in the original source file 86 * @param Doku_Handler $handler 87 * @return array|bool 88 * @see DokuWiki_Syntax_Plugin::handle() 89 * 90 */ 91 function handle($match, $state, $pos, Doku_Handler $handler) 92 { 93 94 switch ($state) { 95 96 case DOKU_LEXER_ENTER : 97 $attributes = TagAttributes::createFromTagMatch($match)->toCallStackArray(); 98 return array( 99 PluginUtility::STATE => $state, 100 PluginUtility::ATTRIBUTES => $attributes 101 ); 102 103 case DOKU_LEXER_UNMATCHED : 104 return PluginUtility::handleAndReturnUnmatchedData(self::TAG, $match, $handler); 105 106 case DOKU_LEXER_EXIT : 107 // Important otherwise we don't get an exit in the render 108 return array(PluginUtility::STATE => $state); 109 110 111 } 112 return array(); 113 114 } 115 116 /** 117 * Render the output 118 * @param string $format 119 * @param Doku_Renderer $renderer 120 * @param array $data - what the function handle() return'ed 121 * @return boolean - rendered correctly? (however, returned value is not used at the moment) 122 * @see DokuWiki_Syntax_Plugin::render() 123 * 124 * 125 */ 126 function render($format, Doku_Renderer $renderer, $data) 127 { 128 129 if ($format == 'xhtml') { 130 131 /** @var Doku_Renderer_xhtml $renderer */ 132 $state = $data [PluginUtility::STATE]; 133 switch ($state) { 134 case DOKU_LEXER_ENTER : 135 136 $attributes = $data[PluginUtility::ATTRIBUTES]; 137 $tagAttributes = TagAttributes::createFromCallStackArray($attributes, self::TAG); 138 $renderer->doc .= $tagAttributes->toHtmlEnterTag("cite"); 139 140 break; 141 142 case DOKU_LEXER_UNMATCHED : 143 $renderer->doc .= PluginUtility::renderUnmatched($data); 144 break; 145 146 case DOKU_LEXER_EXIT : 147 148 $renderer->doc .= '</cite>'; 149 break; 150 151 } 152 return true; 153 } 154 155 // unsupported $mode 156 return false; 157 } 158 159 160} 161 162