(.module: [lux #- comment] (lux (data [text] text/format (coll [list "L/" Functor])))) (type: #export Attributes {#.doc "Attributes for an HTML tag."} (List [Text Text])) (type: #export HTML Text) (def: #export (text value) {#.doc "Properly formats text to ensure no injection can happen on the HTML."} (-> Text HTML) (|> value (text.replace-all "&" "&") (text.replace-all "<" "<") (text.replace-all ">" ">") (text.replace-all "\"" """) (text.replace-all "'" "'") (text.replace-all "/" "/"))) (def: #export (comment content) (-> Text HTML) (format "")) (def: attrs-to-text (-> Attributes Text) (|>> (L/map (function (_ [key val]) (format key "=" "\"" (text val) "\""))) (text.join-with " "))) (def: #export (tag name attrs children) {#.doc "Generates the HTML for a tag."} (-> Text Attributes (List HTML) HTML) (format "<" name " " (attrs-to-text attrs) ">" (text.join-with " " children) "")) (do-template [ ] [(def: #export ( document) (-> HTML HTML) (format document))] [html-5 ""] [html-4_01 ""] [xhtml-1_0 ""] [xhtml-1_1 ""] )