Last active
December 29, 2020 06:59
-
-
Save wcaleb/17ca606788f9b4b9a36b to your computer and use it in GitHub Desktop.
Pandoc filter to convert all notes to inline notes in Pandoc Markdown output
This file contains 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
#!/usr/bin/env python | |
from pandocfilters import toJSONFilter, RawInline, Space, Str, walk | |
""" | |
Pandoc filter for Markdown that converts most endnotes into | |
Pandoc's inline notes. If input notes had multiple paragraphs, | |
the paragraphs are joined by a space. But if an input note | |
had any blocks other than paragraphs, the note is left as is. | |
""" | |
def query(k, v, f, meta): | |
global inlines | |
if k == 'BlockQuote': | |
inlines.append(v) | |
elif isinstance(v, list): | |
if inlines and k == 'Para': | |
inlines.append(Space()) | |
inlines.extend(v) | |
return v | |
def inlinenotes(k, v, f, meta): | |
global inlines | |
inlines = [] | |
if k == 'Note' and f == 'markdown': | |
walk(v, query, f, meta) | |
if all(isinstance(x, dict) for x in inlines): | |
return [RawInline('html', '^[')] + inlines + [Str(']')] | |
if __name__ == "__main__": | |
toJSONFilter(inlinenotes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Caleb! I wonder what's the status of this filter. Is it still supported? How would you deploy it? I tried with this but it didn't work:
pandoc -t markdown --filter inlinenotes.py input.md