Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
# Pandoc filter to convert inline HTML comments to LaTeX todos
# Requires panflute (if you don't have it, do "pip install panflute")
# Also requires the todonotes LaTeX package, see https://www.ctan.org/pkg/todonotes
# When prerequisites are installed, use pandoc option "--filter ./pandoc_comments_to_todo.py"
# (adjusting the filter directory if necessary)
import panflute as pf
import re
def action(e, doc):
if (isinstance(e, pf.RawBlock) or isinstance(e, pf.RawInline)) and (doc.format == 'latex'):
match = re.search("<!-- ([^-]+) -->", e.text)
if match:
if len(match.group(1)) > 20:
e.format = 'latex'
e.text = '\\todo[inline]{' + match.group(1) + '}'
else:
e.format = 'latex'
e.text = '\\todo{' + match.group(1) + '}'
def main():
pf.toJSONFilter(action=action)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.