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

dg / texy / 15479423458

05 Jun 2025 11:37PM UTC coverage: 92.741% (+0.5%) from 92.224%
15479423458

push

github

dg
HtmlElement: removed toHtml() & toText()

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

78 existing lines in 11 files now uncovered.

2389 of 2576 relevant lines covered (92.74%)

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

15

16
/**
17
 * Scripts module.
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->toElement(...));
1✔
30

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

45

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

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

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

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

73

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

88
                        return '';
1✔
89
                }
90

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