-
Notifications
You must be signed in to change notification settings - Fork 1
/
page.py
50 lines (43 loc) · 1.52 KB
/
page.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import markdown
# Directory containing Markdown files
md_dir = 'C:/Users/akrat/Downloads/HerDeadVoiceWs'
# Directory to save the HTML files
html_dir = 'C:/Users/akrat/Downloads/HerDeadVoiceWs'
# Ensure the html directory exists
os.makedirs(html_dir, exist_ok=True)
# Function to convert Markdown to HTML
def convert_md_to_html(md_content):
html_content = markdown.markdown(md_content, extensions=['nl2br'])
return f"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Poem</title>
<link rel="stylesheet" href="./page.css">
<link rel="stylesheet" href="../herdeadvoice/assets/css/style2.css">
</head>
<body>
<div class="background"></div>
<div class="woolf"></div>
<div class="content-container">
<div class="content">
{html_content}
</div>
</div>
</body>
</html>
"""
# Iterate through Markdown files and convert them
for filename in os.listdir(md_dir):
if filename.endswith('.md'):
with open(os.path.join(md_dir, filename), 'r', encoding='utf-8') as f:
md_content = f.read()
html_content = convert_md_to_html(md_content)
# Save the HTML content to a new file
html_filename = os.path.splitext(filename)[0] + '.html'
with open(os.path.join(html_dir, html_filename), 'w', encoding='utf-8') as f:
f.write(html_content)
print("Conversion complete!")