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

dg / texy / 22262589061

21 Feb 2026 07:04PM UTC coverage: 92.991% (+1.8%) from 91.178%
22262589061

push

github

dg
LinkModule: deprecated label and modifiers in link definitions

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

126 existing lines in 22 files now uncovered.

2083 of 2240 relevant lines covered (92.99%)

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
                [, $mURLs, $mImgMod, $mAlign, $mLink, $mContent, $mMod] = $matches;
1✔
73
                // [1] => URLs
74
                // [2] => .(title)[class]{style}<>
75
                // [3] => * < >
76
                // [4] => url | [ref] | [*image*]
77
                // [5] => ...
78
                // [6] => .(title)[class]{style}<>
79

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

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

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

100

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

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

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

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

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

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

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

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

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

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

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