1<?php 2 3use dokuwiki\Extension\SyntaxPlugin; 4 5/** 6 * Info Indexmenu tag: Tag a page with a sort number. 7 * 8 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 9 * @author Samuele Tognini <samuele@samuele.netsons.org> 10 * 11 */ 12/** 13 * All DokuWiki plugins to extend the parser/rendering mechanism 14 * need to inherit from this class 15 */ 16class syntax_plugin_indexmenu_tag extends SyntaxPlugin 17{ 18 /** 19 * What kind of syntax are we? 20 */ 21 public function getType() 22 { 23 return 'substition'; 24 } 25 26 /** 27 * Where to sort in? 28 */ 29 public function getSort() 30 { 31 return 139; 32 } 33 34 /** 35 * Connect pattern to lexer 36 * 37 * @param string $mode 38 */ 39 public function connectTo($mode) 40 { 41 $this->Lexer->addSpecialPattern('{{indexmenu_n>.+?}}', $mode, 'plugin_indexmenu_tag'); 42 } 43 44 /** 45 * Handle the match 46 * 47 * @param string $match The text matched by the patterns 48 * @param int $state The lexer state for the match 49 * @param int $pos The character position of the matched text 50 * @param Doku_Handler $handler The Doku_Handler object 51 * @return array Return an array with all data you want to use in render 52 */ 53 public function handle($match, $state, $pos, Doku_Handler $handler) 54 { 55 $match = substr($match, 14, -2); 56 $match = str_replace("\xE2\x80\x8B", "", $match); 57 return [$match]; 58 } 59 60 /** 61 * Render output 62 * 63 * @param string $format output format being rendered 64 * @param Doku_Renderer $renderer the current renderer object 65 * @param array $data data created by handler() 66 */ 67 public function render($format, Doku_Renderer $renderer, $data) 68 { 69 if ($format == 'metadata') { 70 /** @var Doku_Renderer_metadata $renderer */ 71 if (is_numeric($data[0])) { 72 $renderer->meta['indexmenu_n'] = $data[0]; 73 } 74 } 75 } 76} 77