AXNode: add spacing between concatenated text nodes

When calculating accessible names for elements without explicit labels, multiple descendant text nodes were previously concatenated directly together. This adds a space between distinct text node contents to prevent words from sticking together.
This commit is contained in:
Adrià Arrufat
2026-03-11 10:45:07 +09:00
parent 6c7272061c
commit ca931a11be

View File

@@ -777,7 +777,8 @@ pub fn getName(self: AXNode, page: *Page, allocator: std.mem.Allocator) !?[]cons
const source = try self.writeName(w, page); const source = try self.writeName(w, page);
if (source != null) { if (source != null) {
// Remove literal quotes inserted by writeString. // Remove literal quotes inserted by writeString.
const raw_text = std.mem.trim(u8, aw.written(), "\""); var raw_text = std.mem.trim(u8, aw.written(), "\"");
raw_text = std.mem.trim(u8, raw_text, &std.ascii.whitespace);
return try allocator.dupe(u8, raw_text); return try allocator.dupe(u8, raw_text);
} }
@@ -908,7 +909,13 @@ fn writeAccessibleNameFallback(node: *DOMNode, writer: *std.Io.Writer, page: *Pa
while (it.next()) |child| { while (it.next()) |child| {
switch (child._type) { switch (child._type) {
.cdata => |cd| switch (cd._type) { .cdata => |cd| switch (cd._type) {
.text => |*text| try writer.writeAll(text.getWholeText()), .text => |*text| {
const content = std.mem.trim(u8, text.getWholeText(), &std.ascii.whitespace);
if (content.len > 0) {
try writer.writeAll(content);
try writer.writeByte(' ');
}
},
else => {}, else => {},
}, },
.element => |el| { .element => |el| {