"""HTML fragment rendering — pure f-strings + html.escape, vivamais-style.
Every fragment the frontend swaps in is built here, so the routes in app.py
stay thin and the look lives in one place next to styles.css.
"""
from __future__ import annotations
import html
import re
from checks import Evaluation, PASS, WARN, FAIL
from guide import TAG_GLYPHS, TAG_SHORT_NAMES
from icons import ICON_PATHS
_esc = html.escape
STATUS_META = {
PASS: ("check", "ok", "all good"),
WARN: ("triangle-alert", "warn", "worth a look"),
FAIL: ("x", "fix", "needs fixing"),
}
VERDICT_META = {
"READY TO SUBMIT": ("ok", "star",
"Everything checks out — pitch your tent and submit it!"),
"ALMOST READY": ("warn", "compass",
"So close! No rule failures, just a few things worth a look below."),
"NOT READY": ("fix", "tent",
"Not there yet — a few trail markers to hit first. You've got this."),
}
def icon(name: str, cls: str = "", size: int = 18, sw: float = 1.8) -> str:
return (
f''
)
def stamp(glyph: str, tone: str = "rose", size: int = 44, spin: bool = False) -> str:
"""Mini replica of the field guide's StampBadge: disc + dashed ring + glyph."""
return (
f''
f'{icon(glyph, size=int(size * 0.4), sw=1.7)}'
)
def _inline_md(text: str) -> str:
"""Escape, then bring back `code` spans and clickable links."""
out = _esc(text)
out = re.sub(r"`([^`]+)`", r" {_inline_md(message)} {_esc(blurb)} {_esc(ev.space_id)}\1", out)
out = re.sub(r"“([^”]*)”", r"“\1”", out)
out = re.sub(
r"(https?://[^\s<]+)",
r'\1',
out,
)
return out
def render_space_options(names: list[str]) -> str:
if not names:
return ''
opts = "".join(f'' for n in names)
return f'{opts}'
def render_error(message: str) -> str:
return (
f'Hmm, that didn’t work
{_esc(ev.verdict.title())}
'
f'{rows}
'
f"{chips}{opps}"
f"
{_inline_md(evidence)}
No tracks or badges tagged yet — the judges’ ' "tooling reads these from the README frontmatter.
{_esc(t)}'
for t in known
)
return f'Badges & prizes this Space might claim but hasn’t yet:
' f'Grounded in the rule check above — this takes a little ' f"longer the first time a model wakes up.
{icon("triangle-alert", size=14, sw=2)} This is an automated ' f"+ AI evaluation — lovingly assembled, occasionally wrong. Double-check everything " f'against the official field guide before you submit, ' f"regardless of what it says.