1<?php 2 3 4// must be run within Dokuwiki 5use ComboStrap\CallStack; 6use ComboStrap\Dimension; 7use ComboStrap\PluginUtility; 8use ComboStrap\TagAttributes; 9 10if (!defined('DOKU_INC')) die(); 11 12/** 13 * Class syntax_plugin_combo_text 14 * A text block that permits to style 15 * paragraph at once 16 * 17 * The output will be a series of {@link syntax_plugin_combo_para paragraph} 18 * with the same properties 19 * 20 * It permits to have several paragraph 21 */ 22class syntax_plugin_combo_text extends DokuWiki_Syntax_Plugin 23{ 24 25 const TAG = "text"; 26 const TAGS = ["typo", self::TAG]; 27 28 /** 29 * Syntax Type. 30 * 31 * Needs to return one of the mode types defined in {@link $PARSER_MODES} in parser.php 32 * @see DokuWiki_Syntax_Plugin::getType() 33 */ 34 function getType() 35 { 36 return 'paragraphs'; 37 } 38 39 /** 40 * How Dokuwiki will add P element 41 * 42 * * 'normal' - The plugin can be used inside paragraphs 43 * * 'block' - Open paragraphs need to be closed before plugin output - block should not be inside paragraphs 44 * * 'stack' - Special case. Plugin wraps other paragraphs. - Stacks can contain paragraphs 45 * 46 * @see DokuWiki_Syntax_Plugin::getPType() 47 */ 48 function getPType() 49 { 50 return 'stack'; 51 } 52 53 /** 54 * @return array 55 * Allow which kind of plugin inside 56 * 57 * No one of array('baseonly','container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs') 58 * because we manage self the content and we call self the parser 59 * 60 * Return an array of one or more of the mode types {@link $PARSER_MODES} in Parser.php 61 */ 62 function getAllowedTypes() 63 { 64 return array('formatting', 'substition', 'paragraphs'); 65 } 66 67 public function accepts($mode) 68 { 69 70 return syntax_plugin_combo_preformatted::disablePreformatted($mode); 71 72 } 73 74 75 function getSort() 76 { 77 return 201; 78 } 79 80 81 function connectTo($mode) 82 { 83 84 foreach (self::TAGS as $tag) { 85 $pattern = PluginUtility::getContainerTagPattern($tag); 86 $this->Lexer->addEntryPattern($pattern, $mode, PluginUtility::getModeFromTag($this->getPluginComponent())); 87 } 88 } 89 90 91 function postConnect() 92 { 93 foreach (self::TAGS as $tag) { 94 $this->Lexer->addExitPattern('</' . $tag . '>', PluginUtility::getModeFromTag($this->getPluginComponent())); 95 } 96 97 } 98 99 function handle($match, $state, $pos, Doku_Handler $handler) 100 { 101 102 switch ($state) { 103 104 case DOKU_LEXER_ENTER : 105 $attributes = TagAttributes::createFromTagMatch($match); 106 $callStackArray = $attributes->toCallStackArray(); 107 108 return array( 109 PluginUtility::STATE => $state, 110 PluginUtility::ATTRIBUTES => $callStackArray 111 ); 112 113 case DOKU_LEXER_UNMATCHED : 114 return PluginUtility::handleAndReturnUnmatchedData(self::TAG, $match, $handler); 115 116 case DOKU_LEXER_EXIT : 117 /** 118 * Transform all paragraphs 119 * with the type as class 120 */ 121 $callStack = CallStack::createFromHandler($handler); 122 $openingCall = $callStack->moveToPreviousCorrespondingOpeningCall(); 123 $attributes = $openingCall->getAttributes(); 124 // if there is no EOL, we add one to create at minimal a paragraph 125 $callStack->insertEolIfNextCallIsNotEolOrBlock(); 126 $callStack->processEolToEndStack($attributes); 127 128 /** 129 * Check and add a scroll toggle if the 130 * text is constrained by height 131 */ 132 Dimension::addScrollToggleOnClickIfNoControl($callStack); 133 134 return array(PluginUtility::STATE => $state); 135 136 137 } 138 return array(); 139 140 } 141 142 /** 143 * Render the output 144 * @param string $format 145 * @param Doku_Renderer $renderer 146 * @param array $data - what the function handle() return'ed 147 * @return boolean - rendered correctly? (however, returned value is not used at the moment) 148 * @see DokuWiki_Syntax_Plugin::render() 149 * 150 * 151 */ 152 function render($format, Doku_Renderer $renderer, $data) 153 { 154 if ($format == 'xhtml') { 155 156 /** @var Doku_Renderer_xhtml $renderer */ 157 $state = $data[PluginUtility::STATE]; 158 switch ($state) { 159 case DOKU_LEXER_EXIT : 160 case DOKU_LEXER_ENTER : 161 /** 162 * The {@link DOKU_LEXER_EXIT} of the {@link syntax_plugin_combo_text::handle()} 163 * has already created in the callstack the {@link syntax_plugin_combo_para} call 164 */ 165 $renderer->doc .= ""; 166 break; 167 case DOKU_LEXER_UNMATCHED : 168 $renderer->doc .= PluginUtility::renderUnmatched($data); 169 break; 170 } 171 return true; 172 } 173 174 // unsupported $mode 175 return false; 176 } 177 178 179} 180 181