Created
March 21, 2021 21:31
-
-
Save TkTech/29d8fd346c941c981752595b202ac75d to your computer and use it in GitHub Desktop.
Rewrite links in Markdown
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
from humanmark import loads, dumps, ast | |
doc = loads('[a](../b.c)') | |
links = doc.find( | |
# Only find link nodes | |
ast.Link, | |
# We don't want to rewrite links that use a reference | |
f=lambda link: link.reference is None, | |
# A negative value means to search the entire tree. | |
depth=-1 | |
) | |
for link in links: | |
# Just an example, you probably want to properly parse the URLs. | |
link.url = link.url.replace('..', 'https://hosted.com') | |
print(dumps(doc)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For https://stackoverflow.com/questions/66660430/is-there-any-python-library-that-allows-markdown-ast-transformation