Skip to content

Commit

Permalink
ignore numbers in braces in indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
michal-h21 committed Mar 29, 2024
1 parent 3c8af19 commit 3f1bc8d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

- 2024/03/29

- ignore numbers in braces in `make4ht-indexing` library.
https://tex.stackexchange.com/q/714247/2891

- 2024/02/22

- version `0.4` released
Expand Down
4 changes: 3 additions & 1 deletion make4ht-indexing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ local fix_idx_pages = function(content, idxobj)
-- there is a problem when index term itself contains numbers, like Bible verses (1:2),
-- because they will be detected as page numbers too. I cannot find a good solution
-- that wouldn't break something else.
return start .. rest:gsub("(%d+)", function(page)
-- There can be also commands with numbers in braces. These numbers in braces will be ignored,
-- as they may be not page numbers
return start .. rest:gsub("(%{?%d+%}?)", function(page)
local entry = entries[tonumber(page)]
if entry then
-- construct link to the index entry
Expand Down
33 changes: 33 additions & 0 deletions make4ht-odtfilter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
local mkutils = require "mkutils"
local zip = require "zip"


-- use function to change contents of the ODT file
local function update_odt(odtfilename, file_path, fn)
-- get name of the odt file
local odtname = mkutils.remove_extension(odtfilename) .. ".odt"
-- open and read contents of the requested file inside ODT file
local odtfile = zip.open(odtname)
local local_file = odtfile:open(file_path)
local content = local_file:read("*all")
local_file:close()
odtfile:close()
-- update the content using user function
content = fn(content)
-- write the updated file
local local_file_file = io.open(file_path,"w")
local_file_file:write(content)
local_file_file:close()
os.execute("zip " .. odtname .. " " .. file_path)
os.remove(file_path)
end

Make:match("tmp$", function(name, par)
update_odt(name, "content.xml", function(content)
return content:gsub("%&%#x([A-Fa-f0-9]+);", function(entity)
-- convert hexadecimal entity to Unicode
print(entity,utfchar(tonumber(entity, 16)))
return utfchar(tonumber(entity, 16))
end)
end)
end)

0 comments on commit 3f1bc8d

Please # to comment.