From b8a6994bafa660055b0b020aec40e0eb06b7d21a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Mon, 28 Sep 2026 09:27:16 +0200 Subject: [PATCH] markdown: keep standalone href-less anchors on their own line Adjacent placeholder anchors, like a JS-driven nav, ran together as HomeAbout. Keep the standalone line placement linked anchors get and drop only the link syntax. --- src/browser/markdown.zig | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/browser/markdown.zig b/src/browser/markdown.zig index a789a1c4d..c4c756eac 100644 --- a/src/browser/markdown.zig +++ b/src/browser/markdown.zig @@ -82,6 +82,8 @@ const Context = struct { // what follows after the children const Epilogue = union(enum) { none, + // A standalone anchor without href: its own line, but no link syntax. + standalone_text, element: Element.Tag, block_anchor: struct { href: []const u8, label: ?[]const u8 }, inline_anchor: struct { href: []const u8, standalone: bool }, @@ -258,12 +260,16 @@ const Context = struct { return; }, .anchor => { + const frame = self.frame; // Without href, is a placeholder, not a hyperlink. const href_raw = el.getAttributeInterned("href") orelse { - return self.open(.init(self.tree.content(el, boxed)), .none); + if (!RenderTree.isStandaloneAnchor(el, frame)) { + return self.open(.init(self.tree.content(el, boxed)), .none); + } + try self.ensureNewline(); + return self.open(.init(self.tree.content(el, boxed)), .standalone_text); }; - const frame = self.frame; const info = RenderTree.analyzeContent(el.asNode(), frame); const label = getAnchorLabel(el); const href = URL.resolve(frame.local_arena, frame.base(), href_raw, .{ .encoding = frame.charset }) catch href_raw; @@ -308,6 +314,10 @@ const Context = struct { fn close(self: *Context, epilogue: Epilogue) Error!void { const tag = switch (epilogue) { .none => return, + .standalone_text => { + try self.ensureNewline(); + return; + }, .element => |t| t, .block_anchor => |anchor| { try self.ensureNewline(); @@ -754,8 +764,12 @@ test "browser.markdown: anchor fallback label" { test "browser.markdown: anchor without href is plain text" { try testMarkdownHTML( - \\
Tags: change deep
- , "Tags: change **deep**\n"); + \\

Read the glossary first.

+ , "\nRead the glossary first.\n"); + + try testMarkdownHTML( + \\ + , "Home\n**About**\n"); try testMarkdownHTML( \\