Skip to content

Commit bdac9e1

Browse files
committed
WIP
1 parent 270cf1c commit bdac9e1

File tree

1 file changed

+42
-20
lines changed

1 file changed

+42
-20
lines changed

docs/soar_manual/index_filter.lua

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,51 @@
1-
-- Simple filter to convert HTML comments with \index commands to LaTeX
1+
-- Comprehensive filter to catch HTML comments with index commands
22

3-
function processBlock(block)
4-
if block.tag == "RawBlock" and block.format == "html" then
5-
local text = block.text
6-
-- Check if this is an HTML comment with \index
7-
local index_match = text:match("^<!%-%-%s*\\index{(.-)}.-->$")
8-
if index_match then
9-
return pandoc.RawBlock("latex", "\\index{" .. index_match .. "}")
10-
end
3+
function processAny(elem)
4+
-- Handle any element that might contain our HTML comments
5+
local text = ""
6+
7+
if elem.tag == "RawBlock" or elem.tag == "RawInline" then
8+
text = elem.text or ""
9+
elseif elem.tag == "Str" then
10+
text = elem.text or ""
11+
elseif elem.tag == "Para" then
12+
text = pandoc.utils.stringify(elem)
1113
end
12-
return block
13-
end
1414

15-
function processInline(inline)
16-
if inline.tag == "RawInline" and inline.format == "html" then
17-
local text = inline.text
18-
-- Check if this is an HTML comment with \index
19-
local index_match = text:match("^<!%-%-%s*\\index{(.-)}.-->$")
20-
if index_match then
21-
return pandoc.RawInline("latex", "\\index{" .. index_match .. "}")
15+
-- Look for HTML comments with index commands anywhere in the text
16+
if text and text:match("<!%-%-%s*\\index{.-}%s*-->") then
17+
-- Found an index comment - extract all index commands
18+
local index_commands = {}
19+
for index_cmd in text:gmatch("<!%-%-%s*(\\index{.-})%s*-->") do
20+
table.insert(index_commands, pandoc.RawInline("latex", index_cmd))
21+
end
22+
23+
-- If we found any, return them
24+
if #index_commands > 0 then
25+
if #index_commands == 1 then
26+
return index_commands[1]
27+
else
28+
return index_commands
29+
end
2230
end
2331
end
24-
return inline
32+
33+
return elem
34+
end
35+
36+
-- Also try a document-level approach to insert some test index entries
37+
function processDocument(doc)
38+
-- Add a test index entry at the very beginning
39+
table.insert(doc.blocks, 1, pandoc.RawBlock("latex", "\\index{test-entry}"))
40+
return doc
2541
end
2642

2743
return {
28-
{ RawBlock = processBlock, RawInline = processInline }
44+
{
45+
RawBlock = processAny,
46+
RawInline = processAny,
47+
Str = processAny,
48+
Para = processAny,
49+
Pandoc = processDocument
50+
}
2951
}

0 commit comments

Comments
 (0)