1be906b56SAndreas Gohr<?php 2be906b56SAndreas Gohr 3be906b56SAndreas Gohrnamespace dokuwiki\Parsing\ParserMode; 4be906b56SAndreas Gohr 5*71096e46SAndreas Gohruse dokuwiki\Parsing\Handler; 6*71096e46SAndreas Gohruse dokuwiki\Parsing\Handler\Lists; 7c8dd1b9dSAndreas Gohruse dokuwiki\Parsing\ModeRegistry; 8c8dd1b9dSAndreas Gohr 9be906b56SAndreas Gohrclass Listblock extends AbstractMode 10be906b56SAndreas Gohr{ 11be906b56SAndreas Gohr /** 12be906b56SAndreas Gohr * Listblock constructor. 13be906b56SAndreas Gohr */ 14be906b56SAndreas Gohr public function __construct() 15be906b56SAndreas Gohr { 16c8dd1b9dSAndreas Gohr $this->allowedModes = ModeRegistry::getInstance()->getModesForCategories([ 17c8dd1b9dSAndreas Gohr ModeRegistry::CATEGORY_FORMATTING, 18c8dd1b9dSAndreas Gohr ModeRegistry::CATEGORY_SUBSTITION, 19c8dd1b9dSAndreas Gohr ModeRegistry::CATEGORY_DISABLED, 20c8dd1b9dSAndreas Gohr ModeRegistry::CATEGORY_PROTECTED, 21c8dd1b9dSAndreas Gohr ]); 22be906b56SAndreas Gohr } 23be906b56SAndreas Gohr 24be906b56SAndreas Gohr /** @inheritdoc */ 25*71096e46SAndreas Gohr public function getSort() 26*71096e46SAndreas Gohr { 27*71096e46SAndreas Gohr return 10; 28*71096e46SAndreas Gohr } 29*71096e46SAndreas Gohr 30*71096e46SAndreas Gohr /** @inheritdoc */ 317958e698SAndreas Gohr public function preConnect() 327958e698SAndreas Gohr { 337958e698SAndreas Gohr $registry = ModeRegistry::getInstance(); 347958e698SAndreas Gohr $registry->registerBlockEolMode('listblock'); 357958e698SAndreas Gohr $registry->registerLineStartMarkers('listblock', ['\\*', '\\-']); 367958e698SAndreas Gohr } 377958e698SAndreas Gohr 387958e698SAndreas Gohr /** @inheritdoc */ 39be906b56SAndreas Gohr public function connectTo($mode) 40be906b56SAndreas Gohr { 41be906b56SAndreas Gohr $this->Lexer->addEntryPattern('[ \t]*\n {2,}[\-\*]', $mode, 'listblock'); 42be906b56SAndreas Gohr $this->Lexer->addEntryPattern('[ \t]*\n\t{1,}[\-\*]', $mode, 'listblock'); 43be906b56SAndreas Gohr 44be906b56SAndreas Gohr $this->Lexer->addPattern('\n {2,}[\-\*]', 'listblock'); 45be906b56SAndreas Gohr $this->Lexer->addPattern('\n\t{1,}[\-\*]', 'listblock'); 46be906b56SAndreas Gohr } 47be906b56SAndreas Gohr 48be906b56SAndreas Gohr /** @inheritdoc */ 49be906b56SAndreas Gohr public function postConnect() 50be906b56SAndreas Gohr { 51be906b56SAndreas Gohr $this->Lexer->addExitPattern('\n', 'listblock'); 52be906b56SAndreas Gohr } 53be906b56SAndreas Gohr 54be906b56SAndreas Gohr /** @inheritdoc */ 55*71096e46SAndreas Gohr public function handle($match, $state, $pos, Handler $handler) 56be906b56SAndreas Gohr { 57*71096e46SAndreas Gohr switch ($state) { 58*71096e46SAndreas Gohr case DOKU_LEXER_ENTER: 59*71096e46SAndreas Gohr $handler->setCallWriter(new Lists($handler->getCallWriter())); 60*71096e46SAndreas Gohr $handler->addCall('list_open', [$match], $pos); 61*71096e46SAndreas Gohr break; 62*71096e46SAndreas Gohr case DOKU_LEXER_EXIT: 63*71096e46SAndreas Gohr $handler->addCall('list_close', [], $pos); 64*71096e46SAndreas Gohr /** @var Lists $reWriter */ 65*71096e46SAndreas Gohr $reWriter = $handler->getCallWriter(); 66*71096e46SAndreas Gohr $handler->setCallWriter($reWriter->process()); 67*71096e46SAndreas Gohr break; 68*71096e46SAndreas Gohr case DOKU_LEXER_MATCHED: 69*71096e46SAndreas Gohr $handler->addCall('list_item', [$match], $pos); 70*71096e46SAndreas Gohr break; 71*71096e46SAndreas Gohr case DOKU_LEXER_UNMATCHED: 72*71096e46SAndreas Gohr $handler->addCall('cdata', [$match], $pos); 73*71096e46SAndreas Gohr break; 74*71096e46SAndreas Gohr } 75*71096e46SAndreas Gohr return true; 76be906b56SAndreas Gohr } 77be906b56SAndreas Gohr} 78