Skip to content

Lightpanda: the headless browser designed for AI and automation

Merge branch 'main' into zig-0.17

Adrià Arrufat01a703f7e2f2
diff --cc src/browser/StyleManager.zig
index 32d2fe897,cc11f6a59..3b8c57ae7
--- a/src/browser/StyleManager.zig
+++ b/src/browser/StyleManager.zig
@@@ -736,14 -781,17 +781,17 @@@ fn Group(comptime Spec: type) type
return struct {
const Self = @This();
const Declared = Spec.Declared;
+ // What we store in our memo
const Computed = Spec.Computed;
+ // The element's own value, only used while resolving, never stored
+ const Cascaded = if (@hasDecl(Spec, "Cascaded")) Spec.Cascaded else Computed;
const Field = std.meta.FieldEnum(Declared);
- const fields = std.meta.fieldNames(Declared);
+ const fields = @typeInfo(Declared).@"struct".field_names;
comptime {
- // compute copies each declared value into its Computed namesake
+ // compute copies each declared value into its Cascaded namesake
for (fields) |field| {
- std.debug.assert(@FieldType(Computed, field) == @typeInfo(@FieldType(Declared, field)).optional.child);
+ std.debug.assert(@FieldType(Cascaded, field) == @typeInfo(@FieldType(Declared, field)).optional.child);
}
}
@@@ -1255,7 -1309,8 +1309,8 @@@ const Visibility = struct
}
};
- const Computed = packed struct(u6) {
+ // The element's own values, from the cascade.
- const Cascaded = packed struct(u6) {
++ pub const Cascaded = packed struct(u6) {
// Author value (inline or sheet). Without `author_display` it's the UA
// fallback: .none when matchesUaDisplayNoneRule, else .other.
display: Display = .other,
@@@ -1282,7 -1362,7 +1362,7 @@@
// element — per CSS Cascade §6.1 any normal-origin author rule beats UA
// origin regardless of specificity, so `.x { display: flex }` on a
// `<div class="x" hidden>` must report visible.
- pub fn finish(p: *Computed, el: *Element, priorities: *const Priorities(Declared)) void {
- fn finish(p: *Cascaded, el: *Element, priorities: *const Priorities(Declared)) void {
++ pub fn finish(p: *Cascaded, el: *Element, priorities: *const Priorities(Declared)) void {
p.author_display = priorities.get(.display) != 0;
if (!p.author_display and matchesUaDisplayNoneRule(el)) {
p.display = .none;
diff --cc src/browser/markdown.zig
index 6bf76e9a4,ca3a91d7c..2068f9c57
--- a/src/browser/markdown.zig
+++ b/src/browser/markdown.zig
@@@ -66,6 -65,29 +66,29 @@@ fn getAnchorLabel(el: *Element) ?[]cons
return el.getAttributeInterned("aria-label") orelse el.getAttributeInterned("title");
}
+ /// The fence info string for a `<pre>`: the `language-*` (or `lang-*`) class
+ /// on the `<pre>` itself or on a `<code>` that is its first element child.
+ fn codeLanguage(pre: *Element) ?[]const u8 {
+ if (classLanguage(pre)) |lang| return lang;
+ const child = pre.firstElementChild() orelse return null;
+ if (child.getTag() != .code) return null;
+ return classLanguage(child);
+ }
+
+ fn classLanguage(el: *Element) ?[]const u8 {
+ const class = el.getClassName() orelse return null;
+ var it = std.mem.tokenizeAny(u8, class, &std.ascii.whitespace);
+ while (it.next()) |token| {
+ for ([_][]const u8{ "language-", "lang-" }) |prefix| {
+ if (!std.mem.startsWith(u8, token, prefix)) continue;
+ const lang = token[prefix.len..];
+ // A backtick would end the fence's info string early.
- if (lang.len > 0 and std.mem.indexOfScalar(u8, lang, '`') == null) return lang;
++ if (lang.len > 0 and std.mem.findScalar(u8, lang, '`') == null) return lang;
+ }
+ }
+ return null;
+ }
+
// Iterative else large trees will stackoverflow
const Context = struct {
state: State,
diff --cc src/browser/webapi/net/Response.zig
index b1f493418,85cf63008..92e70bfaf
--- a/src/browser/webapi/net/Response.zig
+++ b/src/browser/webapi/net/Response.zig
@@@ -561,9 -580,10 +580,10 @@@ pub fn clone(self: *const Response, exe
.bytes => |b| .{ .bytes = try arena.dupe(u8, b) },
.empty => .empty,
.stream => .empty, // TODO: implement stream tee for proper cloning
+ .errored => .errored,
};
const status_text = try arena.dupe(u8, self._status_text);
- const url = try arena.dupeZ(u8, self._url);
+ const url = try arena.dupeSentinel(u8, self._url, 0);
const cloned = try arena.create(Response);
cloned.* = .{