#!/usr/bin/env python3
"""Render the maintained Markdown guide into a self-contained HTML document."""
from pathlib import Path
import re,html,json,base64
ROOT=Path(__file__).resolve().parents[1]
source=ROOT/'colorBlock-level-editor/docs/SCREENSHOT_RECOGNITION_EXPLAINED.md'
# This small renderer supports precisely the tables/headings/lists/code in this guide.
def inline(s):
s=html.escape(s);s=re.sub(r'`([^`]+)`',r'\1',s);return re.sub(r'\*\*([^*]+)\*\*',r'\1',s)
lines=source.read_text().splitlines();out=[];toc=[];i=0
while i'+html.escape('\n'.join(block))+'');i+=1;continue
if line.startswith('#'):
level=len(line)-len(line.lstrip('#'));title=line[level:].strip();id='section-'+str(len(toc)) if level==2 else 'h-'+str(i)
if level==2:toc.append((id,title))
if level>1:out.append(f'{inline(title)}')
i+=1;continue
if line.startswith('|'):
rows=[]
while i
'+''.join('
'+inline(c)+'
' for c in rows[0])+'
'+''.join('
'+''.join('
'+inline(c)+'
' for c in row)+'
' for row in rows[1:])+'
');continue
if re.match(r'(- |\d+\. )',line):
tag='ul' if line.startswith('-') else 'ol';items=[]
while i'+''.join('
'+inline(c)+'
' for c in items)+''+tag+'>');continue
paragraph=[]
while i'+inline(' '.join(paragraph))+'
')
result=json.loads((ROOT/'outputs/editor-level19-20261015/result.json').read_text())
grid=result['inspections'][0]['grid'];old={'cols':6,'rows':10,'corners':[[152.5197,338],[646.7146,338],[661.6781,1130],[127.5033,1130]],'rowCurve':-.154803758}
def point(g,c,r):
u=c/g['cols'];t=r/g['rows'];v=t+g['rowCurve']*t*(t-1);a,b,d,e=g['corners'];return [(1-v)*((1-u)*a[j]+u*b[j])+v*((1-u)*e[j]+u*d[j]) for j in (0,1)]
def grid_svg(g):
poly=[]
for c in range(g['cols']+1):poly.append([point(g,c,r/4) for r in range(g['rows']*4+1)])
for r in range(g['rows']+1):poly.append([point(g,0,r),point(g,g['cols'],r)])
return ''.join('' for ps in poly)
img=base64.b64encode(Path('/Users/ruoruo/Desktop/截屏2026-10-15 19.37.51.png').read_bytes()).decode()
figure=f'''