Diff options
Diffstat (limited to 'custom/extensions/about-render.lua')
| -rw-r--r-- | custom/extensions/about-render.lua | 19 |
1 file changed, 13 insertions, 6 deletions
diff --git a/custom/extensions/about-render.lua b/custom/extensions/about-render.lua index 03c17d8..af4f0df 100644 --- a/custom/extensions/about-render.lua +++ b/custom/extensions/about-render.lua @@ -38,8 +38,9 @@ local max_depth = 24 local filename, tree_base, tree_query, chunks = "", "", "", {} --- How often each heading anchor has been handed out. The ids already on the --- page around the readme start at one, so no heading takes them. +-- The heading anchors handed out so far, each with the count its next +-- repeat takes. The ids already on the page around the readme are in it +-- from the start, so no heading takes them. local id_counts = {} @@ -259,10 +260,16 @@ local function emit_id(nodes) if base == "" then return end - local count = id_counts[base] or 0 - id_counts[base] = count + 1 + -- A count can land on an anchor a heading already took, as "Twice 1" + -- does after two of "Twice", so it goes on up until the anchor is free. + local id = base + while id_counts[id] do + id_counts[base] = id_counts[base] + 1 + id = base .. "-" .. id_counts[base] + end + id_counts[id] = 0 html(" id='") - html_attr(count > 0 and base .. "-" .. count or base) + html_attr(id) html("'") end @@ -972,7 +979,7 @@ function filter_open(name, base, query) tree_base = base or "" tree_query = query or "" chunks = {} - id_counts = { cgit = 1, header = 1, about = 1 } + id_counts = { cgit = 0, header = 0, about = 0 } end function filter_write(str) |
