Last active
March 12, 2023 23:39
-
-
Save TimoReusch/0b97fe4c6083d99a02bbf35654f3e526 to your computer and use it in GitHub Desktop.
Replaces <img> HTML-Tags with the MkDocs Markdown Syntax
This file contains 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
file = open("Skript.md", "r") | |
newfile = open("new.md", "a") | |
lines = file.readlines() | |
replacements = [ | |
["<img", "<figure markdown>\n ): | |
was_replaced = True | |
start_index = 0 | |
end_index = 0 | |
for i in range(0, len(line)): | |
if line[i] == "=" and line[i+1] == '"': | |
start_index = i+2 | |
if line[i] == '"' and line[i+1] == ' ': | |
end_index = i | |
break | |
image_name = line[start_index:end_index] | |
image_name = image_name.replace("Bilder", "assets") | |
newfile.write(r[1] + | |
image_name + "){ width=400 }\n" + r[2]) | |
if (not was_replaced): | |
newfile.write(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment