Files
OpenMAIC/lib/export/html-parser/stringify.ts
T
wyucandClaude Opus 4.6 843d33e5cc chore: enforce Prettier formatting and fix lint issues
- Add .prettierignore to exclude vendor packages, lock files, markdown, and YAML
- Update .prettierrc: printWidth 100, singleQuote, trailingComma "all"
- Run Prettier across all source files for consistent formatting
- Fix unused imports (UserRequirements, setTTSProvider)
- Fix eslint-disable comment placement after Prettier reformat

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 16:09:45 +08:00

29 lines
1.0 KiB
TypeScript

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('');
};