Monkeylib HTML
https://github.com/gigamonkey/monkeylib-html
monleylib-html is a library from Peter Seibel of Practical Common Lisp fame. It seems to be an implementation of HTML generation library described in the last two chapters of "Practical Common Lisp".
(ql:quickload '(:monkeylib-html :parenscript)) (defpackage monkeylib-examples (:use :cl :monkeylib-html))
Emit HTML to standard output:
(with-html-output (*standard-output*)
(html
((:body :id "a" :onclick "javascript: alert(1)")
(:h1 "Hello"))))
<body id='a' onclick='javascript: alert(1)'>
<h1>Hello</h1>
</body>
Helpers for standard output and string:
(defmacro htmlout (&body body)
`(with-html-output (*standard-output* :pretty t)
(html ,@body)))
(defmacro htmlstr (&body body)
`(with-output-to-string (out)
(with-html-output (out :pretty t)
(html ,@body))))
HTML5 preamble
(define-html-macro :html5 (&attributes attrs &body body)
`(:progn
(:noescape (:format "<!DOCTYPE html>"))
(:newline)
((:html ,@attrs)
,@body)))
(htmlout
((:html5 :lang "en")
(:h1 "Yay! HTML5")))
<!DOCTYPE html>
<html lang='en'>
<h1>Yay! HTML5</h1>
</html>
Parenscript
(define-html-macro :ps (&body body)
`(:noescape (:print (ps:ps ,@body))))
(htmlout
(:html5
(:head
(:script
(:ps (defun greet () (alert "Hello, world!")))))
(:body
((:button :onclick (:ps (greet))) "Click me!"))))
<!DOCTYPE html>
<html>
<head>
<script>function greet() {
__PS_MV_REG = [];
return alert('Hello, world!');
};</script>
</head>
<body>
<button onclick='greet();'>Click me!</button>
</body>
</html>
Components
TODO.