macro-html is a DSL for generating HTML¹. It aims to be fast, modular, cachable and concise. It does so by defining each element as a macro which expands to code printing the respective HTML source. It also employs a readtable syntax for element attributes.
macro-html.widgets is a collection of widget functions. Those functions utilize
macro-html to print compound HTML elements such as lists, forms or even complete documents. The provided widgets are documented in macro-html Widgets.
- 1. HTML5
macro-html exports an element macro for every valid HTML element as of HTML5. An element macro prints the respective HTML element including its attributes, child elements and text nodes to
*standard-output*. Single element macros such as
br take a property list of attributes as their arguments, e.g.
(br :class "foo" ...). Regular tag macros such as
p take an arbitrary number of children as arguments. The first argument can optionally be an attribute list, e.g.
(p '(:attributes :class "bar" ...) "foo" ...).
In order to ease specifying attributes for regular element macros the readtable
macro-html:syntax provides a specialized reader syntax, e.g.
(p [:class "bar" ...] "foo" ...).
Every child form gets evaluated exactly once. If a form evaluates to a string or pathname it will be escaped and printed inside the element, otherwise its return value will be ignored. Element macros can be nested to produce compound HTML output.
html-doctype prints the HTML
!DOCTYPE element to
*standard-output*. The macro
text evaluates its body forms as if they were children of a element macro and can be used to explicitly print text nodes.
macro-html depends on
named-readtables and shadows
time as those symbols collide with HTML element names.