Something went wrong. Try again.
Zig Markdown
Something went wrong. Try again.
Zig 100%
README.md
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
- template blocks (
{{...}})
Usage #
const std = @import("std");
const zmd = @import("zmd");
pub fn main(init: std.process.Init) !void {
const markdown =
\\# Header
\\## Sub-header
\\### Sub-sub-header
\\
\\some text in **bold** and _italic_
\\
\\a paragraph
\\
\\```
\\some code
\\some more code in the same block
\\and yet more code
\\```
\\some more text with a `code` fragment
\\- list item
\\ 1. ordered item
;
const stdout: std.Io.File = .stdout();
var buf: [256]u8 = undefined;
var writer = stdout.writer(init.io, &buf);
try zmd.parseSlice(markdown, &writer.interface, .{});
}
Customization #
The HTML output for each markdown element is defined by a Tag - a pair of opening and closing strings. The default tags are in Config.zig.
Tags can be overridden at runtime by passing a Config value to the parse functions. Individual tags not specified fall back to the configured defaults:
const html = zmd.parseAlloc(alloc, markdown, .{
.h1 = .{ .opening = "<h1 class=\"title\">", .closing = "</h1>\n" },
.block = .{ .opening = "<pre><code>", .closing = "</code></pre>\n" },
});
License #
Zmd is MIT-licensed.