Improve support when code occurrs multiple times

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
Danila Fedorin 2024-05-22 17:05:38 -07:00
parent f78f877e21
commit 9d0dcd98bd

12
agda.rb
View File

@ -222,10 +222,18 @@ class Handler
# module HTML files. So, note the ID that we want to redirect, # module HTML files. So, note the ID that we want to redirect,
# and pick a new unique ID to replace it with. # and pick a new unique ID to replace it with.
id = match[:id].to_s id = match[:id].to_s
uniq_id = "agda-unique-ident-#{id_counter}" local_href = "#{html_file}##{id}"
# The same piece of Agda module code could have been included
# twice (e.g., a snippet first, then the surrounding code)
# In that case, don't assign it a new ID; prefer the earlier
# occurrence.
uniq_id = seen_hrefs.fetch(local_href) do
new_id = "agda-unique-ident-#{id_counter}"
id_counter += 1 id_counter += 1
seen_hrefs[local_href] = new_id
end
new_link['id'] = uniq_id new_link['id'] = uniq_id
seen_hrefs["#{html_file}##{id}"] = uniq_id
end end
new_link.content = content[relative_from...relative_to] new_link.content = content[relative_from...relative_to]