You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

50 lines
984 B

  1. <?php
  2. namespace dokuwiki\Parsing\ParserMode;
  3. use dokuwiki\Parsing\Lexer\Lexer;
  4. class Entity extends AbstractMode
  5. {
  6. protected $entities = [];
  7. protected $pattern = '';
  8. /**
  9. * Entity constructor.
  10. * @param string[] $entities
  11. */
  12. public function __construct($entities)
  13. {
  14. $this->entities = $entities;
  15. }
  16. /** @inheritdoc */
  17. public function preConnect()
  18. {
  19. if (!count($this->entities) || $this->pattern != '') return;
  20. $sep = '';
  21. foreach ($this->entities as $entity) {
  22. $this->pattern .= $sep . Lexer::escape($entity);
  23. $sep = '|';
  24. }
  25. }
  26. /** @inheritdoc */
  27. public function connectTo($mode)
  28. {
  29. if (!count($this->entities)) return;
  30. if (strlen($this->pattern) > 0) {
  31. $this->Lexer->addSpecialPattern($this->pattern, $mode, 'entity');
  32. }
  33. }
  34. /** @inheritdoc */
  35. public function getSort()
  36. {
  37. return 260;
  38. }
  39. }