Skip to content

Instantly share code, notes, and snippets.

@tarleb
Created January 13, 2020 12:43
Show Gist options
  • Save tarleb/4949e41ae7ad9f17c38a1fcce02960d3 to your computer and use it in GitHub Desktop.
Save tarleb/4949e41ae7ad9f17c38a1fcce02960d3 to your computer and use it in GitHub Desktop.
function Inlines (inlns)
-- switch period/cite elements
for i=1,#inlns-1 do
local period, cite = inlns[i], inlns[i+1]
if period.t == 'Str' and period.text == '.' and cite.t == 'Cite' then
inlns[i], inlns[i+1] = cite, period
end
end
return inlns
end
function filter_inlines(element, field)
local new_inlines = Inlines(element[field])
if new_inlines then element[field] = new_inlines end
return element
end
function Inline (inln)
-- abort if element has no direct inline content
if inln.t == 'Note' then return end
if not inln.content and not inln.caption then return end
local inlines_field = inln.t == 'Image' and 'caption' or 'content'
return filter_inlines(inln, inlines_field)
end
function Table (tbl) return filter_inlines(tbl, 'caption') end
function Header (h) return filter_inlines(h, 'content') end
function Para (p) return filter_inlines(p, 'content') end
function Plain (p) return filter_inlines(p, 'content') end
function LineBlock (lb)
for i=1,#lb.content do
filter_inlines(lb.content, i)
end
return lb
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment