Created
December 27, 2022 08:05
-
-
Save snosrap/cff663ac77b08e0970c204ebb2308e67 to your computer and use it in GitHub Desktop.
python pandoc filter to add a base href/url to each image src
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 python3 | |
from urllib.parse import urljoin | |
from pandocfilters import toJSONFilter, Image | |
BASEURL = "https://example.com" | |
def basehref(key, value, format, meta): | |
if key == "Image": | |
[[id, classes, attrs], children, [src, title]] = value | |
src = urljoin(BASEURL, src) | |
return Image([id, classes, attrs], children, [src, title]) | |
if __name__ == "__main__": | |
toJSONFilter(basehref) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment