1be906b56SAndreas Gohr<?php 2be906b56SAndreas Gohr 3be906b56SAndreas Gohrnamespace dokuwiki\Parsing\ParserMode; 4be906b56SAndreas Gohr 5*71096e46SAndreas Gohruse dokuwiki\Parsing\Handler; 6*71096e46SAndreas Gohr 7be906b56SAndreas Gohrclass Header extends AbstractMode 8be906b56SAndreas Gohr{ 9be906b56SAndreas Gohr /** @inheritdoc */ 10*71096e46SAndreas Gohr public function getSort() 11*71096e46SAndreas Gohr { 12*71096e46SAndreas Gohr return 50; 13*71096e46SAndreas Gohr } 14*71096e46SAndreas Gohr 15*71096e46SAndreas Gohr /** @inheritdoc */ 16be906b56SAndreas Gohr public function connectTo($mode) 17be906b56SAndreas Gohr { 18be906b56SAndreas Gohr //we're not picky about the closing ones, two are enough 19be906b56SAndreas Gohr $this->Lexer->addSpecialPattern( 20be906b56SAndreas Gohr '[ \t]*={2,}[^\n]+={2,}[ \t]*(?=\n)', 21be906b56SAndreas Gohr $mode, 22be906b56SAndreas Gohr 'header' 23be906b56SAndreas Gohr ); 24be906b56SAndreas Gohr } 25be906b56SAndreas Gohr 26be906b56SAndreas Gohr /** @inheritdoc */ 27*71096e46SAndreas Gohr public function handle($match, $state, $pos, Handler $handler) 28be906b56SAndreas Gohr { 29*71096e46SAndreas Gohr // get level and title 30*71096e46SAndreas Gohr $title = trim($match); 31*71096e46SAndreas Gohr $level = 7 - strspn($title, '='); 32*71096e46SAndreas Gohr if ($level < 1) $level = 1; 33*71096e46SAndreas Gohr $title = trim($title, '='); 34*71096e46SAndreas Gohr $title = trim($title); 35*71096e46SAndreas Gohr 36*71096e46SAndreas Gohr if ($handler->getStatus('section')) $handler->addCall('section_close', [], $pos); 37*71096e46SAndreas Gohr 38*71096e46SAndreas Gohr $handler->addCall('header', [$title, $level, $pos], $pos); 39*71096e46SAndreas Gohr 40*71096e46SAndreas Gohr $handler->addCall('section_open', [$level], $pos); 41*71096e46SAndreas Gohr $handler->setStatus('section', true); 42*71096e46SAndreas Gohr return true; 43be906b56SAndreas Gohr } 44be906b56SAndreas Gohr} 45