|
2 | 2 | -- This allows index entries to be hidden from MkDocs while being processed for PDF output
|
3 | 3 |
|
4 | 4 | function extractIndexFromComments(elem)
|
5 |
| - -- Handle RawInline and RawBlock elements with HTML format |
6 |
| - if (elem.tag == "RawInline" or elem.tag == "RawBlock") and elem.format == "html" then |
7 |
| - local comment = elem.text |
| 5 | + -- Handle RawInline and RawBlock elements with any format |
| 6 | + if elem.tag == "RawInline" or elem.tag == "RawBlock" then |
| 7 | + local text = elem.text or "" |
8 | 8 | -- Match HTML comments containing \index commands
|
9 |
| - local index_cmd = comment:match("<!%-%-%s*\\index{(.-)}.-->") |
| 9 | + local index_cmd = text:match("<!%-%-%s*\\index{(.-)}.-->") |
10 | 10 | if index_cmd then
|
11 | 11 | return pandoc.RawInline("latex", "\\index{" .. index_cmd .. "}")
|
12 | 12 | end
|
13 | 13 | -- Match full \index{...} commands in comments (allowing spaces)
|
14 |
| - local full_index = comment:match("<!%-%-%s*(%\\index{.-})%s*-->") |
| 14 | + local full_index = text:match("<!%-%-%s*(%\\index{.-})%s*-->") |
15 | 15 | if full_index then
|
16 | 16 | return pandoc.RawInline("latex", full_index)
|
17 | 17 | end
|
|
21 | 21 |
|
22 | 22 | -- Also try to catch HTML comments that might be processed as plain text
|
23 | 23 | function extractFromPlainText(elem)
|
24 |
| - if elem.tag == "Str" or elem.tag == "Para" then |
25 |
| - local text = elem.text or pandoc.utils.stringify(elem) |
26 |
| - if text and text:match("<!%-%-%s*\\index{.-}%s*-->") then |
27 |
| - -- Replace HTML comments with LaTeX index commands |
28 |
| - local new_text = text:gsub("<!%-%-%s*(\\index{.-})%s*-->", "%1") |
29 |
| - if new_text ~= text then |
30 |
| - return pandoc.RawInline("latex", new_text) |
31 |
| - end |
| 24 | + local text = "" |
| 25 | + if elem.tag == "Str" then |
| 26 | + text = elem.text or "" |
| 27 | + elseif elem.tag == "Para" then |
| 28 | + text = pandoc.utils.stringify(elem) |
| 29 | + end |
| 30 | + |
| 31 | + if text and text:match("<!%-%-%s*\\index{.-}%s*-->") then |
| 32 | + -- Replace HTML comments with LaTeX index commands |
| 33 | + local new_text = text:gsub("<!%-%-%s*(\\index{.-})%s*-->", "%1") |
| 34 | + if new_text ~= text then |
| 35 | + return pandoc.RawInline("latex", new_text) |
32 | 36 | end
|
33 | 37 | end
|
34 | 38 | return elem
|
|
0 commit comments