~andreadimatteo

.md to .html compiler

ยท

Hi, this is Andrea.

I'm new to Rust and thought that a very pratical way to get in touch with it was writing something. I've thought of writing my own .md to .html compiler for for a while. So here we are, both my micro-blog and my project have come to life. Before even thinking of writing it, I was using Hugo. It was really nice, but you know, sometimes it's just too much, I just wanted a very simple thing, not taking a lifetime choosing a theme and other stuff, or maybe as a SWE I thought I could just build it myself, and after 12-13 hours of my not really spare time I came eventually with something.

It's very basic, written with no GenAI tools, and as much docs as possible. I've implemented very basic .md syntax for now, eventually will expand later. Some time ago I read the dragon book, so writing a compiler was not a completely new thing, but it was fun to see that some of my own choices were pretty similar to actual .md to .html compilers, even Hugo itself.

The compilation follows the following steps:

[
    Heading {
        level: H1,
        content: [
            Text(
                "this\n",
            ),
        ],
    },
    Heading {
        level: H2,
        content: [
            Text(
                "is\n",
            ),
        ],
    },
    Paragraph(
        [
            Text(
                "a very ",
            ),
            Italic(
                "simple",
            ),
            Text(
                " ",
            ),
            Bold(
                "post",
            ),
            Text(
                "\n",
            ),
        ],
    ),
]

Output to file was particularly simple since redefining Display on Block => Inline made it no different than a simple display.

Here's a demo of the generated index and a couple posts.

demo

Let's now delve into some more technicalities: Every post starts with a YAML front matter block delimited by ---:

---
title: Building a markdown compiler
date: 2026-07-27
description: A short line shown in the index
tags: [rust, web]
draft: false
---

[markdown body]

title and date are required, the rest are optional. date is YYYY-MM-DD and drives the ordering of the index. Setting draft: true skips the post entirely. This is the list of the current CommonMark coverage:

The index.html is the whole post list, no pagination and no client side router, filtering can be done through the searhc bar on top of the page, (shortcut to searchbar is / and search text can be deleted with esc), or the tags on the single posts or still on top of page. You can navigate through posts and within posts with vim-like-moves (this is vibe-coded and theme dependent, hence I won't keep track of it try it, it's pretty cool, you can also yank text :) ). It's really early stage, so be careful with .md syntax, for instance split every block element with an empty line, don't have comprehensive tests for now.Don't think this tool will ever be useful for anyone besides me, but it was fun to make and surely will expand, the code can be found at this repo.