@@ -40,26 +40,48 @@ export class HTMLParser {
4040 public replaceTags ( namespaceTag : string ) : Map < string , string > {
4141 const htmlContentMap = new Map < string , string > ( ) ;
4242 // Load the HTML into cheerio
43- const $ = this . parser ;
43+ // const $ = this.parser;
4444 htmlContentMap . set ( FileConstant . BASE_CONTENT , this . html ) ;
4545 // Find all tags that contain the substring "omnistudio" in their tag name
46- $ ( '*' ) . each ( ( i , element ) => {
47- if ( element . type === TAG && element . name && element . name . includes ( namespaceTag + '-' ) ) {
48- // Create a new tag with the same content and attributes as the old tag
49- const newTag = DEFAULT_NAMESPACE + element . name . substring ( element . name . indexOf ( '-' ) ) ;
50- const newElement = $ ( `<${ newTag } >` ) . html ( $ ( element ) . html ( ) ) ;
46+ // $('*').each((i, element) => {
47+ // if (element.type === TAG && element.name && element.name.includes(namespaceTag + '-')) {
48+ // // Create a new tag with the same content and attributes as the old tag
49+ // const newTag = DEFAULT_NAMESPACE + element.name.substring(element.name.indexOf('-'));
50+ // const newElement = $(`<${newTag}>`).html($(element).html());
5151
52- // Copy all attributes from the old element to the new one
53- Object . keys ( element . attribs ) . forEach ( ( attr ) => {
54- newElement . attr ( attr , $ ( element ) . attr ( attr ) ) ;
55- } ) ;
52+ // // Copy all attributes from the old element to the new one
53+ // Object.entries (element.attribs).forEach(([key, value] ) => {
54+ // newElement.attr(key, value );
55+ // });
5656
57- // Replace the old element with the new one
58- $ ( element ) . replaceWith ( newElement ) ;
59- }
60- } ) ;
61- $ . html ( ) . replace ( / \n \s * / g, '' ) ;
62- htmlContentMap . set ( FileConstant . MODIFIED_CONTENT , $ . html ( ) ) ;
57+ // // Replace the old element with the new one
58+ // $(element).replaceWith(newElement);
59+ // }
60+ // });
61+ // // $.html().replace(/\n\s*/g, '');
62+
63+ // let html = `
64+ // <html lang="en">
65+ // <head>
66+ // <meta charset="UTF-8" />
67+ // <meta name="viewport" content="width=device-width, initial-scale=1.0" />
68+ // <title>Replace Tags Example</title>
69+ // </head>
70+ // <span dir={_dir}>test</span>
71+ // <body>
72+ // <template>
73+ // <vlocity_ins-input vertical-align=stretch>Hello Shailesh</vlocity_ins-input>
74+ // <vlocity_ins-input vertical-align=stretch>Another Input</vlocity_ins-input>
75+ // </template>
76+ // </body>
77+ // </html>`;
78+
79+ // Use a regular expression to match <omnistudio-input ...>...</omnistudio-input>
80+ this . html = this . html . replace ( '/<' + namespaceTag + '-/g' , '<c-' ) . replace ( '/<' + namespaceTag + '-/g' , '</c-' ) ;
81+
82+ console . log ( this . html ) ;
83+ // htmlContentMap.set(FileConstant.MODIFIED_CONTENT, $.html());
84+ htmlContentMap . set ( FileConstant . MODIFIED_CONTENT , this . html ) ;
6385 return htmlContentMap ;
6486 }
6587
0 commit comments