|
1 |
| --- Simple Pandoc Lua filter to add index entries |
2 |
| --- For now, let's just add some basic index entries manually |
| 1 | +-- Simple filter to convert HTML comments with \index commands to LaTeX |
3 | 2 |
|
4 |
| -function addIndexEntries(meta) |
5 |
| - -- This function runs once per document |
6 |
| - return meta |
| 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 |
| 11 | + end |
| 12 | + return block |
7 | 13 | end
|
8 | 14 |
|
9 |
| -function processDocument(doc) |
10 |
| - -- Add some basic index entries at the beginning of the document |
11 |
| - local index_entries = { |
12 |
| - pandoc.RawBlock("latex", "\\index{chunking}"), |
13 |
| - pandoc.RawBlock("latex", "\\index{chunk}"), |
14 |
| - pandoc.RawBlock("latex", "\\index{result}"), |
15 |
| - pandoc.RawBlock("latex", "\\index{subgoal}"), |
16 |
| - pandoc.RawBlock("latex", "\\index{instantiation}"), |
17 |
| - pandoc.RawBlock("latex", "\\index{chunking!backtracing}"), |
18 |
| - pandoc.RawBlock("latex", "\\index{singleton}"), |
19 |
| - pandoc.RawBlock("latex", "\\index{chunking!explanation-based behavior summarization}") |
20 |
| - } |
21 |
| - |
22 |
| - -- Insert index entries at the beginning |
23 |
| - for i = #index_entries, 1, -1 do |
24 |
| - table.insert(doc.blocks, 1, index_entries[i]) |
| 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 .. "}") |
| 22 | + end |
25 | 23 | end
|
26 |
| - |
27 |
| - return doc |
| 24 | + return inline |
28 | 25 | end
|
29 | 26 |
|
30 | 27 | return {
|
31 |
| - { |
32 |
| - Meta = addIndexEntries, |
33 |
| - Pandoc = processDocument |
34 |
| - } |
| 28 | + { RawBlock = processBlock, RawInline = processInline } |
35 | 29 | }
|
0 commit comments