Created
October 27, 2018 23:22
-
-
Save RLesur/e81358c11031d06e40b8fef9fdfb2682 to your computer and use it in GitHub Desktop.
A pandoc lua filter that sorts definition lists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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