add(zmd): parse markdown file contents and display the parsed contents
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 44s
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 44s
Not everything can be parsed and displayed correctly yet, however this will the default file format to use for adding page contents (i.e. normal pages, blog entries, etc.)
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
const std = @import("std");
|
||||
const vaxis = @import("vaxis");
|
||||
const Zmd = @import("zmd").Zmd;
|
||||
|
||||
const node2buffer = @import("node2buffer.zig");
|
||||
const widget = @import("../widget.zig");
|
||||
|
||||
const Event = widget.Event;
|
||||
@@ -51,23 +53,21 @@ pub fn draw(this: *@This(), win: vaxis.Window) void {
|
||||
const msg =
|
||||
\\# Goto
|
||||
\\
|
||||
\\*a* about
|
||||
\\*h* home
|
||||
\\**a** about
|
||||
\\**h** home
|
||||
;
|
||||
var zmd = Zmd.init(this.allocator);
|
||||
defer zmd.deinit();
|
||||
|
||||
var cells = std.ArrayList(vaxis.Cell).init(this.allocator);
|
||||
defer cells.deinit();
|
||||
|
||||
zmd.parse(msg) catch @panic("failed to parse markdown file");
|
||||
node2buffer.toBuffer(zmd.nodes.items[0], this.allocator, msg, &cells, .{}) catch @panic("failed to transform to cell array");
|
||||
|
||||
var col: usize = 0;
|
||||
var row: usize = 0;
|
||||
for (msg, 0..) |_, i| {
|
||||
const cell: vaxis.Cell = .{
|
||||
// each cell takes a _grapheme_ as opposed to a single
|
||||
// codepoint. This allows Vaxis to handle emoji properly,
|
||||
// particularly with terminals that the Unicode Core extension
|
||||
// (IE Mode 2027)
|
||||
.char = .{ .grapheme = msg[i .. i + 1] },
|
||||
.style = .{
|
||||
.fg = .{ .index = 6 },
|
||||
.bold = true,
|
||||
},
|
||||
};
|
||||
for (cells.items) |cell| {
|
||||
view.writeCell(col, row, cell);
|
||||
if (std.mem.eql(u8, cell.char.grapheme, "\n")) {
|
||||
col = 0;
|
||||
|
||||
Reference in New Issue
Block a user