diff options
Diffstat (limited to 'inc/ParserMode/Smiley.php')
-rw-r--r-- | inc/ParserMode/Smiley.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/inc/ParserMode/Smiley.php b/inc/ParserMode/Smiley.php new file mode 100644 index 000000000..73d302e2f --- /dev/null +++ b/inc/ParserMode/Smiley.php @@ -0,0 +1,46 @@ +<?php + +namespace dokuwiki\ParserMode; + +class Smiley extends AbstractMode +{ + protected $smileys = array(); + protected $pattern = ''; + + /** + * Smiley constructor. + * @param string[] $smileys + */ + public function __construct($smileys) + { + $this->smileys = $smileys; + } + + /** @inheritdoc */ + public function preConnect() + { + if (!count($this->smileys) || $this->pattern != '') return; + + $sep = ''; + foreach ($this->smileys as $smiley) { + $this->pattern .= $sep.'(?<=\W|^)'.Doku_Lexer_Escape($smiley).'(?=\W|$)'; + $sep = '|'; + } + } + + /** @inheritdoc */ + public function connectTo($mode) + { + if (!count($this->smileys)) return; + + if (strlen($this->pattern) > 0) { + $this->Lexer->addSpecialPattern($this->pattern, $mode, 'smiley'); + } + } + + /** @inheritdoc */ + public function getSort() + { + return 230; + } +} |