Skip to content

Commit b222819

Browse files
committed
fixed handling of numbers in optional arguments
1 parent cd47d27 commit b222819

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
- 2025/01/15
4+
5+
- fixed handling of commands with number as optional arguments in the `make4ht-indexing` library.
6+
https://fosstodon.org/@[email protected]/113809011903088411
7+
38
- 2025/01/09
49

510
- convert horizontal rules in MathML arrays to the `rowlines` attribute.

make4ht-indexing.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ local function replace_index_pages(rest, entries)
100100
-- keep track of the previous page number
101101
local count = 0
102102
local delete_coma = false
103-
return rest:gsub("(%s*%-*%s*)(,?%s*)(%{?)(%d+)(%}?)", function(dash, coma, lbrace, page, rbrace)
103+
return rest:gsub("(%s*%-*%s*)(,?%s*)(%{?)(%[?)(%d+)(%]?)(%}?)", function(dash, coma, lbrace, lbracket, page, rbracket, rbrace)
104+
if lbracket == "[" and rbracket == "]" then
105+
-- don't process numbers in brackets, they are not page numbers
106+
return nil
107+
end
104108
local entry = entries[tonumber(page)]
105109
count = count + 1
106110
if entry then
@@ -128,7 +132,7 @@ local function replace_index_pages(rest, entries)
128132
return dash .. coma.. lbrace .. "\\Link[" .. entry.file .."]{".. entry.dest .."}{}" .. page .."\\EndLink{}" .. rbrace
129133
end
130134
else
131-
return dash .. coma .. lbrace .. page .. rbrace
135+
return dash .. coma .. lbrace .. lbracket .. page .. rbracket .. rbrace
132136
end
133137
end)
134138
end
@@ -139,7 +143,7 @@ local fix_idx_pages = function(content, idxobj)
139143
local buffer = {}
140144
local entries = idxobj.map
141145
for line in content:gmatch("([^\n]+)") do
142-
local line, count = line:gsub("(%s*\\%a+.-%,)(.+)$", function(start,rest)
146+
local line, count = line:gsub("(%s*\\%a+[^%[^,]+)(.+)$", function(start,rest)
143147
-- reset the previous page number
144148
previous = nil
145149
-- there is a problem when index term itself contains numbers, like Bible verses (1:2),

0 commit comments

Comments
 (0)