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

voku / simple_html_dom / 24632839975

19 Apr 2026 03:42PM UTC coverage: 77.11% (+6.3%) from 70.769%
24632839975

push

github

web-flow
Merge pull request #135 from voku/copilot/fix-html-parsing-newline-issue

Preserve node HTML formatting when serializing nested elements

4 of 24 new or added lines in 1 file covered. (16.67%)

51 existing lines in 6 files now uncovered.

1654 of 2145 relevant lines covered (77.11%)

262.05 hits per line

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

82.14
/src/voku/helper/HtmlDomHelper.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace voku\helper;
6

7
final class HtmlDomHelper
8
{
9
    /**
10
     * @param string $html
11
     * @param string $optionStr
12
     * @param string $htmlCssSelector
13
     *
14
     * @return string
15
     */
16
    public static function mergeHtmlAttributes(
17
        string $html,
18
        string $optionStr,
19
        string $htmlCssSelector
20
    ): string {
21
        if (!$optionStr) {
14✔
22
            return $html;
×
23
        }
24

25
        $dom = \voku\helper\HtmlDomParser::str_get_html($html);
14✔
26
        $domNew = \voku\helper\HtmlDomParser::str_get_html('<textarea ' . $optionStr . '></textarea>');
14✔
27

28
        $domElement = $dom->findOneOrFalse($htmlCssSelector);
14✔
29
        if ($domElement === false) {
14✔
30
            return $html;
×
31
        }
32
        $attributes = $domElement->getAllAttributes();
14✔
33
        if (!$attributes) {
14✔
34
            return $html;
×
35
        }
36

37
        $domElementNew = $domNew->findOneOrFalse('textarea');
14✔
38
        if ($domElementNew === false) {
14✔
39
            return $html;
×
40
        }
41
        $attributesNew = $domElementNew->getAllAttributes();
14✔
42
        if (!$attributesNew) {
14✔
43
            return $html;
×
44
        }
45

46
        foreach ($attributesNew as $attributeNameNew => $attributeValueNew) {
14✔
47
            $attributeNameNew = \strtolower($attributeNameNew);
14✔
48

49
            if (
50
                $attributeNameNew === 'class'
14✔
51
                ||
52
                $attributeNameNew === 'style'
14✔
53
                ||
54
                \strpos($attributeNameNew, 'on') === 0 // e.g. onClick, ...
14✔
55
            ) {
56
                if (isset($attributes[$attributeNameNew])) {
14✔
57
                    $attributes[$attributeNameNew] .= ' ' . $attributeValueNew;
14✔
58
                } else {
UNCOV
59
                    $attributes[$attributeNameNew] = $attributeValueNew;
8✔
60
                }
61
            } else {
62
                $attributes[$attributeNameNew] = $attributeValueNew;
14✔
63
            }
64
        }
65

66
        foreach ($attributes as $attributeName => $attributeValue) {
14✔
67
            $domElement->setAttribute($attributeName, $attributeValue, true);
14✔
68
        }
69

70
        return $domElement->html();
14✔
71
    }
72
}
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