diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-25 18:48:31 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-25 18:48:31 +0200 |
| commit | 7ce1e3fdeb407b4485e44da811086a388e6a17b3 (patch) | |
| tree | e732d95f741c40d8390bb54f9ac0aae5d66b0d8b /src/root.zig | |
| parent | b53f5e086c3fa41083a3a17d73ffa3e8d4fa3872 (diff) | |
feat(lib): returns document instead of html
Diffstat (limited to 'src/root.zig')
| -rw-r--r-- | src/root.zig | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/root.zig b/src/root.zig index 32f48ef..185e6b6 100644 --- a/src/root.zig +++ b/src/root.zig @@ -1,6 +1,8 @@ const std = @import("std"); const builtin = @import("builtin"); +const Allocator = std.mem.Allocator; const parser = @import("parser.zig"); +pub const Document = parser.Document; pub const Error = parser.Error; inline fn getErrorCode(err: Error) u8 { @@ -45,7 +47,12 @@ var default_alloc: std.mem.Allocator = /// Use typdown_getErrorString to retrieve the string linked with the error code. /// Use parse if you are in Zig. export fn typdown_parse(content: [*:0]const u8, code: *u8) ?[*:0]const u8 { - const res = parse(default_alloc, std.mem.span(content)) catch |err| { + const doc = parse(default_alloc, std.mem.span(content)) catch |err| { + code.* = getErrorCode(err); + return null; + }; + defer doc.deinit(); + const res = doc.renderHTML(default_alloc) catch |err| { code.* = getErrorCode(err); return null; }; @@ -60,11 +67,11 @@ export fn typdown_parse(content: [*:0]const u8, code: *u8) ?[*:0]const u8 { /// Parse the content. /// /// Use parse if you are not in Zig. -pub fn parse(alloc: std.mem.Allocator, content: []const u8) Error![]const u8 { +pub fn parse(alloc: std.mem.Allocator, content: []const u8) Error!Document { return parser.parse(alloc, content); } -pub fn parseReader(alloc: std.mem.Allocator, r: *std.io.Reader) (Error || std.io.Reader.Error)![]const u8 { +pub fn parseReader(alloc: std.mem.Allocator, r: *std.io.Reader) (Error || std.io.Reader.Error)!Document { return parser.parseReader(alloc, r); } |
