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

dg / texy / 16790351274

06 Aug 2025 10:42PM UTC coverage: 92.746% (+0.005%) from 92.741%
16790351274

push

github

dg
HtmlElement: removed toHtml() & toText()

18 of 19 new or added lines in 5 files covered. (94.74%)

136 existing lines in 23 files now uncovered.

2391 of 2578 relevant lines covered (92.75%)

0.93 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.info)
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 Texy\Regexp;
14
use function preg_quote, preg_split, trim;
15

16

17
/**
18
 * Scripts module.
19
 */
20
final class ScriptModule extends Texy\Module
21
{
22
        /** arguments separator */
23
        public string $separator = ',';
24

25

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

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

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

46

47
        /**
48
         * Callback for: {{...}}.
49
         */
50
        public function parse(Texy\LineParser $parser, array $matches): Texy\HtmlElement|string|null
1✔
51
        {
52
                [, $mContent] = $matches;
1✔
53
                // [1] => ...
54

55
                $cmd = trim($mContent);
1✔
56
                if ($cmd === '') {
1✔
UNCOV
57
                        return null;
×
58
                }
59

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

71
                return $this->texy->invokeAroundHandlers('script', $parser, [$cmd, $args, $raw]);
1✔
72
        }
73

74

75
        public function toElement(
1✔
76
                Texy\HandlerInvocation $invocation,
77
                string $cmd,
78
                ?array $args = null,
79
                ?string $raw = null,
80
        ): Texy\HtmlElement|string|null
81
        {
82
                if ($cmd === 'texy' && $args) {
1✔
83
                        switch ($args[0]) {
1✔
84
                                case 'nofollow':
1✔
85
                                        $this->texy->linkModule->forceNoFollow = true;
×
UNCOV
86
                                        break;
×
87
                        }
88

89
                        return '';
1✔
90
                }
91

92
                return null;
1✔
93
        }
94
}
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