32 lines
1.2 KiB
Zig
32 lines
1.2 KiB
Zig
const std = @import("std");
|
|
const Children = @import("parser.zig").Children;
|
|
|
|
pub fn printChildren(writer: anytype, children: Children) @TypeOf(writer).Error!void {
|
|
for (children.items) |child| {
|
|
switch (child) {
|
|
.document => unreachable,
|
|
.heading => |heading| {
|
|
try writer.print("<h{0}>{1s}</h{0}>", .{ heading.level, heading.text });
|
|
},
|
|
.paragraph => |paragraph| {
|
|
try writer.print("<p>{s}</p>", .{paragraph.text});
|
|
},
|
|
.block_quote => |block_quote| {
|
|
try writer.print("<blockquote>", .{});
|
|
try printChildren(writer, block_quote.children);
|
|
try writer.print("</blockquote>", .{});
|
|
},
|
|
.list => |list| {
|
|
try writer.print("<ul>", .{});
|
|
try printChildren(writer, list.children);
|
|
try writer.print("</ul>", .{});
|
|
},
|
|
.list_item => |list_item| {
|
|
try writer.print("<li>", .{});
|
|
try printChildren(writer, list_item.children);
|
|
try writer.print("</li>", .{});
|
|
},
|
|
}
|
|
}
|
|
}
|