1<?php 2 3/** 4 * DokuWiki plugin Struct Template block syntax 5 * 6 * @author Iain Hallam <iain@nineworlds.net> 7 * @copyright © 2022 Iain Hallam 8 * @license GPL-2.0-only (http://www.gnu.org/licenses/gpl-2.0.html) 9 */ 10 11declare(strict_types=1); 12 13use dokuwiki\plugin\structtemplate\meta\StructTemplateSyntax; 14 15/** 16 * Syntax plugin extending common Struct Template base class 17 */ 18class syntax_plugin_structtemplate_block extends StructTemplateSyntax 19{ 20 /** 21 * Define how this plugin handles paragraphs 22 * 23 * @see https://www.dokuwiki.org/devel:syntax_plugins#ptype 24 */ 25 public function getPType() 26 { 27 return 'block'; 28 } 29 30 /** 31 * Connect lookup patterns to lexer 32 * 33 * @see https://www.dokuwiki.org/devel:syntax_plugins#patterns 34 * 35 * @param string $lmode Existing lexer mode 36 */ 37 public function connectTo($lmode) 38 { 39 // Syntax: 40 // <struct-template block> OR <STRUCT-TEMPLATE> 41 // ---- data ---- 42 // [...] 43 // ---- 44 // [...] 45 // </struct-template> OR </STRUCT-TEMPLATE> respectively 46 47 $re = '<' . self::TAG . ' +block\b.*?>\n' 48 . '----+ *data *----+\n' 49 . '.*?\n' 50 . '----+\n' 51 . '.*?\n' 52 . '<\/' . self::TAG . '>' 53 ; 54 $this->Lexer->addSpecialPattern( 55 $re, // regex 56 $lmode, // lexer mode to use in 57 'plugin_' . self::PLUGIN . '_block' // lexer mode to enter 58 ); 59 60 $re = '<' . strtoupper(self::TAG) . '\b.*?>\n' 61 . '----+ *data *----+\n' 62 . '.*?\n' 63 . '----+\n' 64 . '.*?\n' 65 . '<\/' . strtoupper(self::TAG) . '>' 66 ; 67 $this->Lexer->addSpecialPattern( 68 $re, // regex 69 $lmode, // lexer mode to use in 70 'plugin_' . self::PLUGIN . '_block' // lexer mode to enter 71 ); 72 } 73} 74