Hacker News new | ask | show | jobs
by lelanthran 876 days ago
You solved it with s expressions.

Replace the braces with parens and you can parse that into a tree with only a handful of lisp macros.

1 comments

The braces are quite deliberate. Firstly, parens are used often in writing and it would be a pain to have to escape them. Secondly, it integrates much easier with the Scheme code of my site generator this way. I can write in a file, something like:

  (define (code-block file-name)
    {pre {{code {class block}}
          #(cmd "highlight" (thisdir (string-append "posts/" file-name))
                "-O" "html" "--inline-css" "--fragment"
                "--line-numbers" "--line-number-length" "3")}})
And it fits quite nicely with surrounding code. The mapping of these curly expressions to Scheme ones is relatively simple, though there is a special case for joining words to brackets.

  {a {b} #c #@d} => `("a" ("b") ,c ,@d)
  {a {b}c} => `("a" ("b") join "c")
Sure, I didn't mean to imply that you didn't know what you were doing. I was just adding more context for those readers who don't know what an s-expression is.

FWIW, my first static blogging system (circa 2003) did almost exactly the same thing you are doing (except that I used `[]` for lists, not `{}`). IIRC, it was maybe 5-6 macros+functions (and some readtable magic) to turn every `[foo ...]` into `<foo> ... </foo>`, with support for attributes using `:name=value` syntax and a list of exceptions for non-closing tags such as `<br>`, etc.

I redid something like that recently, in C, and it turned out to be unreasonably larger to write than in Clisp.

TBH, these days it's better to simply stick to markdown, because the tooling is much better (previews as you type, tools to automatically generate the html, inline HTML for what markdown won't do, etc).