-- keep-citations.lua -- Replace citations with a placeholder and eat any preceding space. local PH = "[citation]" -- Pandoc-native citations (if the reader produced Cite nodes) function Cite(el) return pandoc.Str(PH) end -- Raw LaTeX \cite-like macros (when not parsed as Cite) function RawInline(el) if el.format and el.format:match("tex") and el.text:match("\\%a-*cite%*?") then return pandoc.Str(PH) end end -- Remove a single leading Space before our placeholder local function squash_spaces(inlines) local out = {} local i = 1 while i <= #inlines do local cur = inlines[i] local nxt = inlines[i + 1] if cur and cur.t == "Space" and nxt and nxt.t == "Str" and nxt.text == PH then table.insert(out, nxt) i = i + 2 else table.insert(out, cur) i = i + 1 end end return out end function Para(el) el.content = squash_spaces(el.content) return el end function Plain(el) el.content = squash_spaces(el.content) return el end