Created
January 13, 2020 12:43
-
-
Save tarleb/4949e41ae7ad9f17c38a1fcce02960d3 to your computer and use it in GitHub Desktop.
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
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