<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title>The Zanc Report</title><id>https://carlo.zancanaro.id.au/feeds/tags/meta.xml</id><subtitle>Tag: meta</subtitle><updated>2026-07-30T04:10:10Z</updated><link href="https://carlo.zancanaro.id.au/feeds/tags/meta.xml" rel="self" /><link href="https://carlo.zancanaro.id.au" /><entry><title>Syntax Highlighting in Haunt</title><id>https://carlo.zancanaro.id.au/posts/syntax-highlighting-in-haunt.html</id><author><name>Carlo Zancanaro</name><email>carlo@zancanaro.id.au</email></author><updated>2026-01-10T00:00:00Z</updated><link href="https://carlo.zancanaro.id.au/posts/syntax-highlighting-in-haunt.html" rel="alternate" /><content type="html">&lt;p&gt;I wrote &lt;a href=&quot;/posts/hello-world.md&quot;&gt;a post just under two years ago&lt;/a&gt; about setting up this blog, and then I didn't write anything else! Shame on me.&lt;/p&gt;
&lt;p&gt;Part of the issue that got me stuck is that I wanted syntax highlighting. The &amp;quot;standard&amp;quot; option for &lt;a href=&quot;https://dthompson.us/projects/guile-syntax-highlight.html&quot;&gt;Haunt&lt;/a&gt;[], but it has a pretty minimal set of supported languages. I wasn't satisfied with that.&lt;/p&gt;
&lt;p&gt;In the past I've used &lt;a href=&quot;https://pygments.org/&quot;&gt;Pygments&lt;/a&gt;, but I wasn't sure how to get that into Haunt.&lt;/p&gt;
&lt;p&gt;Well, it's been two years: I think it's finally time to solve this problem!&lt;/p&gt;
&lt;p&gt;I had some trouble finding a way to call an external process, passing something to its &lt;code&gt;stdin&lt;/code&gt; and reading something from its &lt;code&gt;stdout&lt;/code&gt;. In the end, I came up with something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code infostring=&quot;scheme&quot;&gt;(define (syntax-highlight-strings strings language)
  (let* ((push (pipe))
         (pull (pipe))
         (pid (spawn &amp;quot;pygmentize&amp;quot; `(&amp;quot;pygmentize&amp;quot; &amp;quot;-f&amp;quot; &amp;quot;html&amp;quot; ,language)
                     #:input (car push)
                     #:output (cdr pull))))
    ;; Write to the subprocess, then close the port
    (close-port (car push))
    (for-each (lambda (b) (display b (cdr push))) strings)
    (close-port (cdr push))

    ;; Read the result back in, then close the port.
    (close-port (cdr pull))
    (let ((result (get-string-all (car pull))))
      (close-port (car pull))
      (waitpid pid)
      result)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This uses &lt;code&gt;spawn&lt;/code&gt; to start a &lt;code&gt;pygmentize&lt;/code&gt; process, writes a list of strings to it, then reads the result back.&lt;/p&gt;
&lt;p&gt;We can then walk the whole tree to find the shape that the &lt;a href=&quot;https://codeberg.org/spritely/guile-commonmark&quot;&gt;guile-commonmark&lt;/a&gt; reader emits for fenced code blocks with a language (which is &lt;code&gt;&amp;lt;pre&amp;gt;&amp;lt;code class=&amp;quot;language-scheme&amp;quot;&amp;gt;...&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;&lt;/code&gt;).&lt;/p&gt;
&lt;pre&gt;&lt;code infostring=&quot;scheme&quot;&gt;(define (syntax-highlight sxml-tree)
  (define (language-from-attrs attrs)
    (let ((classname (assoc-ref attrs 'class)))
      (and classname
           (string-prefix? &amp;quot;language-&amp;quot; (car classname))
           (substring (car classname) 9))))

  (match sxml-tree
    (('pre ('code ('@ . attrs) . body))
     (match (html-&amp;gt;shtml (syntax-highlight-strings body (language-from-attrs attrs)))
       (('*TOP* element &amp;quot;\n&amp;quot;)
        `(div (@ ,@attrs) ,element))))
    ((tag ('@ . attrs) . bodies)
     (cons* tag (cons '@ attrs) (map syntax-highlight bodies)))
    (((? symbol? tag) . bodies)
     (cons tag (map syntax-highlight bodies)))
    ((? list? elements)
     (map syntax-highlight elements))
    (_ sxml-tree)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then it's just a matter of calling &lt;code&gt;syntax-highlight&lt;/code&gt; on the &lt;code&gt;post-sxml&lt;/code&gt; in our theme's &lt;code&gt;#:post-template&lt;/code&gt; function.&lt;/p&gt;
&lt;pre&gt;&lt;code infostring=&quot;scheme&quot;&gt;(define my-theme
  (theme #:name &amp;quot;My Made Up Theme&amp;quot;
         #:post-template (lambda (post)
                           `((h1 (,post-title post))
                             (div ,(syntax-highlight (post-sxml post)))))))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This sets up the HTML necessary for colours, but to get actual colours you'll need to generate a stylesheet with the colours you want. The &lt;code&gt;pygmentize&lt;/code&gt; command can do this. This will print the styles to stdout:&lt;/p&gt;
&lt;pre&gt;&lt;code infostring=&quot;sh&quot;&gt;pygmentize -S default -f html
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can include these styles in your page (either in a linked &lt;code&gt;.css&lt;/code&gt; file, or inline) and colours should appear.&lt;/p&gt;
</content></entry><entry><title>Hello, World!</title><id>https://carlo.zancanaro.id.au/posts/hello-world.html</id><author><name>Carlo Zancanaro</name><email>carlo@zancanaro.id.au</email></author><updated>2024-01-26T00:00:00Z</updated><link href="https://carlo.zancanaro.id.au/posts/hello-world.html" rel="alternate" /><content type="html">&lt;p&gt;As this blog enters the world, let us begin in the customary way: &amp;quot;hello, world!&amp;quot;&lt;/p&gt;
&lt;p&gt;This blog will be a place for me to write things. I'm not really trying to achieve anything with this, except to write more words, so keep your expectations low. 🙂&lt;/p&gt;
&lt;p&gt;For some reason, I have decided on a slightly odd software stack for this blog: I am using &lt;a href=&quot;https://dthompson.us/projects/haunt.html&quot;&gt;the Haunt static site generator&lt;/a&gt;. It is pretty bare-bones, and requires some up-front setup. Haunt is not much more than a Guile Scheme library for parsing posts and constructing pages from them. It has a few helpers, and a way to define &amp;quot;themes&amp;quot;, but not that much else.&lt;/p&gt;
&lt;p&gt;I decided to define a fancy style that I saw in an Org mode exporter time, to put the name of a language on the top-right of a code block.&lt;/p&gt;
&lt;pre&gt;&lt;code infostring=&quot;css&quot;&gt;pre code:after {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    padding: 10px;
    outline: 1px solid black;
}
pre:hover code:after {
    display: block;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I need to make sure to define a new style for each language I use, though.&lt;/p&gt;
&lt;pre&gt;&lt;code infostring=&quot;css&quot;&gt;.language-scheme:after { content: &amp;quot;Scheme&amp;quot;; }
.language-css:after { content: &amp;quot;CSS&amp;quot;; }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But I should also add some sort of source highlighting, I guess. I have no idea how hard that is going to be.&lt;/p&gt;
&lt;p&gt;Anyway, it's a start!&lt;/p&gt;
</content></entry></feed>