#!/usr/bin/env python3 """Build a styled HTML file from chapter markdown drafts for email/review.""" import argparse import re import sys from pathlib import Path import markdown CHAPTER_DIR = Path(__file__).parent / "chapters" / "book1" OUTPUT_DIR = Path(__file__).parent / "exports" HTML_TEMPLATE = """\
* * *
", '* * *
') return html def extract_title(text: str) -> str: """Extract the chapter title from the first # heading in the markdown.""" match = re.match(r"^#\s+(.+)$", text.strip(), re.MULTILINE) return match.group(1) if match else None def add_heading_id(html: str, anchor_id: str) -> str: """Add an id attribute to the first