I have a markdown file and I want to PDF with a last section with alphabetical index such as latex alphabetical index.
But I have been looking in the pandoc manual and looking for a Lua plugin for this thing, but I have not seen anything.
I have a markdown file and I want to PDF with a last section with alphabetical index such as latex alphabetical index.
But I have been looking in the pandoc manual and looking for a Lua plugin for this thing, but I have not seen anything.
You could use a filter. Assuming that you enclose your indexed words with a span id="index"
and that you have a div id='compiled_index
where you want the index to show, the following should do what you want.
function buildMap(dic, idx)
table.sort(idx)
for i,v in ipairs(idx) do
local key = string.upper(string.sub(v, 1, 1))
if(dic[key] == nil) then
dic[key] = {pandoc.Para(pandoc.Link(v,"#"..v))}
else
table.insert(dic[key],pandoc.Para(pandoc.Link(v,"#"..v)))
end
end
return dic
end
function Span(el)
if el.identifier == 'index' then
local index = pandoc.utils.stringify(el.content)
table.insert(idx,index)
out = pandoc.Link(index,"")
out.identifier=index
return out
end
end
function Div(el)
if el.identifier == 'compiled_index' then
local list = buildMap(dic,idx)
local lists = {}
for key, items in pairs(list) do
local inner_list = {}
for _,item in pairs(items) do
table.insert(inner_list,item)
end
table.insert(lists,pandoc.DefinitionList{{key, inner_list}})
end
return lists
end
end
You can then run pandoc -L <filterName>.lua -t html <inputFile>.md -o <outputFile>.html