Created
January 31, 2023 14:23
-
-
Save githubyouser/baae453f5843ee2ad0727a231b352012 to your computer and use it in GitHub Desktop.
Modify a MD file from Word to add headings.
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
import sys | |
import re | |
with open(sys.argv[1], "r", encoding="utf-8") as input: | |
with open(sys.argv[2], "x", encoding="utf-8") as output: | |
for line in input: | |
clean = (line) | |
clean = re.sub('## \*\*(Lesson [0-9]+)\*\*(\n)', '# \\1\\2', clean) # Convert Lesson #s to H1s | |
clean = re.sub('\*\*\[(.*?)\]\{\.underline\}\*\*(\n)', '### \\1\\2', clean) # Convert underlined Word H1s to md H3s | |
clean = re.sub('\*\*\*(.*?)\*\*\*(\n)', '##### \\1\\2', clean) # Convert bold and italic headers to H5s | |
clean = re.sub("(## )\*\*(.*?)\*\*(\n)", '\\1\\2\\3', clean) # Remove bold from H2s | |
clean = re.sub('\*\*(.*?)\*\*(\n)', '#### \\1\\2', clean) # Convert bold headers to H3s | |
output.write(clean) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment