zig-gemtext - A new gemini text parser


Date: 05.03.2021

Intro


In the last two days i created a new library called zig-gemtext which provides both spec-compliant parsing as well as rendering gemini text into the following formats:

The library is written in Zig, but exposes both a Zig and C api, so it can be used from pretty much any programming language or platform. In theory, the library should be compilable to wasm as well and be used from there.
The parser itself is a non-blocking streaming parser, so it's perfectly suitable for any asynchronous or stream processing, also combinable with the renderer.

You can get the source of the library here:
github.com/MasterQ32/zig-gemtext

Usage


Here's a small usage example of the library:

pub fn main() !void {
    var document = try gemtext.Document.parse(
      std.heap.page_allocator,
      std.io.getStdIn().reader(),
    );
    defer document.deinit();

    try gemtext.renderer.html(
      document.fragments.items, 
      std.io.getStdOut().writer(),
    );
}

Performance


I tested the library with a pretty naive benchmark and got those results:

148489113 Bytes (148 MB, 142 MiB) copied, 6,13719 s, 24,2 MB/s


I think it can be faster, but it's good enough for now.