1<?php 2 3 4require_once(__DIR__ . '/../vendor/autoload.php'); 5 6// must be run within Dokuwiki 7use ComboStrap\BlockquoteTag; 8use ComboStrap\HeadingTag; 9use ComboStrap\PluginUtility; 10use ComboStrap\XmlTagProcessing; 11 12 13/** 14 * The xml block tag (non-empty) pattern 15 */ 16class syntax_plugin_combo_xmlblocktag extends DokuWiki_Syntax_Plugin 17{ 18 /** 19 * Should be the same than the last name of the class 20 */ 21 const TAG = "xmlblocktag"; 22 23 24 /** 25 * The Syntax Type determines which syntax may be nested 26 * 27 * Needs to return one of the mode types defined in $PARSER_MODES in parser.php 28 * @see DokuWiki_Syntax_Plugin::getType() 29 * See https://www.dokuwiki.org/devel:syntax_plugins#syntax_types 30 */ 31 function getType(): string 32 { 33 /** 34 * Choice between container, formatting and substition 35 * 36 * Icon had 'substition' and can still have other mode inside (ie tooltip) 37 * We choose substition then 38 * 39 * For heading, title, it was `baseonly` because 40 * Heading disappear when a table is just before because the {@link HeadingTag::SYNTAX_TYPE} was `formatting` 41 * The table was then accepting it and was deleting it at completion because there was no end of cell character (ie `|`) 42 * 43 */ 44 return 'substition'; 45 } 46 47 /** 48 * @param string $mode 49 * @return bool 50 * Allowed type 51 */ 52 public function accepts($mode): bool 53 { 54 /** 55 * header mode is disable to take over 56 * and replace it with {@link syntax_plugin_combo_headingwiki} 57 */ 58 if ($mode == "header") { 59 return false; 60 } 61 62 return syntax_plugin_combo_preformatted::disablePreformatted($mode); 63 64 } 65 66 /** 67 * How Dokuwiki will add P element 68 * 69 * * 'normal' - Inline (dokuwiki will not close an ongoing p) 70 * * 'block' - Block (dokuwiki does not not create p inside and close an open p) 71 * * 'stack' - Block (dokuwiki create p inside) 72 * 73 * @see DokuWiki_Syntax_Plugin::getPType() 74 */ 75 function getPType(): string 76 { 77 /** 78 * Ptype is the driver of the {@link \dokuwiki\Parsing\Handler\Block::process()} 79 * that creates the P tag. 80 * 81 * Works with block and stack for now 82 * Not with `normal` as if dokuwiki has created a p 83 * and that is encounters a block, it will close the p inside the stack unfortunately 84 * (You can try with {@link BlockquoteTag} 85 * 86 * For box, not stack, otherwise it creates p 87 * and as box is used mostly for layout purpose, it breaks the 88 * {@link \ComboStrap\TagAttribute\Align} flex css attribute 89 * 90 * For Cardbody, block value was !important! as 91 * it will not create an extra paragraph after it encounters a block 92 * 93 * For {@link \ComboStrap\GridTag}, 94 * not stack, otherwise you get extra p's 95 * and it will fucked up the flex layout 96 */ 97 return 'block'; 98 } 99 100 /** 101 * @return array the kind of plugin that are allowed inside (ie an array of 102 * <a href="https://www.dokuwiki.org/devel:syntax_plugins#syntax_types">mode type</a> 103 * ie 104 * * array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs') 105 * * array of one or more of the mode types {@link $PARSER_MODES} in Parser.php 106 */ 107 public function getAllowedTypes(): array 108 { 109 /** 110 * Tweak: `paragraphs` is not in the allowed type 111 */ 112 return array('container', 'formatting', 'substition', 'protected', 'disabled'); 113 } 114 115 116 function getSort(): int 117 { 118 return 999; 119 } 120 121 122 function connectTo($mode) 123 { 124 125 // One pattern to not compete between pattern 126 // this pattern ensure that the tag 127 // (ie that `accordion` will not intercept also the tag `accordionitem`) 128 129 130 $pattern = XmlTagProcessing::START_TAG_PATTERN; 131 $this->Lexer->addEntryPattern($pattern, $mode, PluginUtility::getModeFromTag($this->getPluginComponent())); 132 133 } 134 135 public function postConnect() 136 { 137 138 $this->Lexer->addExitPattern('</[\w-]+>', PluginUtility::getModeFromTag($this->getPluginComponent())); 139 140 } 141 142 143 function handle($match, $state, $pos, Doku_Handler $handler): array 144 { 145 return XmlTagProcessing::handleStatic($match, $state, $pos, $handler, $this); 146 } 147 148 /** 149 * Render the output 150 * @param string $format 151 * @param Doku_Renderer $renderer 152 * @param array $data - what the function handle() return'ed 153 * @return boolean - rendered correctly? (however, returned value is not used at the moment) 154 * @see DokuWiki_Syntax_Plugin::render() 155 * 156 * 157 */ 158 function render($format, Doku_Renderer $renderer, $data): bool 159 { 160 161 return XmlTagProcessing::renderStatic($format, $renderer, $data, $this); 162 163 } 164 165 166} 167 168