Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
istarkov committed Jun 3, 2024
1 parent 5072d5f commit 108ec22
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion packages/cli/src/html-to-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ const convertTagName = (tagName: string) => {
return tag;
};

const escapeValue = (value: string) =>
value
.trim()
.replace(/\\/g, "\\\\")
.replace(/`/g, "\\`")
.replace(/\$/g, "\\$")
.replace(/\r/g, "\\r")
.replace(/\n/g, "\\n");

export const htmlToJsx = (html: string) => {
const parsedHtml = parseFragment(html);

Expand All @@ -74,7 +83,11 @@ export const htmlToJsx = (html: string) => {
for (const walkNode of walkChildNodes(parsedHtml)) {
switch (walkNode.type) {
case "text":
result += walkNode.value;
{
const escapedValue = escapeValue(walkNode.value);

result += escapedValue ? "{`" + escapedValue + "`}" : "";
}
break;
case "element-start":
{
Expand Down

0 comments on commit 108ec22

Please sign in to comment.