"""Run only checkbox-related probes; preserve upstream matrix rows.""" import importlib.metadata import inspect import json import platform import subprocess from datetime import datetime, timezone from html.parser import HTMLParser from pathlib import Path import markdown from markdown_it import MarkdownIt from markdown_it.presets import commonmark from markdown_it.renderer import RendererHTML ROOT = Path(__file__).resolve().parent OUT = ROOT / 'renderers' SAMPLES = { 'checkbox': '- [x] alpha\n- [ ] beta\n', 'checkbox-ordered': '1. [x] alpha\n2. [ ] beta\n', 'checkbox-nested': '- [ ] parent\n - [x] child\n', 'checkbox-table': '| Task | State |\n| --- | --- |\n| alpha | - [x] done |\n', 'checkbox-malformed': '- [] empty\n- [x]joined\n- [ x ] padded\n', 'checkbox-fenced': '```markdown\n- [x] alpha\n- [ ] beta\n```\n', 'checkbox-bare': '[ ] alpha\n', 'checkbox-uppercase': '- [X] alpha\n', } class Counts(HTMLParser): def __init__(self): super().__init__() self.tags = {} self.checked = 0 self.disabled = 0 def handle_starttag(self, tag, attrs): self.tags[tag] = self.tags.get(tag, 0) + 1 if tag == 'input': self.checked += 'checked' in dict(attrs) self.disabled += 'disabled' in dict(attrs) report = json.loads((OUT / 'results.json').read_text()) report['results'] = [r for r in report['results'] if r['sample'] not in SAMPLES] for sample, source in SAMPLES.items(): (OUT / f'{sample}.md').write_text(source) htmls = { 'markdown-it-commonmark': MarkdownIt('commonmark').render(source), 'markdown-it-breaks': MarkdownIt('commonmark', {'breaks': True}).render(source), 'python-markdown': markdown.markdown(source, extensions=['tables', 'fenced_code']), 'pandoc-gfm': subprocess.run(['pandoc', '-f', 'gfm', '-t', 'html'], input=source, text=True, capture_output=True, check=True).stdout, } for renderer, html in htmls.items(): output = f'lab/renderers/{sample}--{renderer}.txt' (ROOT.parent / output).write_text(html) p = Counts() p.feed(html) report['results'].append(dict(sample=sample, renderer=renderer, tags=p.tags, checked=p.checked, disabled=p.disabled, source=f'lab/renderers/{sample}.md', output=output)) report['checkbox_probe'] = { 'date': datetime.now(timezone.utc).isoformat(), 'command': '.venv/bin/python runs/2026-10-19-markovo-markdown-checkbox/lab/checkbox_probe.py', 'python': platform.python_version(), 'versions': {'markdown-it-py': importlib.metadata.version('markdown-it-py'), 'Markdown': importlib.metadata.version('Markdown'), 'pandoc': subprocess.check_output(['pandoc', '--version'], text=True).splitlines()[0]}, 'options': {'markdown-it-commonmark': 'commonmark preset, no plugins', 'markdown-it-breaks': 'commonmark preset, breaks=True, no plugins', 'python-markdown': 'extensions=[tables,fenced_code]', 'pandoc-gfm': 'pandoc -f gfm -t html'}, 'scope': 'HTML structure only; no browser clicks, persistence, GitHub.com or VS Code UI', } (OUT / 'results.json').write_text(json.dumps(report, indent=2) + '\n') for name, obj in [('commonmark-preset', commonmark.make), ('softbreak-renderer', RendererHTML.softbreak)]: (ROOT / f'{name}.txt').write_text(inspect.getsource(obj)) lines = ['# Checkbox-only structural summary', '', '| Sample | Renderer | li | input | checked | disabled | table |', '|---|---|---:|---:|---:|---:|---:|'] for row in report['results']: if row['sample'] in SAMPLES: t = row['tags'] lines.append(f"| {row['sample']} | {row['renderer']} | {t.get('li',0)} | {t.get('input',0)} | {row['checked']} | {row['disabled']} | {t.get('table',0)} |") (OUT / 'checkbox-summary.md').write_text('\n'.join(lines) + '\n') print(json.dumps(report['checkbox_probe'], indent=2))