Vgbvcf's picture
download
raw
1.08 kB
import type { AST, ElementAST, ElementAttribute } from './types';
import { voidTags } from './tags';
export const formatAttributes = (attributes: ElementAttribute[]) => {
return attributes.reduce((attrs, attribute) => {
const { key, value } = attribute;
if (value === null) return `${attrs} ${key}`;
if (key === 'style' && !value) return '';
const quoteEscape = value.indexOf("'") !== -1;
const quote = quoteEscape ? '"' : "'";
return `${attrs} ${key}=${quote}${value}${quote}`;
}, '');
};
export const toHTML = (tree: AST[]) => {
const htmlStrings: string[] = tree.map((node) => {
if (node.type === 'text') return node.content;
if (node.type === 'comment') return `<!--${node.content}-->`;
const { tagName, attributes, children } = node as ElementAST;
const isSelfClosing = voidTags.includes(tagName.toLowerCase());
if (isSelfClosing) return `<${tagName}${formatAttributes(attributes)}>`;
return `<${tagName}${formatAttributes(attributes)}>${toHTML(children)}</${tagName}>`;
});
return htmlStrings.join('');
};

Xet Storage Details

Size:
1.08 kB
·
Xet hash:
b979e948645db20bec6f7f41e7782f68b795e7aee50e036b6a2c0f4d87ad157f

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.