Fix CSS errors when using HTML escaped quotes

This commit is contained in:
Derek Yang
2024-12-04 23:48:25 -05:00
parent 309454fe80
commit 4685d75964
2 changed files with 18 additions and 0 deletions

View File

@@ -198,6 +198,17 @@ function updateContent(c: EmbeddedRegion, content: string): string {
if (!c.attributeValue && c.languageId === 'javascript') {
return content.replace(`<!--`, `/* `).replace(`-->`, ` */`);
}
if (c.languageId === 'css') {
const quoteEscape = /(&quot;|&#34;)/g;
return content.replace(quoteEscape, (match, _, offset) => {
const spaces = ' '.repeat(match.length - 1);
const afterChar = content[offset + match.length];
if (!afterChar || afterChar.includes(' ')) {
return `${spaces}"`;
}
return `"${spaces}`;
});
}
return content;
}