|
1 |
| --- Comprehensive filter to catch HTML comments with index commands |
| 1 | +-- Simple test filter to add index entries |
2 | 2 |
|
3 |
| -function processAny(elem) |
4 |
| - -- Handle any element that might contain our HTML comments |
5 |
| - local text = "" |
| 3 | +function processDoc(doc) |
| 4 | + -- Insert multiple test index entries at the beginning |
| 5 | + table.insert(doc.blocks, 1, pandoc.RawBlock("latex", "\\index{chunking}")) |
| 6 | + table.insert(doc.blocks, 2, pandoc.RawBlock("latex", "\\index{test-entry}")) |
| 7 | + table.insert(doc.blocks, 3, pandoc.RawBlock("latex", "\\index{Soar}")) |
6 | 8 |
|
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) |
13 |
| - end |
| 9 | + -- Also add some debug output |
| 10 | + io.stderr:write("Index filter: Added test index entries\n") |
14 | 11 |
|
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 |
30 |
| - end |
31 |
| - end |
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 | 12 | return doc
|
41 | 13 | end
|
42 | 14 |
|
43 | 15 | return {
|
44 | 16 | {
|
45 |
| - RawBlock = processAny, |
46 |
| - RawInline = processAny, |
47 |
| - Str = processAny, |
48 |
| - Para = processAny, |
49 |
| - Pandoc = processDocument |
| 17 | + Pandoc = processDoc |
50 | 18 | }
|
51 | 19 | }
|
0 commit comments