Skip to content

Commit

Permalink
remove duplicate index locators
Browse files Browse the repository at this point in the history
  • Loading branch information
michal-h21 committed Dec 20, 2024
1 parent ef53e27 commit ee28a8b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

- 2024/12/20

- remove duplicate index locators in the `make4ht-indexing` library.
https://tex.stackexchange.com/a/733106/2891

- 2024/12/19

- fixed fatal error caused by handling comments in the `fixinlines` DOM filter.
Expand Down
19 changes: 15 additions & 4 deletions make4ht-indexing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,25 @@ end

-- replace numbers in .ind file with links back to text
local function replace_index_pages(rest, entries)
return rest:gsub("(%{?)(%d+)(%}?)", function(lbrace, page, rbrace)
-- keep track of the previous page number
local previous
return rest:gsub("(%s*%-*%s*)(,?%s*)(%{?)(%d+)(%}?)", function(dash, coma, lbrace, page, rbrace)
local entry = entries[tonumber(page)]
if entry then
page = entry.locator or page
-- construct link to the index entry
return lbrace .. "\\Link[" .. entry.file .."]{".. entry.dest .."}{}" .. page .."\\EndLink{}" .. rbrace
-- if the page number is the same as the previous one, don't create a link
-- this can happen when we use section numbers as locators. for example,
-- we could get 1.1 -- 1.1, 1.1, so we want to keep only the first one
if page == previous then
previous = page
return ""
else
previous = page
-- construct link to the index entry
return dash .. coma.. lbrace .. "\\Link[" .. entry.file .."]{".. entry.dest .."}{}" .. page .."\\EndLink{}" .. rbrace
end
else
return lbrace .. page .. rbrace
return dash .. coma .. lbrace .. page .. rbrace
end
end)
end
Expand Down

0 comments on commit ee28a8b

Please sign in to comment.