#!/usr/bin/env python3
"""Render docs/FEATURE_MATRIX.md to docs/FEATURE_MATRIX.html.
The markdown tables are the source of truth; this gives them a browsable
view with color-coded status cells (green = full, amber = partial, red =
missing). Run it whenever the matrix changes:
python3 scripts/feature-matrix-html.py
"""
import html
import os
import re
import sys
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
def cell_class(c):
t = c.strip()
if '✅' in t:
return 'ok'
if '◐' in t:
return 'part'
if t.startswith('✗'):
return 'no'
if t in ('—', '— single framebuffer'):
return 'na'
return ''
def inline(s):
s = html.escape(s)
s = re.sub(r'`([^`]+)`', r'\1', s)
s = re.sub(r'\*\*([^*]+)\*\*', r'\1', s)
return s
def convert(src):
out = ['''
' + ' '.join(inline(x) for x in para) + '
') para.clear() i = 0 while i < len(src): line = src[i] if line.startswith('|'): flush() rows = [] while i < len(src) and src[i].startswith('|'): cells = [c.strip() for c in src[i].strip().strip('|').split('|')] if not all(re.fullmatch(r':?-{2,}:?', c) for c in cells): rows.append(cells) i += 1 out.append('| {inline(c)} | ' for c in rows[0]) + '
|---|
| {inline(c)} | ' for c in r) + '
' + html.escape('\n'.join(buf)) + '')
continue
if line.startswith('#'):
flush()
n = len(line) - len(line.lstrip('#'))
out.append(f'