@@ -39,12 +39,16 @@ function processConditionals(html, attributes) {
3939 const ifdefRegex = / \$ \$ i f d e f : ( [ a - z A - Z 0 - 9 _ ] + ) \$ \$ ( [ \s \S ] * ?) \$ \$ e n d i f \$ \$ / g;
4040
4141 return html . replace ( ifdefRegex , ( match , attrName , content ) => {
42+ if ( attrName === "value" || attrName === "xmlns" ) return content ;
43+
4244 const attribute = attributes . find ( attr => attr . name === attrName ) ;
4345
4446 // If the attribute exists, keep the content (without the ifdef/endif tags)
4547 if ( attribute && attribute . value ) {
4648 // Replace $$attrName$$ with the attribute value
47- return content . replace ( new RegExp ( `\\$\\$${ attrName } \\$\\$` , 'g' ) , attribute . value ) ;
49+ content = content . replace ( new RegExp ( `\\$\\$${ attrName } \\$\\$` , 'g' ) , attribute . value ) ;
50+ content = content . replace ( new RegExp ( `___${ attrName } ___` , 'g' ) , attribute . value ) ;
51+ return content ;
4852 }
4953
5054 // If the attribute doesn't exist or is empty, remove the entire block
@@ -77,22 +81,14 @@ export async function parse(originalHtml, reload = false) {
7781
7882 componentHtml = processConditionals ( componentHtml , attributes ) ;
7983
80-
81- const componentDom = new DOMParser ( ) . parseFromString ( componentHtml , 'text/html' ) ;
82-
83- // Replace <slot> with inner elements nodes
84- const innerHtml = new XMLSerializer ( ) . serializeToString ( element ) ;
85- replaceTagWithValue ( componentDom , 'slot' , innerHtml ) ;
86-
87- // Replace <slot:attribute></slot:attribute> with attribute value
88- for ( const attribute of attributes ) {
89- replaceTagWithValue ( componentDom , `slot-${ attribute . name } ` , attribute . value ) ;
84+ let innerHtml = new XMLSerializer ( ) . serializeToString ( element ) ;
85+ let innerText = innerHtml ;
86+ if ( element . childNodes . length > 0 && element . childNodes [ 0 ] . nodeType == 3 ) {
87+ innerText = element . childNodes [ 0 ] . textContent ;
9088 }
9189
92- componentHtml = new XMLSerializer ( ) . serializeToString ( componentDom ) ;
93-
9490 // Replace $$attribute$$ with attribute value
95-
91+
9692 const regex = / \$ \$ ( [ a - z A - Z 0 - 9 _ ] + ) \$ \$ / g;
9793 let match ;
9894 while ( ( match = regex . exec ( componentHtml ) ) !== null ) {
@@ -103,10 +99,27 @@ export async function parse(originalHtml, reload = false) {
10399
104100
105101
106-
102+
107103
108104 // Replace $$value$$ with innerHtml
109- componentHtml = componentHtml . replace ( / \$ \$ v a l u e \$ \$ / g, innerHtml ) ;
105+ componentHtml = componentHtml . replace ( / _ _ _ v a l u e _ _ _ / g, innerText ) ;
106+ componentHtml = componentHtml . replace ( / \$ \$ v a l u e \$ \$ / g, innerText ) ;
107+
108+
109+ const componentDom = new DOMParser ( ) . parseFromString ( componentHtml , 'text/html' ) ;
110+
111+
112+ // Replace <slot> with inner elements nodes
113+
114+ replaceTagWithValue ( componentDom , 'slot' , innerHtml ) ;
115+
116+ // Replace <slot:attribute></slot:attribute> with attribute value
117+ for ( const attribute of attributes ) {
118+ replaceTagWithValue ( componentDom , `slot-${ attribute . name } ` , attribute . value ) ;
119+ }
120+
121+ componentHtml = new XMLSerializer ( ) . serializeToString ( componentDom ) ;
122+
110123
111124
112125 const componentFragment = new DOMParser ( ) . parseFromString ( componentHtml , 'text/html' ) . documentElement ;
0 commit comments