1<?php 2 3namespace dokuwiki\Parsing\ParserMode; 4 5use dokuwiki\Parsing\Lexer\Lexer; 6 7/** 8 * This class and all the subclasses below are used to reduce the effort required to register 9 * modes with the Lexer. 10 * 11 * @author Harry Fuecks <hfuecks@gmail.com> 12 */ 13abstract class AbstractMode implements ModeInterface 14{ 15 /** @var Lexer $Lexer will be injected on loading FIXME this should be done by setter */ 16 public $Lexer; 17 protected $allowedModes = []; 18 19 /** 20 * Regex snippet: quantified group matching any character that does not 21 * start a paragraph break (a blank line — two newlines possibly separated 22 * by horizontal whitespace). 23 * 24 * The DokuWiki lexer compiles all mode patterns with the `s` (DOTALL) flag 25 * via ParallelRegex::getPerlMatchingFlags(), so a plain `.*` inside an 26 * entry-pattern lookahead matches across newlines and lets an unclosed 27 * delimiter greedily consume following paragraphs. Use this constant in 28 * lookaheads that scan for a closing delimiter to keep formatting inside 29 * a single paragraph. 30 * 31 * Example: 32 * return '\*\*(?=' . self::CONTENT_UNTIL_PARA . '\*\*)'; 33 */ 34 protected const CONTENT_UNTIL_PARA = '(?:(?!\n[ \t]*\n).)*'; 35 36 /** @inheritdoc */ 37 abstract public function getSort(); 38 39 /** @inheritdoc */ 40 public function preConnect() 41 { 42 } 43 44 /** @inheritdoc */ 45 public function connectTo($mode) 46 { 47 } 48 49 /** @inheritdoc */ 50 public function postConnect() 51 { 52 } 53 54 /** @inheritdoc */ 55 public function accepts($mode) 56 { 57 return in_array($mode, (array) $this->allowedModes); 58 } 59} 60