Created
March 10, 2019 19:10
-
-
Save minkkinen/0d58e4cd0acc6b05fd8fb36f55e4dd4e 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
| #!/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