jhtml:jhtml
is a function that takes in a list and spits out a string of
tightly packed html.
Take a sexp - it returns html! Intuitive, too.
(asdf:load-system :jhtml)
(jhtml:jhtml '(p "hello!")) ; => "<p>hello!</p>"
(jhtml:jhtml '((h1 "hi") (p "hey"))) ; => "<h1>hi</h1><p>hey</p>"
(jhtml:jhtml
`(div :class "package"
(h2 :class "package-name" "jhtml")
(p :class "package-description" "sexp to html converter!")))
Special rules are “special” tags that behave differently than one would expect any other tag to behave, for example the DOCTYPE. It doesn’t have a closing tag, nor does it have attributes, just one parameter, the document type.
(jhtml:jhtml '(doctype)) ; => "<!DOCTYPE html>"
(jhtml:jhtml '(doctype "another")) ; => "<!DOCTYPE another>"
(jhtml:jhtml
'((jhtml:doctype) ; special rule! (they belong to packages)
(html
(head
(title "Hello")
;; self-closing tags are keywords
;; this is because they're all special rules in the :KEYWORD package
(:link :rel "stylesheet" :type "text/css" :href "link/to/css"))
(body
(h1 "Hi!!")
(nil You can use a nil tag for comments!)
(p "whadup?")))))
The previous code will return: (formatted for clearness)
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
<link REL="stylesheet" TYPE="text/css" HREF="link/to/css" />
</head>
<body>
<h1>Hi!!</h1>
<p>whadup?</p>
</body>
</html>
inserts a doctype directive
(jhtml:jhtml '(jhtml:doctype)) ; => "<!DOCTYPE html>"
(jhtml:jhtml '(jhtml:doctype "another")) ; => "<!DOCTYPE another>"
because jhtml filters its strings to escape them, you need INSERT-HTML to insert raw html
;; without INSERT-HTML
(jhtml:jhtml '(head "<title>helo</title>")) ; => "<head><title>helo</title></head>"
;; with INSERT-HTML
(jhtml:jhtml
'(jhtml:insert-html
"<head><title>helo</title></head>")) ; => "<head><title>helo</title></head>"
mostly, it’s intended to be used for using jhtml within another jhtml call
(defun maths (a b)
(declare (ignorable a))
(jhtml:jhtml
`(html
(head (title "maths"))
(body
(jhtml:insert-html
,(when (> (+ a b) 10)
(jhtml:jhtml '((h1 "BIG!") (:hr)))))
(p ,a " + "
,b " = "
,(+ a b))))))
Because it sounds nice.