88use Tempest \Core \Environment ;
99use Tempest \View \Element ;
1010use Tempest \View \Parser \TempestViewCompiler ;
11+ use Tempest \View \Parser \TempestViewParser ;
1112use Tempest \View \Slot ;
1213use Tempest \View \ViewComponent ;
1314
@@ -25,6 +26,7 @@ final class ViewComponentElement implements Element
2526 public function __construct (
2627 private readonly Environment $ environment ,
2728 private readonly TempestViewCompiler $ compiler ,
29+ private readonly ElementFactory $ elementFactory ,
2830 private readonly ViewComponent $ viewComponent ,
2931 array $ attributes ,
3032 ) {
@@ -100,12 +102,9 @@ public function compile(): string
100102 replace: function ($ matches ) {
101103 $ closingTag = '</ ' . $ matches ['tag ' ] . '> ' ;
102104
103- $ html = $ matches [0 ] . $ closingTag ;
105+ $ ast = TempestViewParser:: ast ( $ matches [0 ] . $ closingTag) ;
104106
105- $ dom = HTMLDocument::createFromString ($ html , LIBXML_HTML_NOIMPLIED | LIBXML_NOERROR | HTML_NO_DEFAULT_NS );
106-
107- /** @var \Dom\HTMLElement $element */
108- $ element = $ dom ->childNodes [0 ];
107+ $ element = $ this ->elementFactory ->make ($ ast [0 ]);
109108
110109 foreach (['class ' , 'style ' , 'id ' ] as $ attributeName ) {
111110 if (! isset ($ this ->dataAttributes [$ attributeName ])) {
@@ -125,12 +124,12 @@ public function compile(): string
125124 }
126125
127126 $ element ->setAttribute (
128- qualifiedName : $ attributeName ,
127+ name : $ attributeName ,
129128 value: $ value ,
130129 );
131130 }
132131
133- return str ($ element ->ownerDocument -> saveHTML ( $ element ))->replaceLast ($ closingTag , '' );
132+ return str ($ element ->compile ( ))->replaceLast ($ closingTag , '' );
134133 },
135134 )
136135 ->prepend (
0 commit comments