Skip to content

Commit 66de3df

Browse files
committed
refactor: remove mvp wording from unsupported subset messaging
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent afe67ea commit 66de3df

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12-
- Initial bootstrap for MVP HTML+CSS subset to Form XObject compilation.
12+
- Initial bootstrap for HTML+CSS subset to Form XObject compilation.

src/Html/SubsetHtmlParser.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ final class SubsetHtmlParser
2626
public function parse(string $html): array
2727
{
2828
$dom = new DOMDocument('1.0', 'UTF-8');
29-
@$dom->loadHTML('<?xml encoding="utf-8" ?><body>' . $html . '</body>', LIBXML_NOERROR | LIBXML_NOWARNING);
29+
$previousUseInternalErrors = libxml_use_internal_errors(true);
30+
$dom->loadHTML(
31+
'<?xml encoding="utf-8" ?><body>' . $html . '</body>',
32+
LIBXML_NOERROR | LIBXML_NOWARNING,
33+
);
34+
libxml_clear_errors();
35+
libxml_use_internal_errors($previousUseInternalErrors);
3036

3137
$body = $dom->getElementsByTagName('body')->item(0);
3238
if (!$body instanceof DOMElement) {
@@ -49,12 +55,14 @@ private function parseDomNode(DOMNode $node, string $inheritedStyle): ?Node
4955
if ($node instanceof DOMElement) {
5056
$tag = strtolower($node->tagName);
5157
if (!isset($this->allowedTags[$tag])) {
52-
throw new UnsupportedSubsetException(sprintf('Tag <%s> is not supported in MVP subset.', $tag));
58+
throw new UnsupportedSubsetException(sprintf('Tag <%s> is not supported.', $tag));
5359
}
5460

5561
$attributes = [];
56-
foreach ($node->attributes as $attribute) {
57-
$attributes[strtolower($attribute->name)] = $attribute->value;
62+
if ($node->attributes !== null) {
63+
foreach ($node->attributes as $attribute) {
64+
$attributes[strtolower($attribute->name)] = $attribute->value;
65+
}
5866
}
5967

6068
$ownStyle = $attributes['style'] ?? '';
@@ -79,7 +87,7 @@ private function parseDomNode(DOMNode $node, string $inheritedStyle): ?Node
7987
);
8088
}
8189

82-
$text = trim($node->textContent ?? '');
90+
$text = trim($node->textContent);
8391
if ($text === '') {
8492
return null;
8593
}

0 commit comments

Comments
 (0)