-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmd_to_html.py
More file actions
executable file
·52 lines (39 loc) · 1.58 KB
/
md_to_html.py
File metadata and controls
executable file
·52 lines (39 loc) · 1.58 KB
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
51
52
#!/usr/bin/env python3
"""
Convert Markdown files to HTML in the Incoming/ directory.
Applies the same processing as podcasts: conversion + margins.
"""
from pathlib import Path
import config as cfg
import utils as U
def convert_md_to_html():
"""Convert all .md files in Incoming/ to HTML."""
incoming_dir = Path(cfg.INCOMING)
md_files = list(incoming_dir.glob("*.md"))
if not md_files:
print("📝 No .md files found to convert")
return
print(f"📝 Converting {len(md_files)} Markdown file(s) to HTML...")
for md_file in md_files:
html_path = md_file.with_suffix(".html")
# Skip if the HTML already exists.
if html_path.exists():
print(f"⏭️ Skipping {md_file.name} (HTML already exists)")
continue
try:
# Read Markdown content.
md_text = md_file.read_text(encoding="utf-8", errors="replace")
# Convert to HTML using the centralized function.
full_html = U.markdown_to_html(md_text, title=md_file.stem)
# Save HTML.
html_path.write_text(full_html, encoding="utf-8")
print(f"✅ HTML generated: {html_path.name}")
except Exception as e:
print(f"❌ Error converting {md_file.name}: {e}")
import traceback
traceback.print_exc()
# Apply margins to all generated HTML.
print("📏 Applying margins...")
U.add_margins_to_html_files(incoming_dir)
if __name__ == "__main__":
convert_md_to_html()