Created
August 26, 2020 00:19
-
-
Save jegfish/8b8bcead6e1fb64657c976394eaa7b4a 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
# pandoc document JSON structure documentation: https://hackage.haskell.org/package/pandoc-types-1.21/docs/Text-Pandoc-Definition.html#t:Inline | |
# pandocfilters: https://github.com/jgm/pandocfilters | |
# | |
# pandocfilters.Link takes 3 arguments | |
# I'm not sure why, | |
# but the pandoc documentation for the JSON structure says "Link" also takes 3 arguments, | |
# which are "Attr [Inline] Target". | |
# I think that may be a coincidence. | |
# | |
# The second argument, 'value', passed to my function, | |
# is a list with 3 elements. | |
# These 3 elements appear to match up with the 3 arguments from the pandoc JSON documentation. | |
# The third one contains the URL of the item, | |
# and when I modify that I can change the URL in the output document. | |
from pandocfilters import toJSONFilter, Link | |
def md_link_to_html(key, value, format, meta): | |
if key == "Link": | |
url = value[2][0] | |
url = url[:-3] + ".html" | |
value[2][0] = url | |
Link(value, format, meta) | |
if __name__ == "__main__": | |
toJSONFilter(md_link_to_html) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment