""" Markdown -> styled HTML export. Produces a clean, self-contained HTML document (inline CSS, no external assets) from the Markdown a brief/artifact is written in. Used for the app's HTML download and as the body of the result email. No AI-provider dependencies. """ from __future__ import annotations import html as _html _CSS = """ :root { --ink:#1A2A4F; --muted:#4B5563; --line:#D1D5DB; --accent:#FF6B35; } * { box-sizing: border-box; } body { font-family: -apple-system, "Segoe UI", Inter, Helvetica, Arial, sans-serif; color:#111827; max-width: 820px; margin: 32px auto; padding: 0 20px; line-height: 1.55; } h1 { color: var(--ink); font-size: 1.9rem; border-bottom: 2px solid var(--ink); padding-bottom: .3em; margin-top: 1.2em; } h2 { color: var(--ink); font-size: 1.3rem; margin-top: 1.4em; } h3 { color: var(--muted); font-size: 1.08rem; margin-top: 1.1em; } p, li { font-size: 0.98rem; } ul, ol { padding-left: 1.3em; } code { background:#F3F4F6; padding: .1em .35em; border-radius: 4px; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .9em; } pre { background:#F3F4F6; padding: 12px 14px; border-radius: 8px; overflow:auto; } pre code { background: none; padding: 0; } blockquote { border-left: 3px solid var(--line); margin: 1em 0; padding: .2em 1em; color: var(--muted); } table { border-collapse: collapse; width: 100%; margin: 1em 0; } th, td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; font-size: .92rem; vertical-align: top; } th { background: var(--ink); color: #fff; } tr:nth-child(even) td { background: #F8FAFC; } hr { border: none; border-top: 1px solid var(--line); margin: 1.5em 0; } .footer { color:#9CA3AF; font-size:.8rem; margin-top:2.5em; border-top:1px solid var(--line); padding-top:1em; } """ def markdown_to_html(markdown_text: str, title: str = "Creative Brief") -> str: """Render Markdown to a full, styled, self-contained HTML document string.""" try: import markdown2 # lazy body = markdown2.markdown( markdown_text, extras=["tables", "fenced-code-blocks", "cuddled-lists", "break-on-newline"], ) except Exception: # Minimal fallback if markdown2 isn't available: escape + keep line breaks. body = "
" + _html.escape(markdown_text) + "" safe_title = _html.escape(title) return f"""