Say that one day we decide to write a new templating library for generating HTML.
In this new library, you are passed an array where the first element is the name of an HTML tag, the second element is optionally a hash containing the element's HTML attributes, and the rest of the elements are the HTML elements that are children of it.
For example:
html = [:html,
[:body,
[:div, {class: "container"},
[:h1, "Hello World"],
[:h2, "Awesome!"]
]
]
]
Your task is to write a function that accepts such an array and outputs a valid HTML string.
transform(html)
=> "<html><body><div class=\"container\"><h1>Hello World</h1><h2>Awesome!</h2></div></body></html>"
Assumptions:
- You will always be passed a valid array
- The tag name will always come in the form of a symbol (or a string if your language doesn't have symbols).
- There exists an array named
void_tags
that contains every void HTML tag.
void_tags = [
:area,
:base,
:br,
:col,
:command,
:embed,
:hr,
:img,
:input,
:keygen,
:link,
:meta,
:param,
:source,
:track,
:wbr
]