From 0260f392c19db7911496172c7d43d1178c6215cb Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Thu, 8 Oct 2026 17:44:46 +0200 Subject: add html parser --- src/z/Component.zig | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/z/Component.zig') diff --git a/src/z/Component.zig b/src/z/Component.zig index ba328b6..deab261 100644 --- a/src/z/Component.zig +++ b/src/z/Component.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const Fragment = @import("root.zig").html.Fragment; const Element = @import("root.zig").html.Element; const Attribute = @import("root.zig").html.Attribute; const Object = @import("Object.zig"); @@ -6,7 +7,7 @@ const Object = @import("Object.zig"); const Self = @This(); name: []const u8, -html: Element, +html: Fragment, css: []const u8, link: type, @@ -63,7 +64,9 @@ pub fn exportLinks(self: *const Self) void { }, ); - comptime self.exportFromHtml(self.html); + for (self.html.elements) |element| { + comptime self.exportFromHtml(element); + } } fn linkAttributes(self: *const Self, attributes: []const Attribute) []const Attribute { @@ -116,10 +119,17 @@ pub fn toElement(self: *const Self) []const Element { .node( "template", .{ .id = "@" ++ self.name }, - &.{ + [_]Element{ .node("style", .{}, &.{.text(self.css)}), - comptime self.linkHtmlRecursive(self.html), - }, + } ++ (html: { + var elements: []const Element = &.{}; + + for (self.html.elements) |element| { + elements = elements ++ .{self.linkHtmlRecursive(element)}; + } + + break :html elements; + }), ), .node( "script", -- cgit v1.2.3-70-g09d2