WIP: transformations
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m38s
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m38s
This commit is contained in:
15
README.md
Normal file
15
README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Tui-Website
|
||||
|
||||
This is my terminal based website. It is served as a tui application via ssh and as a simple html page via https.
|
||||
|
||||
It contains information about me and my projects as well as blog entries about something I feel like writing something about.
|
||||
|
||||
## Open tasks
|
||||
|
||||
- [ ] BUG: when served via `wish-serve` the corresponding outputs are not pushed through the ssh connection
|
||||
- they are instead showed locally, which might cause issues with the docker container running in the background
|
||||
- very likely it is `tui-website` which causes this issue
|
||||
- not entirely as inputs are not passed through correctly to the below running application (i.e. `diffnav` via `serve git diff`)
|
||||
- [ ] Improve navigation
|
||||
- [ ] Have clickable/navigatable links inside of the tui application
|
||||
- [ ] Launch simple http server alongside tui application
|
||||
@@ -2,9 +2,8 @@
|
||||
|
||||
const std = @import("std");
|
||||
const vaxis = @import("vaxis");
|
||||
const Zmd = @import("zmd").Zmd;
|
||||
|
||||
const node2buffer = @import("node2buffer.zig");
|
||||
const converter = @import("node2buffer.zig").Markdown;
|
||||
const widget = @import("../widget.zig");
|
||||
|
||||
const Event = widget.Event;
|
||||
@@ -61,14 +60,10 @@ pub fn draw(this: *@This(), win: vaxis.Window) void {
|
||||
\\**h** home
|
||||
\\**t** test
|
||||
;
|
||||
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, .{}, null) catch @panic("failed to transform to cell array");
|
||||
converter.toBuffer(msg, this.allocator, &cells);
|
||||
|
||||
var col: usize = 0;
|
||||
var row: usize = 0;
|
||||
|
||||
@@ -4,7 +4,7 @@ const std = @import("std");
|
||||
const vaxis = @import("vaxis");
|
||||
const Zmd = @import("zmd").Zmd;
|
||||
|
||||
const node2buffer = @import("node2buffer.zig");
|
||||
const converter = @import("node2buffer.zig").Markdown;
|
||||
const widget = @import("../widget.zig");
|
||||
|
||||
const Event = widget.Event;
|
||||
@@ -67,19 +67,9 @@ pub fn update(this: *@This(), event: Event) void {
|
||||
|
||||
// TODO: support typst files as parser and display driver -> as I'll be using this file format anyway with my personal note system
|
||||
// - I should leverage the typst compiler! (i.e. maybe use the html export, once that is available?)
|
||||
var zmd = Zmd.init(this.allocator);
|
||||
defer zmd.deinit();
|
||||
|
||||
this.buffer.clearRetainingCapacity();
|
||||
zmd.parse(this.contents.?) catch @panic("failed to parse markdown contents");
|
||||
node2buffer.toBuffer(
|
||||
zmd.nodes.items[0],
|
||||
this.allocator,
|
||||
this.contents.?,
|
||||
&this.buffer,
|
||||
.{},
|
||||
null,
|
||||
) catch @panic("failed to transform to cell array");
|
||||
converter.toBuffer(this.contents.?, this.allocator, &this.buffer);
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
|
||||
@@ -1,18 +1,43 @@
|
||||
///! Transform a given `zmd.Node` into a buffer which can be used by any `vaxis.widgets.View`
|
||||
///! Transform a given file type into a buffer which can be used by any `vaxis.widgets.View`
|
||||
///!
|
||||
///! Use the `toBuffer` method of any struct to convert the file type described by the
|
||||
///! struct to convert the file contents accordingly.
|
||||
const std = @import("std");
|
||||
const vaxis = @import("vaxis");
|
||||
const zmd = @import("zmd");
|
||||
|
||||
const digits = "0123456789";
|
||||
/// Markdown tronsformation to convert a markdown file as a `std.ArrayList(vaxis.cell)`
|
||||
pub const Markdown = struct {
|
||||
const zmd = @import("zmd");
|
||||
|
||||
pub fn toBuffer(
|
||||
const digits = "0123456789";
|
||||
|
||||
pub fn toBuffer(
|
||||
input: []const u8,
|
||||
allocator: std.mem.Allocator,
|
||||
array: *std.ArrayList(vaxis.Cell),
|
||||
) void {
|
||||
var z = zmd.Zmd.init(allocator);
|
||||
defer z.deinit();
|
||||
|
||||
z.parse(input) catch @panic("failed to parse markdown contents");
|
||||
convert(
|
||||
z.nodes.items[0],
|
||||
allocator,
|
||||
input,
|
||||
array,
|
||||
.{},
|
||||
null,
|
||||
) catch @panic("failed to transform parsed markdown to cell array");
|
||||
}
|
||||
|
||||
fn convert(
|
||||
node: *zmd.Node,
|
||||
allocator: std.mem.Allocator,
|
||||
input: []const u8,
|
||||
array: *std.ArrayList(vaxis.Cell),
|
||||
sty: vaxis.Cell.Style,
|
||||
start: ?usize,
|
||||
) !void {
|
||||
) !void {
|
||||
var next_start: ?usize = start;
|
||||
var style = sty;
|
||||
|
||||
@@ -263,6 +288,27 @@ pub fn toBuffer(
|
||||
|
||||
// run conversion for all childrens
|
||||
for (node.children.items) |child_node| {
|
||||
try toBuffer(child_node, allocator, input, array, style, next_start);
|
||||
try convert(child_node, allocator, input, array, style, next_start);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
pub const Typst = struct {
|
||||
pub fn toBuffer(
|
||||
input: []const u8,
|
||||
allocator: std.mem.Allocator,
|
||||
array: *std.ArrayList(vaxis.Cell),
|
||||
) void {
|
||||
// TODO: leverage the compiler to create corresponding file?
|
||||
// -> would enable functions to be executed, however this is not possible currently
|
||||
// -> this would only work if I serve the corresponding pdf's (maybe I can have a download server for these?)
|
||||
// NOTE: currently the typst compiler does not allow such a usage from the outside
|
||||
// -> I would need to wait for html export I guess
|
||||
|
||||
// TODO: use pret parsing to parse typst file contents and transform them into `vaxis.Cell`s accordingly
|
||||
_ = input;
|
||||
_ = allocator;
|
||||
_ = array;
|
||||
@panic("Typst parsing not yet implemented");
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user