Dead Simple HTML Templating in Emacs Lisp (2021-10) - Transform elisp
structures nearly verbatim to HTML, using elisp itself for generation,
loops, etc.
reddit / emacs
----------------------------------------------------------------------
deltille · 2022-05-18 04:18
----------------------------------------------------------------------
deltille · 2022-05-18 04:20
I found this recently, and it's been serving my HTML-building needs so
far beautifully. It's like a simpler version of [pp-
html](https://github.com/Kinneyzhang/pp-html) that just relies on
quoting/backquoting and the existing ecosystem of elisp functions for
evaluation (instead of its own idiosynrasies and operators as pp-html
seems to).
I didn't see it here and figured someone else might enjoy it as much
as me. I'm curious if anyone knows about any similar projects.
----------------------------------------------------------------------
polaris64 · 2022-05-18 12:13
You can also do something similar with `shr`: -
(shr-dom-to-xml
`(html ((lang . "en"))
(head ()
(meta ((charset . "UTF-8")))
(title () "shr-dom-to-xml test"))
(body ()
(div ((class . "my-class"))
(h1 () "HTML generated by shr!")
(ol ()
,@(cl-loop for i from 1 to 5 collect `(li
() ,(format " times %s is %s" 5 (* i 5)))))))))
----------------------------------------------------------------------
deltille · 2022-05-18 14:39
This is a great tip. I looked at "charge.el" source to make sure, and
it doesn't look like the author is using this one. I'll tuck this away
in case I deal with any weird DOM-specific issues down the line.
If you know off the top of your head, is there a similar builtin for
quickly flowing/breaking and indenting the kind of string-bean HTML
this produces?
----------------------------------------------------------------------
polaris64 · 2022-05-18 15:03
I've just taken a look at the source code of the `shr-dom-print`
function (which is called by `shr-dom-to-xml`) and it doesn't appear
so. It does however seem to be a fairly simple wrapper around various
functions from the built-in [dom.el](https://git.savannah.gnu.org/cgit
/emacs.git/tree/lisp/dom.el), so it would be very easy to create a
modified version.