Introduction to Lucid DSL
masterLucid is a DSL for writing HTML in Haskell. It uses a postfix underscore (_) to distinguish HTML elements (data) from standard Haskell functions (code).
Core Syntax Patterns
- Elements: Written with a postfix underscore (e.g.,
p_,div_,table_). - Nesting: Elements are nested using function application.
- Juxtaposition: Elements can be placed side-by-side using monoidal append (
<>) or monadic sequencing (doblocks). - Attributes: Attributes are set by providing an argument list before the content. Attributes also use the postfix underscore (e.g.,
class_,style_). - Text: Plain text is automatically escaped to prevent XSS.
-- Nesting via function application
table_ (tr_ (td_ (p_ "Hello, World!")))
-- Juxtaposition via monoidal append
p_ "hello" <> p_ "sup"
-- Juxtaposition via monadic sequencing
div_ (do p_ "hello"; p_ "sup")
-- Setting attributes
p_ [class_ "brand"] "Lucid Inc"