• 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

98.04
/src/Texy/Modules/FigureModule.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\Patterns;
12
use function trim;
13

14

15
/**
16
 * Processes images with captions.
17
 */
18
final class FigureModule extends Texy\Module
19
{
20
        public string $tagName = 'div';
21

22
        /** non-floated box CSS class */
23
        public ?string $class = 'figure';
24

25
        /** left-floated box CSS class */
26
        public ?string $leftClass = null;
27

28
        /** right-floated box CSS class */
29
        public ?string $rightClass = null;
30

31

32
        public function __construct(
1✔
33
                private Texy\Texy $texy,
34
        ) {
35
                $texy->addHandler('figure', $this->solve(...));
1✔
36
        }
1✔
37

38

39
        public function beforeParse(string &$text): void
1✔
40
        {
41
                $this->texy->registerBlockPattern(
1✔
42
                        $this->parse(...),
1✔
43
                        '~^
44
                                (?>
45
                                        \[\*\ *+                      # opening bracket with asterisk
46
                                        ([^\n' . Patterns::MARK . ']{1,1000}) # URLs (1)
1✔
47
                                        ' . Patterns::MODIFIER . '?   # modifier (2)
1✔
48
                                        \ *+
49
                                        ( \* | (?<! < ) > | < )       # alignment (3)
50
                                        ]
51
                                )
52
                                (?:
53
                                        :(' . Patterns::LINK_URL . ' | : ) # link or colon (4)
1✔
54
                                )??
55
                                (?:
56
                                        \ ++ \*\*\* \ ++              # separator
57
                                        (.{0,2000})                   # caption (5)
58
                                )?
59
                                ' . Patterns::MODIFIER_H . '?     # modifier (6)
1✔
60
                        $~mU',
61
                        'figure',
1✔
62
                );
63
        }
1✔
64

65

66
        /**
67
         * Parses [*image*]:link *** caption .(title)[class]{style}>.
68
         * @param  array<?string>  $matches
69
         */
70
        public function parse(Texy\BlockParser $parser, array $matches): Texy\HtmlElement|string|null
1✔
71
        {
72
                /** @var array{string, string, ?string, string, ?string, ?string, ?string} $matches */
73
                [, $mURLs, $mImgMod, $mAlign, $mLink, $mContent, $mMod] = $matches;
1✔
74
                // [1] => URLs
75
                // [2] => .(title)[class]{style}<>
76
                // [3] => * < >
77
                // [4] => url | [ref] | [*image*]
78
                // [5] => ...
79
                // [6] => .(title)[class]{style}<>
80

81
                $texy = $this->texy;
1✔
82
                $image = $texy->imageModule->factoryImage($mURLs, $mImgMod . $mAlign);
1✔
83
                $mod = Texy\Modifier::parse($mMod);
1✔
84
                $mContent = trim($mContent ?? '');
1✔
85

86
                if ($mLink) {
1✔
87
                        if ($mLink === ':') {
1✔
88
                                $link = new Texy\Link($image->linkedURL ?? $image->URL);
1✔
89
                                $link->raw = ':';
1✔
90
                                $link->type = $link::IMAGE;
1✔
91
                        } else {
92
                                $link = $texy->linkModule->factoryLink($mLink, null, null);
1✔
93
                        }
94
                } else {
95
                        $link = null;
1✔
96
                }
97

98
                return $texy->invokeAroundHandlers('figure', $parser, [$image, $link, $mContent, $mod]);
1✔
99
        }
100

101

102
        /**
103
         * Finish invocation.
104
         */
105
        private function solve(
1✔
106
                Texy\HandlerInvocation $invocation,
107
                Texy\Image $image,
108
                ?Texy\Link $link,
109
                string $content,
110
                Texy\Modifier $mod,
111
        ): ?Texy\HtmlElement
112
        {
113
                $texy = $this->texy;
1✔
114

115
                $hAlign = $image->modifier->hAlign;
1✔
116
                $image->modifier->hAlign = null;
1✔
117

118
                $elImg = $texy->imageModule->solve(null, $image, $link); // returns Texy\HtmlElement or null!
1✔
119
                if (!$elImg) {
1✔
UNCOV
120
                        return null;
×
121
                }
122

123
                $el = new Texy\HtmlElement($this->tagName);
1✔
124
                $mod->decorate($texy, $el);
1✔
125

126
                $el->add($elImg);
1✔
127

128
                if ($content !== '') {
1✔
129
                        $el[1] = new Texy\HtmlElement($this->tagName === 'figure' ? 'figcaption' : 'p');
1✔
130
                        $el[1]->parseLine($texy, $content);
1✔
131
                }
132

133
                $class = $this->class;
1✔
134
                if ($hAlign) {
1✔
135
                        $var = $hAlign . 'Class'; // leftClass, rightClass
1✔
136
                        if (!empty($this->$var)) {
1✔
137
                                $class = $this->$var;
1✔
138

139
                        } elseif (empty($texy->alignClasses[$hAlign])) {
1✔
140
                                $el->attrs['style'] = (array) ($el->attrs['style'] ?? []);
1✔
141
                                $el->attrs['style']['float'] = $hAlign;
1✔
142

143
                        } else {
144
                                $class .= '-' . $texy->alignClasses[$hAlign];
1✔
145
                        }
146
                }
147

148
                $el->attrs['class'] = (array) ($el->attrs['class'] ?? []);
1✔
149
                $el->attrs['class'][] = $class;
1✔
150

151
                return $el;
1✔
152
        }
153
}
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