import { CodeSection } from "../../types/CodeSection"; import { HtmlElement } from "../../types/html/HtmlElement"; import { HtmlElementType } from "../../types/html/HtmlElementType"; import { renderButton } from "./elements/button"; import { renderDiv } from "./elements/div"; import { renderInput } from "./elements/input"; import { renderParagraph } from "./elements/p"; import { HtmlButtonElement } from "../../types/html/HtmlButtonElement"; import { HtmlDivElement } from "../../types/html/HtmlDivElement"; import { HtmlInputElement } from "../../types/html/HtmlInputElement"; import { HtmlParagraphElement } from "../../types/html/HtmlParagraphElement"; import { renderList } from "./elements/list"; import { HtmlListElement } from "../../types/html/HtmlListElement"; export function renderHTML( { content }: CodeSection ) { const elements = content as HtmlElement[]; return elements .map( element => renderElement( element ) ) .join('\n'); } export function renderElement( element: HtmlElement ) { switch( element.tag ) { case HtmlElementType.Button: return renderButton( element as HtmlButtonElement ); case HtmlElementType.Div: return renderDiv( element as HtmlDivElement ); case HtmlElementType.Input: return renderInput( element as HtmlInputElement ); case HtmlElementType.Paragraph: return renderParagraph( element as HtmlParagraphElement ); case HtmlElementType.List: return renderList( element as HtmlListElement ); } }