xref: /dokuwiki/inc/Parsing/ParserMode/Filelink.php (revision 504c13e8df88563c11b3720b317991bc38835a35)
1<?php
2
3namespace dokuwiki\Parsing\ParserMode;
4
5use dokuwiki\Parsing\Handler;
6
7class Filelink extends AbstractMode
8{
9    protected $pattern;
10
11    /** @inheritdoc */
12    public function getSort()
13    {
14        return 360;
15    }
16
17    /** @inheritdoc */
18    public function preConnect()
19    {
20
21        $ltrs = '\w';
22        $gunk = '/\#~:.?+=&%@!\-';
23        $punc = '.:?\-;,';
24        $any  = $ltrs . $gunk . $punc;
25
26        $this->pattern = '\b(?i)file(?-i)://[' . $any . ']+?[' .
27            $punc . ']*[^' . $any . ']';
28    }
29
30    /** @inheritdoc */
31    public function connectTo($mode)
32    {
33        $this->Lexer->addSpecialPattern(
34            $this->pattern,
35            $mode,
36            'filelink'
37        );
38    }
39
40    /** @inheritdoc */
41    public function handle($match, $state, $pos, Handler $handler)
42    {
43        $handler->addCall('filelink', [$match, null], $pos);
44        return true;
45    }
46}
47