Skip to content

Instantly share code, notes, and snippets.

@oliverhu
Created January 16, 2022 08:12
Show Gist options
  • Save oliverhu/a4eb76b7bbe7d72bc2f98edb8984e0c9 to your computer and use it in GitHub Desktop.
Save oliverhu/a4eb76b7bbe7d72bc2f98edb8984e0c9 to your computer and use it in GitHub Desktop.
import urllib.parse
import re
import os
for root, dirs, files in os.walk("./"):
for file in files:
if file.endswith(".md"):
# f_base_name = urllib.parse.quote(os.path.basename(f_name))
# print(f_base_name)
f_path = os.path.join(root, file)
p = re.compile(r"(.*)<a href.*>(.*.PDF)</a>(.*)", re.IGNORECASE)
f = open(f_path, 'r+')
file_contents = f.read()
file_contents = p.sub(f'![[\g<2>]]', file_contents)
f.seek(0)
f.truncate()
f.write(file_contents)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment