I am finally getting back to try writing such a filter. I am opting to use the python pandocfilters package to intercept this with toJSONFilter. But I don't seem to be getting it.
I think I have it close but don't know how to handle the lines in the metadata include-after before the start of the reference header.
from pandocfilters import toJSONFilter, RawBlock, Header
import sys
def latex(x):
return RawBlock('latex', x)
def references_includeafter(key, value, format, meta):
if key == 'Header':
[level, [ident, _, _], content] = value
if ident == "references":
if format == "latex":
# insert include-after lines before start of reference header
includeafter = meta.get('include-after', {})
print >> sys.stderr, str(includeafter)
return includeafter
if __name__ == "__main__":
toJSONFilter(references_includeafter)