Improvements to #530 styling

This commit is contained in:
Zef Hemel
2023-10-29 12:10:30 +01:00
parent 63b614670c
commit 7e9a3f7b6a
5 changed files with 80 additions and 26 deletions
+15 -7
View File
@@ -7,10 +7,18 @@ export type Tag = {
} | string;
function htmlEscape(s: string): string {
return s.replace(/&/g, "&")
s = s.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;");
.replace(/"/g, "&quot;")
.replace(/\n/g, "<br>");
let oldS = s;
do {
oldS = s;
s = s.replace(/ /g, "&nbsp; ");
} while (s !== oldS);
return s;
}
export function renderHtml(t: Tag | null): string {
@@ -33,9 +41,9 @@ export function renderHtml(t: Tag | null): string {
if (t.name === Fragment) {
return body;
}
if (t.body) {
return `<${t.name}${attrs}>${body}</${t.name}>`;
} else {
return `<${t.name}${attrs}/>`;
}
// if (t.body) {
return `<${t.name}${attrs}>${body}</${t.name}>`;
// } else {
// return `<${t.name}${attrs}/>`;
// }
}