From 8c250b5bafb1e48d99686f83c1b95e21bf60811c Mon Sep 17 00:00:00 2001 From: "Shailesh M. Pachbhai" Date: Thu, 14 Nov 2024 18:46:57 +0530 Subject: [PATCH] feat: fix html qoute issue --- package.json | 1 - src/migration/related/LwcMigration.ts | 2 +- src/utils/lwcparser/htmlParser/HTMLParser.ts | 54 ++++++++++++++------ src/utils/lwcparser/xmlParser/XmlParser.ts | 5 ++ test/utils/lwc/parser/htmlparser.test.ts | 2 +- 5 files changed, 45 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 02b3e23..0eb7da9 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,6 @@ "@types/jsdom": "^21.1.7", "@types/lodash.chunk": "^4.2.9", "@types/shelljs": "^0.8.15", - "cheerio": "^1.0.0", "jsdom": "^25.0.0", "lodash.chunk": "^4.2.0", "open": "^8.4.2", diff --git a/src/migration/related/LwcMigration.ts b/src/migration/related/LwcMigration.ts index 2c4caf1..3126248 100644 --- a/src/migration/related/LwcMigration.ts +++ b/src/migration/related/LwcMigration.ts @@ -63,7 +63,7 @@ export class LwcMigration extends BaseRelatedObjectMigration implements RelatedO const jsonData: LWCAssessmentInfo[] = []; fileMap.forEach((fileList, dir) => { const changeInfos: FileChangeInfo[] = []; - if (dir !== 'lwc' && !dir.endsWith('English') && !dir.includes('_') && !dir.includes('cf')) { + if (dir !== 'lwc' && !dir.endsWith('English') && !dir.includes('_') && !dir.startsWith('cf')) { for (const file of fileList) { if (this.isValideFile(file.name)) { const processor = FileProcessorFactory.getFileProcessor(file.ext); diff --git a/src/utils/lwcparser/htmlParser/HTMLParser.ts b/src/utils/lwcparser/htmlParser/HTMLParser.ts index 6230cdf..a1c3805 100644 --- a/src/utils/lwcparser/htmlParser/HTMLParser.ts +++ b/src/utils/lwcparser/htmlParser/HTMLParser.ts @@ -40,26 +40,48 @@ export class HTMLParser { public replaceTags(namespaceTag: string): Map { const htmlContentMap = new Map(); // Load the HTML into cheerio - const $ = this.parser; + //const $ = this.parser; htmlContentMap.set(FileConstant.BASE_CONTENT, this.html); // Find all tags that contain the substring "omnistudio" in their tag name - $('*').each((i, element) => { - if (element.type === TAG && element.name && element.name.includes(namespaceTag + '-')) { - // Create a new tag with the same content and attributes as the old tag - const newTag = DEFAULT_NAMESPACE + element.name.substring(element.name.indexOf('-')); - const newElement = $(`<${newTag}>`).html($(element).html()); + // $('*').each((i, element) => { + // if (element.type === TAG && element.name && element.name.includes(namespaceTag + '-')) { + // // Create a new tag with the same content and attributes as the old tag + // const newTag = DEFAULT_NAMESPACE + element.name.substring(element.name.indexOf('-')); + // const newElement = $(`<${newTag}>`).html($(element).html()); - // Copy all attributes from the old element to the new one - Object.keys(element.attribs).forEach((attr) => { - newElement.attr(attr, $(element).attr(attr)); - }); + // // Copy all attributes from the old element to the new one + // Object.entries(element.attribs).forEach(([key, value]) => { + // newElement.attr(key, value); + // }); - // Replace the old element with the new one - $(element).replaceWith(newElement); - } - }); - $.html().replace(/\n\s*/g, ''); - htmlContentMap.set(FileConstant.MODIFIED_CONTENT, $.html()); + // // Replace the old element with the new one + // $(element).replaceWith(newElement); + // } + // }); + // // $.html().replace(/\n\s*/g, ''); + +// let html = ` +// +// +// +// +// Replace Tags Example +// +// test +// +// +// +// `; + +// Use a regular expression to match ... +this.html = this.html.replace('/<'+namespaceTag+'-/g', ' { // eslint-disable-next-line no-console console.log(new FileDiffUtil().getFileDiff('file.txt', html.get('original'), html.get('modified'))); htmlParser.saveToFile('test/utils/lwc/parser/output/test.html', html.get('modified')); - expect(htmlParser.getModifiedHTML()).contains('c-input'); + expect(htmlParser.getModifiedHTML()).contains('c-omniscript-step-chart'); }); });