Skip to content

Commit

Permalink
fixed handling of numbers in optional arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
michal-h21 committed Jan 15, 2025
1 parent cd47d27 commit b222819
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

- 2025/01/15

- fixed handling of commands with number as optional arguments in the `make4ht-indexing` library.
https://fosstodon.org/@[email protected]/113809011903088411

- 2025/01/09

- convert horizontal rules in MathML arrays to the `rowlines` attribute.
Expand Down
10 changes: 7 additions & 3 deletions make4ht-indexing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ local function replace_index_pages(rest, entries)
-- keep track of the previous page number
local count = 0
local delete_coma = false
return rest:gsub("(%s*%-*%s*)(,?%s*)(%{?)(%d+)(%}?)", function(dash, coma, lbrace, page, rbrace)
return rest:gsub("(%s*%-*%s*)(,?%s*)(%{?)(%[?)(%d+)(%]?)(%}?)", function(dash, coma, lbrace, lbracket, page, rbracket, rbrace)
if lbracket == "[" and rbracket == "]" then
-- don't process numbers in brackets, they are not page numbers
return nil
end
local entry = entries[tonumber(page)]
count = count + 1
if entry then
Expand Down Expand Up @@ -128,7 +132,7 @@ local function replace_index_pages(rest, entries)
return dash .. coma.. lbrace .. "\\Link[" .. entry.file .."]{".. entry.dest .."}{}" .. page .."\\EndLink{}" .. rbrace
end
else
return dash .. coma .. lbrace .. page .. rbrace
return dash .. coma .. lbrace .. lbracket .. page .. rbracket .. rbrace
end
end)
end
Expand All @@ -139,7 +143,7 @@ local fix_idx_pages = function(content, idxobj)
local buffer = {}
local entries = idxobj.map
for line in content:gmatch("([^\n]+)") do
local line, count = line:gsub("(%s*\\%a+.-%,)(.+)$", function(start,rest)
local line, count = line:gsub("(%s*\\%a+[^%[^,]+)(.+)$", function(start,rest)
-- reset the previous page number
previous = nil
-- there is a problem when index term itself contains numbers, like Bible verses (1:2),
Expand Down

0 comments on commit b222819

Please sign in to comment.