Skip to content

Commit 0fe0df9

Browse files
authored
feat(view): more lenient DOM parsing (#941)
1 parent 1b3433d commit 0fe0df9

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Tempest/View/src/Renderers/TempestViewCompiler.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,15 @@ private function parseDom(string $template): HTMLDocument|NodeList
108108
->trim()
109109
->startsWith(['<html', '<!DOCTYPE', '<!doctype']);
110110

111+
$parserFlags = LIBXML_HTML_NOIMPLIED | LIBXML_NOERROR | HTML_NO_DEFAULT_NS;
112+
111113
if ($isFullHtmlDocument) {
112114
// If we're rendering a full HTML document, we'll parse it as is
113-
return HTMLDocument::createFromString($template->toString(), LIBXML_NOERROR | HTML_NO_DEFAULT_NS);
115+
return HTMLDocument::createFromString($template->toString(), $parserFlags);
114116
}
115117

116118
// If we're rendering an HTML snippet, we'll wrap it in a div, and return the resulting nodelist
117-
$dom = HTMLDocument::createFromString("<div id='tempest_render'>{$template}</div>", LIBXML_NOERROR | HTML_NO_DEFAULT_NS);
119+
$dom = HTMLDocument::createFromString("<div id='tempest_render'>{$template}</div>", $parserFlags);
118120

119121
return $dom->getElementById('tempest_render')->childNodes;
120122
}

tests/Integration/View/ViewComponentTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ public function test_empty_slots_are_commented_out(): void
500500
HTML);
501501

502502
$this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML'
503-
<html lang="en"><head><!--<x-slot name="styles" ></x-slot>--><link rel="stylesheet" href="#"></link></head><body></body></html>
503+
<html lang="en"><head><!--<x-slot name="styles" ></x-slot>--><link rel="stylesheet" href="#"></link></head></html>
504504
HTML, $html);
505505
}
506506
}

0 commit comments

Comments
 (0)