Added prompt for the folder path

This commit is contained in:
Steve Dogiakos 2022-12-09 17:08:32 -07:00
parent a1261b1827
commit ffd0682a00
1 changed files with 10 additions and 4 deletions

View File

@ -1,6 +1,7 @@
import os import os
import re import re
def convert_md_to_paprika3(file_path): def convert_md_to_paprika3(file_path):
# read the contents of the file # read the contents of the file
with open(file_path, "r") as f: with open(file_path, "r") as f:
@ -8,15 +9,20 @@ def convert_md_to_paprika3(file_path):
# perform formatting operations on the text # perform formatting operations on the text
formatted_contents = re.sub(r"# (.*)", r"<h1>\1</h1>", contents) formatted_contents = re.sub(r"# (.*)", r"<h1>\1</h1>", contents)
formatted_contents = re.sub(r"## (.*)", r"<h2>\1</h2>", formatted_contents) formatted_contents = re.sub(r"## (.*)", r"<h2>\1</h2>", formatted_contents)
formatted_contents = re.sub(r"### (.*)", r"<h3>\1</h3>", formatted_contents) formatted_contents = re.sub(
formatted_contents = re.sub(r"\*\*(.*)\*\*", r"<strong>\1</strong>", formatted_contents) r"### (.*)", r"<h3>\1</h3>", formatted_contents)
formatted_contents = re.sub(
r"\*\*(.*)\*\*", r"<strong>\1</strong>", formatted_contents)
formatted_contents = re.sub(r"_(.*)_", r"<em>\1</em>", formatted_contents) formatted_contents = re.sub(r"_(.*)_", r"<em>\1</em>", formatted_contents)
# write the formatted text to a new file # write the formatted text to a new file
with open(file_path[:-3] + ".paprika3", "w") as f: with open(file_path[:-3] + ".paprika3", "w") as f:
f.write(formatted_contents) f.write(formatted_contents)
# prompt the user for the folder path
folder_path = input("Enter the path to the folder: ")
# get a list of all the files in the folder # get a list of all the files in the folder
folder_path = "/path/to/folder"
files = os.listdir(folder_path) files = os.listdir(folder_path)
# convert each file to Paprika3 format # convert each file to Paprika3 format
for file in files: for file in files: