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

dg / texy / 22262381750

25 Jan 2026 11:44PM UTC coverage: 92.367% (-0.7%) from 93.057%
22262381750

push

github

dg
cs

9 of 11 new or added lines in 8 files covered. (81.82%)

161 existing lines in 23 files now uncovered.

2384 of 2581 relevant lines covered (92.37%)

0.92 hits per line

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

96.08
/src/Texy/Modules/ParagraphModule.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 Texy\Regexp;
14
use function preg_match, preg_split, str_contains, str_replace, strlen, strtr, substr_replace, trim;
15
use const PREG_SPLIT_NO_EMPTY;
16

17

18
/**
19
 * Paragraph module.
20
 */
21
final class ParagraphModule extends Texy\Module
22
{
23
        public function __construct(Texy\Texy $texy)
1✔
24
        {
25
                $this->texy = $texy;
1✔
26
                $texy->addHandler('paragraph', $this->solve(...));
1✔
27
        }
1✔
28

29

30
        public function process(Texy\BlockParser $parser, string $content, Texy\HtmlElement $el): void
1✔
31
        {
32
                $parts = $parser->isIndented()
1✔
33
                        ? preg_split('#(\n(?!\ )|\n{2,})#', $content, -1, PREG_SPLIT_NO_EMPTY)
1✔
34
                        : preg_split('#(\n{2,})#', $content, -1, PREG_SPLIT_NO_EMPTY);
1✔
35

36
                foreach ($parts as $s) {
1✔
37
                        $s = trim($s);
1✔
38
                        if ($s === '') {
1✔
39
                                continue;
×
40
                        }
41

42
                        // try to find modifier
43
                        $mod = null;
1✔
44
                        if ($mx = Regexp::match($s, '#' . Texy\Patterns::MODIFIER_H . '(?=\n|\z)#sUm', Regexp::OFFSET_CAPTURE)) {
1✔
45
                                [$mMod] = $mx[1];
1✔
46
                                $s = trim(substr_replace($s, '', $mx[0][1], strlen($mx[0][0])));
1✔
47
                                if ($s === '') {
1✔
48
                                        continue;
1✔
49
                                }
50

51
                                $mod = new Texy\Modifier;
1✔
52
                                $mod->setProperties($mMod);
1✔
53
                        }
54

55
                        $res = $this->texy->invokeAroundHandlers('paragraph', $parser, [$s, $mod]);
1✔
56
                        if ($res) {
1✔
57
                                $el->insert(null, $res);
1✔
58
                        }
59
                }
60
        }
1✔
61

62

63
        /**
64
         * Finish invocation.
65
         */
66
        private function solve(
1✔
67
                Texy\HandlerInvocation $invocation,
68
                string $content,
69
                ?Texy\Modifier $mod = null,
70
        ): ?Texy\HtmlElement
71
        {
72
                $texy = $this->texy;
1✔
73

74
                // find hard linebreaks
75
                $content = $texy->mergeLines
1✔
76
                        // ....
77
                        // ... => \r means break line
78
                        ? Regexp::replace($content, '#\n\ +(?=\S)#', "\r")
1✔
UNCOV
79
                        : Regexp::replace($content, '#\n#', "\r");
×
80

81
                $el = new Texy\HtmlElement('p');
1✔
82
                $el->parseLine($texy, $content);
1✔
83
                $content = $el->getText(); // string
1✔
84

85
                // check content type
86
                // block contains block tag
87
                if (str_contains($content, $texy::CONTENT_BLOCK)) {
1✔
88
                        $el->setName(null); // ignores modifier!
1✔
89

90
                // block contains text (protected)
91
                } elseif (str_contains($content, $texy::CONTENT_TEXTUAL)) {
1✔
92
                        // leave element p
93

94
                // block contains text
95
                } elseif (preg_match('#[^\s' . Texy\Patterns::MARK . ']#u', $content)) {
1✔
96
                        // leave element p
97

98
                // block contains only replaced element
99
                } elseif (str_contains($content, $texy::CONTENT_REPLACED)) {
1✔
100
                        if ($texy->nontextParagraph instanceof Texy\HtmlElement) {
1✔
101
                                $el = (clone $texy->nontextParagraph)->setText($content);
1✔
102
                        } else {
103
                                $el->setName($texy->nontextParagraph);
1✔
104
                        }
105

106
                // block contains only markup tags or spaces or nothing
107
                } else {
108
                        // if {ignoreEmptyStuff} return null;
109
                        if (!$mod) {
1✔
110
                                $el->setName(null);
1✔
111
                        }
112
                }
113

114
                if ($el->getName()) {
1✔
115
                        // apply modifier
116
                        if ($mod) {
1✔
117
                                $mod->decorate($texy, $el);
1✔
118
                        }
119

120
                        // add <br>
121
                        if (str_contains($content, "\r")) {
1✔
122
                                $key = $texy->protect('<br>', $texy::CONTENT_REPLACED);
1✔
123
                                $content = str_replace("\r", $key, $content);
1✔
124
                        }
125
                }
126

127
                $content = strtr($content, "\r\n", '  ');
1✔
128
                $el->setText($content);
1✔
129

130
                return $el;
1✔
131
        }
132
}
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