• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dg / texy / 22283286087

22 Feb 2026 06:58PM UTC coverage: 93.01% (+0.02%) from 92.991%
22283286087

push

github

dg
LinkModule: deprecated label and modifiers in link definitions

3 of 3 new or added lines in 1 file covered. (100.0%)

72 existing lines in 16 files now uncovered.

2089 of 2246 relevant lines covered (93.01%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.0
/src/Texy/Modules/DirectiveModule.php
1
<?php declare(strict_types=1);
2

3
/**
4
 * This file is part of the Texy! (https://texy.nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
namespace Texy\Modules;
9

10
use Texy;
11
use Texy\Regexp;
12
use function trim;
13

14

15
/**
16
 * Processes {{macro}} script commands.
17
 */
18
final class DirectiveModule extends Texy\Module
19
{
20
        /** arguments separator */
21
        public string $separator = ',';
22

23

24
        public function __construct(
1✔
25
                private Texy\Texy $texy,
26
        ) {
27
                $texy->addHandler('script', $this->solve(...));
1✔
28
        }
1✔
29

30

31
        public function beforeParse(string &$text): void
1✔
32
        {
33
                $this->texy->registerLinePattern(
1✔
34
                        $this->parse(...),
1✔
35
                        '~
36
                                \{\{
37
                                ((?:
38
                                        [^' . Texy\Patterns::MARK . '}]++ |  # content not containing }
1✔
39
                                        }                                    # or single }
40
                                )+)
41
                                }}
42
                        ~U',
43
                        'script',
1✔
44
                );
45
        }
1✔
46

47

48
        /**
49
         * Parses {{...}}
50
         * @param  array<?string>  $matches
51
         */
52
        public function parse(Texy\InlineParser $parser, array $matches): Texy\HtmlElement|string|null
1✔
53
        {
54
                /** @var array{string, string} $matches */
55
                [, $mContent] = $matches;
1✔
56
                // [1] => ...
57

58
                $cmd = trim($mContent);
1✔
59
                if ($cmd === '') {
1✔
UNCOV
60
                        return null;
×
61
                }
62

63
                $raw = null;
1✔
64
                $args = [];
1✔
65
                // function (arg, arg, ...) or function: arg, arg
66
                /** @var array{string, string, ?string, ?string} $matches */
67
                if ($matches = Regexp::match($cmd, '~^ ([a-z_][a-z0-9_-]*) \s* (?: \( ([^()]*) \) | : (.*) )$~i')) {
1✔
68
                        $cmd = $matches[1];
1✔
69
                        $raw = trim((string) ($matches[3] ?? $matches[2]));
1✔
70
                        if ($raw !== '') {
1✔
71
                                $args = Regexp::split($raw, '~\s*' . Regexp::quote($this->separator) . '\s*~');
1✔
72
                        }
73
                }
74

75
                return $this->texy->invokeAroundHandlers('script', $parser, [$cmd, $args, $raw]);
1✔
76
        }
77

78

79
        /**
80
         * Finish invocation.
81
         * @param ?list<string>  $args
82
         */
83
        private function solve(
1✔
84
                Texy\HandlerInvocation $invocation,
85
                string $cmd,
86
                ?array $args = null,
87
                ?string $raw = null,
88
        ): ?string
89
        {
90
                if ($cmd === 'texy' && $args) {
1✔
91
                        switch ($args[0]) {
1✔
92
                                case 'nofollow':
1✔
UNCOV
93
                                        $this->texy->linkModule->forceNoFollow = true;
×
UNCOV
94
                                        break;
×
95
                        }
96

97
                        return '';
1✔
98
                }
99

100
                return null;
1✔
101
        }
102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc