Skip to content

Commit

Permalink
feat: fix html qoute issue
Browse files Browse the repository at this point in the history
  • Loading branch information
shailesh-sf committed Nov 14, 2024
1 parent 055ba08 commit 8c250b5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 19 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/migration/related/LwcMigration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
54 changes: 38 additions & 16 deletions src/utils/lwcparser/htmlParser/HTMLParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,48 @@ export class HTMLParser {
public replaceTags(namespaceTag: string): Map<string, string> {
const htmlContentMap = new Map<string, string>();
// 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 = `
// <html lang="en">
// <head>
// <meta charset="UTF-8" />
// <meta name="viewport" content="width=device-width, initial-scale=1.0" />
// <title>Replace Tags Example</title>
// </head>
// <span dir={_dir}>test</span>
// <body>
// <template>
// <vlocity_ins-input vertical-align=stretch>Hello Shailesh</vlocity_ins-input>
// <vlocity_ins-input vertical-align=stretch>Another Input</vlocity_ins-input>
// </template>
// </body>
// </html>`;

// Use a regular expression to match <omnistudio-input ...>...</omnistudio-input>
this.html = this.html.replace('/<'+namespaceTag+'-/g', '<c-').replace('/<'+namespaceTag+'-/g', '</c-');

console.log(this.html);
// htmlContentMap.set(FileConstant.MODIFIED_CONTENT, $.html());
htmlContentMap.set(FileConstant.MODIFIED_CONTENT, this.html);
return htmlContentMap;
}

Expand Down
5 changes: 5 additions & 0 deletions src/utils/lwcparser/xmlParser/XmlParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ export class XmlParser {
throw error;
}
}

// public isAutogenratedFile(filePath: string) {
// this.fileContent = fs.readFileSync(filePath, 'utf-8');
// return this.fileContent.includes('OmniScript Auto-generated');
// }
}
2 changes: 1 addition & 1 deletion test/utils/lwc/parser/htmlparser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ describe('HTMLParser test class', () => {
// 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');
});
});

0 comments on commit 8c250b5

Please sign in to comment.