Skip to content

Instantly share code, notes, and snippets.

@TimoReusch
Last active March 12, 2023 23:39
Show Gist options
  • Save TimoReusch/0b97fe4c6083d99a02bbf35654f3e526 to your computer and use it in GitHub Desktop.
Save TimoReusch/0b97fe4c6083d99a02bbf35654f3e526 to your computer and use it in GitHub Desktop.
Replaces <img> HTML-Tags with the MkDocs Markdown Syntax
file = open("Skript.md", "r")
newfile = open("new.md", "a")
lines = file.readlines()
replacements = [
["<img", "<figure markdown>\n ![](", "</figure>"],
["> <img", "> <figure markdown>\n> ![](", "> </figure>"],
[" <img", " <figure markdown>\n ![](", " </figure>"]
]
for line in lines:
was_replaced = False
for r in replacements:
if (line.startswith(r[0])):
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