getIndentWidth()); $this->Lexer->addEntryPattern('\n' . $indent, $mode, 'preformatted'); $this->Lexer->addEntryPattern('\n\t', $mode, 'preformatted'); // match continuation lines inside the preformatted block $this->Lexer->addPattern('\n' . $indent, 'preformatted'); $this->Lexer->addPattern('\n\t', 'preformatted'); } /** @inheritdoc */ public function postConnect() { // Two exits: a zero-width lookahead when the next line starts with // non-whitespace content (so the boundary \n stays in the stream // and downstream block-level modes like GfmHr or GfmHeader can // anchor on it), and a consuming \n fall-through for blank lines // and end-of-input. The lookahead-only branch is registered first // so PCRE's leftmost-first alternation prefers it whenever it // applies; the consuming branch handles the cases where it cannot. $this->Lexer->addExitPattern('(?=\n[^ \t\n])', 'preformatted'); $this->Lexer->addExitPattern('\n', 'preformatted'); } /** @inheritdoc */ public function handle($match, $state, $pos, Handler $handler) { switch ($state) { case DOKU_LEXER_ENTER: $handler->setCallWriter(new PreformattedHandler($handler->getCallWriter())); $handler->addCall('preformatted_start', [], $pos); break; case DOKU_LEXER_EXIT: $handler->addCall('preformatted_end', [], $pos); /** @var PreformattedHandler $reWriter */ $reWriter = $handler->getCallWriter(); $handler->setCallWriter($reWriter->process()); break; case DOKU_LEXER_MATCHED: $handler->addCall('preformatted_newline', [], $pos); break; case DOKU_LEXER_UNMATCHED: $handler->addCall('preformatted_content', [$match], $pos); break; } return true; } }