2025-12-22 17:13:45 -05:00
2025-12-22 17:13:45 -05:00
2025-09-11 22:00:27 -04:00
2024-08-30 18:14:05 +01:00
2025-08-10 23:21:02 -04:00
2025-08-22 18:11:37 -04:00
2025-09-21 11:04:37 -04:00

Zmd

Zmd is a Markdown parser and HTML translator written in 100% pure Zig with zero dependencies.

Zmd is used by the Jetzig web framework.

Supported syntax

  • Headers (H1->H6)
  • bold
  • italic
  • code
  • Links
  • Images
  • Fenced code blocks (with info string)
  • Ordered lists
  • Unordered lists

Usage

const std = @import("std");
const zmd = @import("zmd");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    const allocator = gpa.allocator();

    const markdown = "# Header";

    const html = try zmd.parse(allocator, markdown, .{});
    defer allocator.free(html);

    const stdout = std.fs.File.stdout();
    try stdout.writeAll(html);
}

Customization

Formatter for supported markdown elements can be overridden with fuctions:

const html = zmd.parse(alloc, markdown, .{
    .block = myBlock,
})

The function signature for formatters is fn (Allocator, Node) ![]const u8

Some node types provie special attributes such as:

  • meta - provided on block elements. This is the language specifier (zig) in this example:
if (true) std.debug.print("some zig code");
  • href, title - provided on image and link elements.
fn myBlock(allocator: std.mem.Allocator, node: zmd.Node) ![]const u8 {
    const style = "font-family: Monospace;";

    return if (node.meta) |meta|
        std.fmt.allocPrint(allocator,
            \\<pre class="language-{s}" style="{s}"><code>{s}</code></pre>
        , .{ meta, style, node.content })
    else
        std.fmt.allocPrint(allocator,
            \\<pre style="{s}"><code>{s}</code></pre>
        , .{ style, node.content });
}

See src/zmd/Formatters.zig for the full reference.

License

Zmd is MIT-licensed.

Description
Zmd is a Markdown library written in Zig
Readme MIT 350 KiB
Languages
Zig 100%