Skip to content

Commit 1607f9d

Browse files
authored
Refactor _build_html function and update imports
1 parent 42047ac commit 1607f9d

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

scripts/export_course.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@
2727

2828
from src import config # noqa: E402
2929
from src.database import Database # noqa: E402
30-
from src.emailer import _EMAIL_CSS, _md_to_html # noqa: E402
30+
from src.emailer import _EMAIL_CSS, _PYGMENTS_CSS, _md_to_html # noqa: E402
3131

3232

33-
def _build_html(
34-
course_title: str, teacher: str, lectures: list[dict], pdf_mode: bool = False
35-
) -> str:
33+
def _build_html(course_title: str, teacher: str, lectures: list[dict]) -> str:
3634
"""Build a complete styled HTML document from course summaries."""
3735
body_parts = [
3836
f"<h1>{escape(course_title)}</h1>",
@@ -44,13 +42,13 @@ def _build_html(
4442
f"<h2>{escape(lec['sub_title'])} "
4543
f"<small>({escape(lec['date'])})</small></h2>"
4644
)
47-
body_parts.append(_md_to_html(lec["summary"], pdf_mode=pdf_mode))
45+
body_parts.append(_md_to_html(lec["summary"]))
4846
body_parts.append("<hr>")
4947

5048
return (
5149
"<!DOCTYPE html>"
5250
"<html><head><meta charset='utf-8'>"
53-
f"<style>{_EMAIL_CSS}</style>"
51+
f"<style>{_EMAIL_CSS}\n{_PYGMENTS_CSS}</style>"
5452
"</head><body>"
5553
+ "\n".join(body_parts)
5654
+ "</body></html>"
@@ -157,7 +155,7 @@ def main():
157155
print("Email configuration incomplete. Set SMTP_EMAIL, SMTP_PASSWORD, RECEIVER_EMAIL.")
158156
sys.exit(1)
159157

160-
html = _build_html(course_title, teacher, lectures, pdf_mode=args.pdf)
158+
html = _build_html(course_title, teacher, lectures)
161159
subject = f"[iCourse 课程摘要导出] {course_title}"
162160

163161
if args.pdf:

0 commit comments

Comments
 (0)