diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-08 19:57:40 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-08 19:58:40 +0200 |
| commit | d0a2f9b05a5df95f3d2800cb899c998d3c8d5fb6 (patch) | |
| tree | 318d963894c138edad769dc08da730df7587aec6 /src/z | |
| parent | 3d0d5d88458112e5cc276f650e02609dc85c5b87 (diff) | |
html-parser: fix custom element parsing
Diffstat (limited to 'src/z')
| -rw-r--r-- | src/z/App/root.zig | 5 | ||||
| -rw-r--r-- | src/z/html/parser.zig | 6 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/z/App/root.zig b/src/z/App/root.zig index 8fce591..b8ca529 100644 --- a/src/z/App/root.zig +++ b/src/z/App/root.zig @@ -2,13 +2,14 @@ const builtin = @import("builtin"); const std = @import("std"); const Element = @import("../root.zig").html.Element; const Document = @import("../root.zig").html.Document; +const Fragment = @import("../root.zig").html.Fragment; const Component = @import("../root.zig").Component; pub const Options = struct { name: []const u8, globals: []const Global, components: []const Component, - body: Element, + body: Fragment, theme: []const u8, pub const Global = struct { @@ -89,7 +90,7 @@ pub fn App(comptime options: Options) type { break :reg register_code; })}), .node("script", .{}, &.{.text(@embedFile("main.js"))}), - } ++ components ++ &[1]Element{options.body}, + } ++ components ++ options.body.elements, ), }), }; diff --git a/src/z/html/parser.zig b/src/z/html/parser.zig index ee926f1..c85cc16 100644 --- a/src/z/html/parser.zig +++ b/src/z/html/parser.zig @@ -5,7 +5,7 @@ const Attribute = mod.Attribute; const Tag = mod.Tag; const Fragment = mod.Fragment; -const alphanumeric: []const u8 = std.ascii.letters ++ .{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; +const tag_name: []const u8 = std.ascii.letters ++ .{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-' }; const void_elements: std.StaticStringMap(void) = .initComptime(.{ .{"area"}, .{"base"}, @@ -58,7 +58,7 @@ pub fn tag(buffer: []const u8) struct { Tag, []const u8 } { var buf: []const u8 = buffer[1..]; const name = name: { - const index = std.mem.findNone(u8, buf, alphanumeric) orelse @panic("uncosed tag"); + const index = std.mem.findNone(u8, buf, tag_name) orelse @panic("uncosed tag"); defer buf = buf[index..]; break :name buf[0..index]; }; @@ -137,7 +137,7 @@ pub fn attribute(buffer: []const u8) struct { Attribute, []const u8 } { buf = std.mem.trimStart(u8, buf, &std.ascii.whitespace); if (buf.len == 0 or buf[0] == '>') { - return .{ .name = name, .value = "" }; + return .{ .{ .name = name, .value = "" }, buf }; } if (buf[0] != '=') @panic("expected attr-eql"); |