Last active
January 7, 2020 20:37
-
-
Save kljensen/b4d4580b678d44d2d85e07fc1e450c1c to your computer and use it in GitHub Desktop.
A Pandoc Lua filter that removes Spaces before Cite elements
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
local function remove_citation_space(para) | |
local table elements = {} | |
i = 0 | |
local function logel(el) | |
i = i + 1 | |
elements[i] = el.t | |
end | |
pandoc.walk_block(para, {Inline = logel}) | |
-- See which Space elements should be deleted. It | |
-- is those that follow a Cite element. | |
local table todelete = {} | |
local post_cite = false | |
for i = #elements, 1, -1 do | |
el = elements[i] | |
if el == "Space" or el == "SoftBreak" then | |
if post_cite then | |
todelete[i] = true | |
end | |
elseif el == "Cite" then | |
post_cite = true | |
else | |
post_cite = false | |
end | |
end | |
j = 0 | |
local function delete(el) | |
j = j + 1 | |
if todelete[j] == true then | |
return {} | |
end | |
end | |
return pandoc.walk_block(para, {Inline = delete}) | |
end | |
return { | |
{Para = remove_citation_space} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment