Skip to content

Instantly share code, notes, and snippets.

@RLesur
Created October 27, 2018 23:22
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RLesur/e81358c11031d06e40b8fef9fdfb2682 to your computer and use it in GitHub Desktop.
Save RLesur/e81358c11031d06e40b8fef9fdfb2682 to your computer and use it in GitHub Desktop.
A pandoc lua filter that sorts definition lists
DefinitionList = function(dl)
local terms = {}
local inlines = {}
local blocks = {}
local sorted = {}
for i, item in ipairs(dl.content) do
local term = string.upper(pandoc.utils.stringify(item[1])) --string.upper() is used because all the terms were not capitalized in the example
table.insert(terms, term)
inlines[term] = item[1]
blocks[term] = item[2]
end
table.sort(terms)
for i, term in ipairs(terms) do
table.insert(sorted, {inlines[term], blocks[term]})
end
return pandoc.DefinitionList(sorted)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment