#!/usr/bin/env python3 """경쟁 병원 영문 AEO/GEO 비교 진단 보고서 → INFINITH 디자인 HTML + PDF. 디자인 토큰은 뷰성형외과 영문 진단 보고서(build_global_en_report.py)에서 그대로 가져온다. ink 0A1128 / navy 021341 / violet 4F1DA1 / accent 6C5CE7 / indigo 1D0024 본문, Pretendard + Playfair Display, keep-all 줄바꿈. 사용: python3 build_report.py [--no-pdf] """ import os, re, sys S = os.path.dirname(os.path.abspath(__file__)) MD = os.path.join(S, "경쟁병원_영문_AEO_GEO_비교진단_2026-09-18.md") OUT = os.path.join(S, "INFINITH_경쟁병원_영문_AEO_GEO_비교진단_2026-09-18") CSS = open(os.path.join(S, "_infinith_tokens.css"), encoding="utf-8").read() EXTRA = """ .page{max-width:1100px} .md h2{font-family:"Playfair Display",Georgia,serif;font-size:27px;margin:46px 0 14px;padding-top:18px;border-top:2px solid var(--ink);color:var(--indigo);display:block} .md h3{font-size:20px;margin:30px 0 10px;color:var(--navy);font-weight:700} .md h4{font-size:17px;margin:20px 0 8px;color:var(--navy);font-weight:700} .md p,.md li{font-size:16px;line-height:1.72} .md ul,.md ol{padding-left:22px;margin:0 0 16px} .md li{margin:0 0 7px} .md table{width:100%;border-collapse:collapse;font-size:15px;margin:14px 0 22px;page-break-inside:auto} .md table th{background:var(--ink);color:#fff;text-align:left;font-weight:700;padding:10px 12px;font-size:14.5px;vertical-align:bottom} .md table td{padding:9px 12px;border-bottom:1px solid var(--line);vertical-align:top} .md table tr{page-break-inside:avoid} .md table tbody tr:nth-child(even){background:#FAFBFF} .md blockquote{margin:16px 0;padding:14px 18px;background:var(--light);border-left:5px solid var(--violet);border-radius:0 6px 6px 0;font-size:15.5px;color:var(--slate6)} .md blockquote p{margin:0} .md code{font-family:Inter,Menlo,monospace;font-size:13.5px;background:var(--light);border:1px solid var(--line);border-radius:4px;padding:1px 5px;color:var(--violet)} .md strong{font-weight:700;color:var(--indigo)} .md hr{border:0;border-top:1px solid var(--line);margin:34px 0} .tag{display:inline-block;font-family:Inter,Pretendard,sans-serif;font-size:14px;font-weight:800;border-radius:6px;padding:1px 9px;line-height:1.55} .notice{background:var(--crit-bg);border:1px solid var(--crit-bd);border-left:5px solid var(--crit-tx);border-radius:0 8px 8px 0;padding:16px 20px;margin:20px 0;font-size:15.5px;color:var(--crit-tx)} .notice strong{color:var(--crit-tx)} @page{size:A4;margin:14mm 12mm} @media print{.cover{margin-top:0}.md h2{page-break-after:avoid}} """ INLINE = [ (r"`([^`]+)`", r"\1"), (r"\*\*([^*]+)\*\*", r"\1"), ] def inline(t): t = (t.replace("&", "&").replace("<", "<").replace(">", ">")) for pat, rep in INLINE: t = re.sub(pat, rep, t) return t def grade_tag(cell): """67 / B, 34 / D, 우위/열위 같은 값에 색 배지를 입힌다.""" c = cell.strip() m = re.match(r"^(\*\*)?(\d{1,3})\s*/\s*([ABCDF])(\*\*)?$", c) if m: n, g = int(m.group(2)), m.group(3) cls = "good" if g in "AB" and n >= 60 else ("warn" if g == "C" else "crit") return f'{n} / {g}' if c in ("우위",): return '우위' if c in ("열위",): return '열위' if c in ("잠재 우위", "동등"): return '' + c + "" return None def md_to_html(md): out, i, lines = [], 0, md.split("\n") while i < len(lines): ln = lines[i].strip() if lines[i].lstrip().startswith("|") else lines[i] if ln.startswith("|") and i + 1 < len(lines) and re.match(r"^\|[\s:\-|]+\|$", lines[i + 1].strip()): head = [c.strip() for c in ln.strip("|").split("|")] i += 2 rows = [] while i < len(lines) and lines[i].lstrip().startswith("|"): rows.append([c.strip() for c in lines[i].strip().strip("|").split("|")]) i += 1 t = ["" + "".join(f"" for h in head) + ""] for r in rows: cells = [] for c in r: g = grade_tag(c) cells.append(f"") t.append("" + "".join(cells) + "") t.append("
{inline(h)}
{g if g else inline(c)}
") out.append("".join(t)) continue if ln.startswith("> "): buf = [] while i < len(lines) and lines[i].startswith(">"): buf.append(lines[i].lstrip("> ").rstrip()) i += 1 body = "
".join(inline(b) for b in buf if b) cls = "notice" if "외부 자료" in body or "내부 검토용" in body else "blockquote-x" out.append(f'
{body}
' if cls == "notice" else f"

{body}

") continue m = re.match(r"^(#{2,4})\s+(.*)$", ln) if m: lvl = len(m.group(1)) out.append(f"{inline(m.group(2))}") i += 1 continue if re.match(r"^[-*]\s+", ln): items = [] while i < len(lines) and re.match(r"^[-*]\s+", lines[i]): items.append(f"
  • {inline(re.sub(r'^[-*]\s+', '', lines[i]))}
  • ") i += 1 out.append("") continue if re.match(r"^\d+\.\s+", ln): items = [] while i < len(lines) and re.match(r"^\d+\.\s+", lines[i]): items.append(f"
  • {inline(re.sub(r'^\d+\.\s+', '', lines[i]))}
  • ") i += 1 out.append("
      " + "".join(items) + "
    ") continue if ln.strip() == "---": out.append("
    ") i += 1 continue if ln.strip(): buf = [] while i < len(lines) and lines[i].strip() and not re.match(r"^(#{2,4}\s|[-*]\s|\d+\.\s|\||>)", lines[i]) and lines[i].strip() != "---": buf.append(lines[i].strip()) i += 1 out.append("

    " + inline(" ".join(buf)) + "

    ") continue i += 1 return "\n".join(out) def render(): md = open(MD, encoding="utf-8").read() body_md = md[md.index("## 0. 결론"):] head = f""" 경쟁 병원 영문 AEO/GEO 비교 진단
    INFINITH AI Discovery · 경쟁 비교 진단

    경쟁 병원 영문 사이트
    AEO / GEO 비교 진단

    뷰성형외과 · JK성형외과 · ID병원 영문 사이트와 AI 답변 노출

    작성 2026-09-18사이트 진단 2026-09-18 AI 답변 3엔진 × 60문항내부 검토용 초안
    뷰성형외과 영문
    67B
    자동 22항목
    JK성형외과 영문
    34D
    자동 22항목
    ID병원 영문
    37D
    자동 22항목
    발견 질문 등장
    10/12
    JK 9 · ID 7 로 팽팽
    측정 엔진
    3종
    OpenAI · Perplexity · AI Overview
    내부 검토용입니다. 경쟁 병원 실명을 담고 있어 제안서·보도자료 등 외부 자료에 그대로 쓰지 않습니다. 의료법 제56조 2항은 다른 의료기관과 비교하는 의료광고를 금지합니다.
    """ return head + md_to_html(body_md) + "
    " def to_pdf(html_path, pdf_path): from playwright.sync_api import sync_playwright with sync_playwright() as p: b = p.chromium.launch() pg = b.new_page() pg.goto("file://" + html_path, wait_until="networkidle") pg.wait_for_timeout(1500) pg.emulate_media(media="print") pg.pdf(path=pdf_path, format="A4", print_background=True, prefer_css_page_size=True) b.close() if __name__ == "__main__": h = OUT + ".html" open(h, "w", encoding="utf-8").write(render()) print("HTML:", h) if "--no-pdf" not in sys.argv: to_pdf(h, OUT + ".pdf") print("PDF:", OUT + ".pdf")