#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""把对比页右侧（新版）导成 Markdown，供下载。"""
import re, html

SRC = '/root/media-hub/export/拍摄/compare-v7-edit.html'
OUT = '/root/media-hub/export/拍摄/dquan-agent-script-1104.md'

h = open(SRC, encoding='utf-8').read()
out = ['# 大全 · 通用 Agent 实战大课（口播定稿 · 2026-11-04）', '']
tot = 0
for n in range(1, 16):
    body = re.search(r'<section id="s%d">(.*?)</section>' % n, h, re.S).group(1)
    title = re.sub(r'<[^>]+>', '', re.search(r'<h2>(.*?)</h2>', body, re.S).group(1)).strip()
    right = body.split('<div class="col new">')[1]
    out.append('## %d. %s' % (n, title))
    out.append('')
    for p in re.findall(r'<div class="txt edit"[^>]*>(.*?)</div>', right, re.S):
        t = re.sub(r'<del>.*?</del>', '', p, flags=re.S)
        t = html.unescape(re.sub(r'<[^>]+>', '', t)).replace('\u00a0', ' ').strip()
        if not t:
            continue
        out.append(t)
        out.append('')
        tot += len(re.findall(r'[\u4e00-\u9fff]', t))
md = '\n'.join(out).rstrip() + '\n'
open(OUT, 'w', encoding='utf-8').write(md)
print('bytes', len(md.encode()), '汉字', tot, '节', md.count('\n## '))
