@@ -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
@@ -75,24 +79,15 @@ export async function parse(originalHtml, reload = false) {
7579 let componentHtml = chtml ;
7680 const attributes = Array . from ( element . attributes ) ;
7781
78- componentHtml = processConditionals ( componentHtml , attributes ) ;
79-
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 ) ;
8682
87- // Replace <slot:attribute></slot:attribute> with attribute value
88- for ( const attribute of attributes ) {
89- replaceTagWithValue ( componentDom , `slot-${ attribute . name } ` , attribute . value ) ;
83+ let innerHtml = new XMLSerializer ( ) . serializeToString ( element ) ;
84+ let innerText = innerHtml ;
85+ if ( element . childNodes . length > 0 && element . childNodes [ 0 ] . nodeType == 3 ) {
86+ innerText = element . childNodes [ 0 ] . textContent ;
9087 }
9188
92- componentHtml = new XMLSerializer ( ) . serializeToString ( componentDom ) ;
93-
9489 // Replace $$attribute$$ with attribute value
95-
90+
9691 const regex = / \$ \$ ( [ a - z A - Z 0 - 9 _ ] + ) \$ \$ / g;
9792 let match ;
9893 while ( ( match = regex . exec ( componentHtml ) ) !== null ) {
@@ -103,10 +98,28 @@ export async function parse(originalHtml, reload = false) {
10398
10499
105100
106-
101+
107102
108103 // Replace $$value$$ with innerHtml
109- componentHtml = componentHtml . replace ( / \$ \$ v a l u e \$ \$ / g, innerHtml ) ;
104+ componentHtml = componentHtml . replace ( / _ _ _ v a l u e _ _ _ / g, innerText ) ;
105+ componentHtml = componentHtml . replace ( / \$ \$ v a l u e \$ \$ / g, innerText ) ;
106+
107+ componentHtml = processConditionals ( componentHtml , attributes ) ;
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