3 namespace dokuwiki\Parsing\ParserMode
;
5 class Acronym
extends AbstractMode
8 protected $acronyms = [];
9 protected $pattern = '';
12 * Acronym constructor.
14 * @param string[] $acronyms
16 public function __construct($acronyms)
18 usort($acronyms, [$this, 'compare']);
19 $this->acronyms
= $acronyms;
23 public function preConnect()
25 if (!count($this->acronyms
)) return;
27 $bound = '[\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]';
28 $acronyms = array_map(['\\dokuwiki\\Parsing\\Lexer\\Lexer', 'escape'], $this->acronyms
);
29 $this->pattern
= '(?<=^|' . $bound . ')(?:' . implode('|', $acronyms) . ')(?=' . $bound . ')';
33 public function connectTo($mode)
35 if (!count($this->acronyms
)) return;
37 if (strlen($this->pattern
) > 0) {
38 $this->Lexer
->addSpecialPattern($this->pattern
, $mode, 'acronym');
43 public function getSort()
49 * sort callback to order by string length descending
56 protected function compare($a, $b)
60 if ($a_len > $b_len) {
62 } elseif ($a_len < $b_len) {