Skip to content

gmi2html

Converts a hierarchy of Gemtext files (.gmi) into a mirrored hierarchy of HTML files. Written in C, no dependencies except a C library and Unity (vendored) for the tests.

This is the C re-implementation of the previous bash/awk version, which is kept in legacy/ for reference.

Features

  • Converts a hierarchy of Gemtext (.gmi) files into a mirrored HTML tree; images are copied along.
  • Incremental: only stale outputs are re-rendered; outputs inherit the source mtime.
  • --prune removes orphans in the output tree, --strict fails fast, --tags builds only the tag index.
  • Automatic tag index (tags.gmi + tags.html) from Tags: lines.
  • Editable style.css in the output root (created once, never overwritten), depth-relative links.
  • sitemap.xml generation from the input directory name.
  • Full Gemtext coverage: headings, links with .gmi→.html rewriting, image links as <img>, lists, blockquotes, preformatted blocks with HTML escaping, em-dash rule, paragraphs.
  • New output files inherit the output root's uid:gid (web server group-friendly).
  • Written in C with no dependencies except libc; vendored Unity tests with ASan/UBSan.

Prerequisites

  • GNU make and any C compiler (cc); no external libraries — the Unity test framework is vendored in vendor/.

Build

make          # builds bin/gmi2html
make test     # builds and runs the Unity test suite (ASan/UBSan)
make clean

Usage

gmi2html [OPTIONS] <input-dir> <output-dir>
  • input-dir must exist; output-dir is created (including parents) if missing.
  • .gmi files are converted to .html, the directory structure is mirrored 1:1. .jpg/.png files are copied.

Options

Option Effect
-s, --strict Abort on the first file error instead of warning and continuing
-p, --prune Delete files in the output tree that no longer have a source file (.html without .gmi, images without counterpart); removes empty directories. Foreign file types are left alone.
-t, --tags Only build tags.gmi in the input directory (no HTML); takes <input-dir> only
-h, --help Show help

Exit codes

Code Meaning
0 success
1 one or more file errors (warnings without --strict, immediate abort with --strict)
2 command line / directory errors (missing input dir, cannot create output dir, unknown option, …)

Behavior

  • Incremental: only files whose output is missing or older than the source are re-rendered. Output files inherit the mtime of their source.
  • Ownership: new files and directories in the output tree inherit the uid:gid of the output root (e.g. for web server groups).
  • Tag index: Tags: … lines are collected from all .gmi files, deduplicated and sorted into tags.gmi at the input root (also served over Gemini). It is rebuilt on every run and also rendered as tags.html.
  • Stylesheet: the CSS lives in style.css in the output root, not inline. It is created with defaults on the first run if missing and is never overwritten afterwards — edit it freely, it is not part of the distribution. Pages link it with a depth-relative path.
  • sitemap.xml: always written to the output root; base URL is the name of the input directory with https:// prepended (e.g. datenbrei.de → https://datenbrei.de).
  • Gemtext coverage: headings, links (with .gmi→.html rewriting for relative links, <img> for image links), single-level lists, quotes (consecutive > lines grouped into one <blockquote>), preformatted blocks with HTML escaping, em-dash line (——) as <hr>, paragraphs.
  • The HTML scaffold (inline CSS, meta tags, Indieweb/h-card markup) is hard-coded, ported from the legacy awk script.

Details, decisions and deviations from the legacy version: see SPEC.md (English) and SPEC.de.md (German).

Layout

src/main.c        CLI orchestration: walking, incremental rendering,
                  copying, tags pass, sitemap, prune, ownership
src/core/gemtext  Gemtext → HTML conversion (pure, unit-tested)
src/core/tags     tags.gmi building (pure, unit-tested)
src/core/cli      command line parsing (pure, unit-tested)
tests/            Unity tests (runner is generated, do not edit
                  tests/test_main.c by hand)
vendor/unity      Unity test framework
tools/gen_runner.sh  generates the Unity test runner
legacy/           the previous bash/awk implementation, for reference

License

MIT — see https://opensource.org/license/mit. The legacy bash/awk code is MIT licensed as well (see legacy/gmi2html.sh).

Contact

devel ät datenbrei.de

Download & Release Notes