const std = @import("std"); const gemtext = @import("gemtext"); pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit(); const allocator = &gpa.allocator; var stream = std.io.getStdIn().reader(); var buffer: [1 << 20]u8 = undefined; var parser = gemtext.Parser.init(allocator); defer parser.deinit(); while (true) { const length = try stream.read(&buffer); if (length == 0) break; var arena = std.heap.ArenaAllocator.init(allocator); defer arena.deinit(); var offset: usize = 0; while (offset < length) { var result = try parser.feed(&arena.allocator, buffer[offset..length]); if (result.fragment) |*frag| { defer frag.free(&arena.allocator); try gemtext.renderer.gemtext(&[_]gemtext.Fragment{frag.*}, std.io.getStdOut().writer()); } offset += result.consumed; } } if (try parser.finalize(allocator)) |*frag| { defer frag.free(allocator); try gemtext.renderer.gemtext(&[_]gemtext.Fragment{frag.*}, std.io.getStdOut().writer()); } }