| 2 | import { voidTags } from './tags'; |
| 3 | |
| 4 | export const formatAttributes = (attributes: ElementAttribute[]) => { |
| 5 | return attributes.reduce((attrs, attribute) => { |
| 6 | const { key, value } = attribute; |
| 7 | if (value === null) return `${attrs} ${key}`; |
| 8 | if (key === 'style' && !value) return ''; |
| 9 | |
| 10 | const quoteEscape = value.indexOf("'") !== -1; |
| 11 | const quote = quoteEscape ? '"' : "'"; |
| 12 | return `${attrs} ${key}=${quote}${value}${quote}`; |
| 13 | }, ''); |
| 14 | }; |
| 15 | |
| 16 | export const toHTML = (tree: AST[]) => { |
| 17 | const htmlStrings: string[] = tree.map((node) => { |