Skip to content

gmi2html — SPEC

Converts a hierarchy of Gemtext files (.gmi) into a mirrored hierarchy of HTML files. Re-implementation of the legacy version (bash/awk, see legacy/) in C.

Command line

gmi2html [OPTIONS] <input-dir> <output-dir>
  • Required arguments: input-dir and output-dir. If input-dir is missing or does not exist (or is not a directory or not readable): error message on stderr, usage hint, exit code 2. No partial results. If output-dir does not exist, it is created including any missing parent directories (like mkdir -p); if creation fails: exit 2.
  • Options:
  • -s, --strict: Abort immediately on file-level errors (exit code 1) instead of only warning.
  • -p, --prune: After converting, delete files in output-dir that no longer have a source file (.html without .gmi, .jpg/.png without counterpart); empty directories are removed. Foreign file types are left untouched. Without this option, nothing is deleted.
  • -t, --tags: Only build tags.gmi in input-dir (Gemini space) and convert nothing. Takes only input-dir as its single required argument.
  • -h, --help: Show usage, exit code 0.

Processing (normal mode, two passes)

Pass 1 — tag index (Gemini space): - Collect the Tags: … line from all .gmi files in the input tree, deduplicate the tags, sort them, and create tags.gmi in the input-dir (root) — format like the legacy version: # Tags, per tag ## <tag>, followed by => <path> <title> for each related file (title = its # line). - Always executed (also on incremental runs) so the index stays current.

Pass 2 — conversion: 1. Recursive walk over input-dir (including the freshly created tags.gmi, which therefore also lands in the output as tags.html). Per file: - .gmi → convert to .html, mirroring the path structure 1:1 (sub/dir/page.gmi → sub/dir/page.html). - .jpg, .png → copied 1:1. - Other files/directories: ignored. 2. Incremental: A file is only re-converted if the output is missing or older than the input (mtime comparison). Unchanged files are left untouched. 3. Preserved mtime: the output file gets the mtime of its input (like the legacy version). 3b. Inherited ownership: If the output root already exists, all newly created files and directories inside inherit its uid:gid (e.g. for web server groups). If the chown fails: warning, or abort with --strict. 4. style.css: The stylesheet is not inlined. On every run in normal mode, the tool ensures style.css exists in the output root: if it is missing, it is created with the default stylesheet (the former inline <style> block, see gmi_default_css()); an existing style.css is never overwritten — manual edits win. Newly created style.css inherits the output root's uid:gid. Prune never touches style.css (unmanaged extension). The rendered HTML links it with a depth-relative prefix (style.css at the root, ../style.css one level down, and so on), so it works at any hosting path. Site operators can edit or replace style.css freely; it is not part of the distribution. 5. sitemap.xml: Always created in the output root. The base URL is the name of the input directory (last path component) with https:// prepended — e.g. the directory datenbrei.de yields the base https://datenbrei.de. A directory name can never contain /, so a scheme in the name is impossible; the legacy scheme check was pointless and was dropped (Martin, 2026-11-15). Format like legacy: loc = base + relative path, lastmod from mtime, ISO-8601 with time zone. (baseurl.txt is no longer read — Martin, 2026-11-15.) 6. Prune (only with -p/--prune): Recursive walk over output-dir; .html files without a .gmi counterpart and .jpg/.png without a counterpart are deleted, afterwards empty directories are removed (bottom-up, never the output root itself). Other file types remain. sitemap.xml is recreated afterwards.

Gemtext → HTML (ported from the legacy awk 1:1, except where noted)

  • toggle: content up to the closing toggle goes into `<pre>` with HTML escaping (`&` `<` `>`). The alternative text after is ignored. An unclosed toggle at EOF: </pre> is still emitted.
  • ###, ##, # → <h3>, <h2>, <h1> (content trimmed, escaped).
  • > → consecutive > lines are grouped into one <blockquote> block; each line inside becomes a <p> (trimmed, escaped, empty content is skipped). The block is closed by a blank line, another line type, or the end of the file. (Deviation from legacy: there, every > was its own block.)
  • * → <li>, consecutive items are grouped into a <ul>; the <ul> is closed by any other line type (including pre).
  • => URL [description]:
  • Description trimmed + escaped; empty → URL as text.
  • Link to .jpg/.png → <img src="…" alt="…">.
  • Another relative/local link with .gmi → extension rewritten to .html.
  • Links with a scheme (scheme://) stay unchanged.
  • Output as <a href="…">…</a><br>.
  • The description is whitespace-normalized like awk field reconstruction in the legacy script ($1="" re-joins fields with single spaces).
  • —— (em-dash line) → <hr>.
  • All other non-empty lines → <p>…</p> (trimmed — leading and trailing whitespace, as decided by Martin 2026-11-15, deviating from legacy —, escaped). Empty lines produce nothing. Tags: lines are not filtered out — they appear as a normal paragraph.
  • Escape order and scope like legacy: & → &amp;, < → &lt;, > → &gt; — for all text content and link URLs.

HTML scaffold (like legacy, hard-coded)

  • <!DOCTYPE html>, lang="de", inline CSS (orange #F80, max-width 720px …), meta tags (viewport, referrer, proof, authorization_endpoint, rel=me) taken verbatim from legacy/gem2html.awk.
  • <title> = text of the file's first # line; if absent: empty.
  • Indieweb markup: article.h-entry, hidden p-author/p-name/ dt-published (datetime = date of mtime), h-card footer at the end. Note: the footer contains name/address hard-coded like legacy.

Error handling

  • All error messages are verbose and in English; on stderr, prefixed with gmi2html: error:.
  • Without --strict: per-file errors (unreadable, write failure) → warning on stderr with the file path, continue with the next file; exit code 1 at the end.
  • With --strict: the first error aborts immediately (exit 1); output written so far remains.
  • Program errors (missing input directory etc.): exit 2.
  • -t/--tags with two instead of one directory argument: usage error (exit 2). Same for -t combined with -p.
  • The tags mode does not treat --strict differently: an error writing tags.gmi → exit 1 with a warning as above.

Out of scope (v1)

  • No nested lists, no tables (Gemtext has none).
  • No asset formats other than jpg/png.
  • No configuration file for the template.