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

dg / texy / 21344532034

26 Jan 2026 02:43AM UTC coverage: 91.98% (-0.4%) from 92.376%
21344532034

push

github

dg
added CLAUDE.md

2397 of 2606 relevant lines covered (91.98%)

0.92 hits per line

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

89.66
/src/Texy/Modules/ScriptModule.php
1
<?php
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
declare(strict_types=1);
9

10
namespace Texy\Modules;
11

12
use Texy;
13
use function preg_quote, preg_split, trim;
14

15

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

24

25
        public function __construct(Texy\Texy $texy)
1✔
26
        {
27
                $this->texy = $texy;
1✔
28

29
                $texy->addHandler('script', $this->solve(...));
1✔
30

31
                $texy->registerLinePattern(
1✔
32
                        $this->pattern(...),
1✔
33
                        '#\{\{((?:[^' . Texy\Patterns::MARK . '}]++|[}])+)\}\}()#U',
1✔
34
                        'script',
1✔
35
                );
36
        }
1✔
37

38

39
        /**
40
         * Callback for: {{...}}.
41
         * @param  string[]  $matches
42
         */
43
        public function pattern(Texy\LineParser $parser, array $matches): Texy\HtmlElement|string|null
1✔
44
        {
45
                [, $mContent] = $matches;
1✔
46
                // [1] => ...
47

48
                $cmd = trim($mContent);
1✔
49
                if ($cmd === '') {
1✔
50
                        return null;
×
51
                }
52

53
                $raw = null;
1✔
54
                $args = [];
1✔
55
                // function (arg, arg, ...) or function: arg, arg
56
                if ($matches = Texy\Regexp::match($cmd, '#^([a-z_][a-z0-9_-]*)\s*(?:\(([^()]*)\)|:(.*))$#iu')) {
1✔
57
                        $cmd = $matches[1];
1✔
58
                        $raw = trim($matches[3] ?? $matches[2]);
1✔
59
                        if ($raw !== '') {
1✔
60
                                $args = preg_split('#\s*' . preg_quote($this->separator, '#') . '\s*#u', $raw);
1✔
61
                        }
62
                }
63

64
                return $this->texy->invokeAroundHandlers('script', $parser, [$cmd, $args, $raw]);
1✔
65
        }
66

67

68
        /**
69
         * Finish invocation.
70
         * @param ?list<string>  $args
71
         */
72
        private function solve(
1✔
73
                Texy\HandlerInvocation $invocation,
74
                string $cmd,
75
                ?array $args = null,
76
                ?string $raw = null,
77
        ): ?string
78
        {
79
                if ($cmd === 'texy' && $args) {
1✔
80
                        switch ($args[0]) {
1✔
81
                                case 'nofollow':
1✔
82
                                        $this->texy->linkModule->forceNoFollow = true;
×
83
                                        break;
×
84
                        }
85

86
                        return '';
1✔
87
                }
88

89
                return null;
1✔
90
        }
91
}
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