From a39e0a651657046f3b936d842147fa51523b6818 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Fri, 14 Feb 2025 10:10:37 +0000 Subject: [PATCH] docs/fix-links: handle `#anchor` targets on the same page --- docs/fix-links/filter.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/fix-links/filter.lua b/docs/fix-links/filter.lua index d17f19fb..3a320187 100644 --- a/docs/fix-links/filter.lua +++ b/docs/fix-links/filter.lua @@ -18,9 +18,13 @@ function Link(link) local target = link.target -- Check for relative links -- TODO: handle ../ - if hasPrefix("./", target) then - link.target = githubUrl .. sub(target, 3) - return link + while hasPrefix("./", target) do + -- strip leading ./ + target = sub(target, 3) + end + if hasPrefix("#", target) then + -- No-op for anchor targets on the same page + return nil end if not hasPrefix("https://", target) then link.target = githubUrl .. target