From 5d37b6340dcf9f1a1c1467f3d11b0e6693d05117 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Wed, 16 Sep 2026 17:33:01 +0200 Subject: [PATCH] Add rounded card content blocks to reports --- docs/report-contract.md | 16 ++++++++++++++++ schema/report.schema.json | 28 ++++++++++++++++++++++++++++ templates/report.typ | 11 +++++++++++ tests/test_contract.py | 12 ++++++++++++ tests/test_render.py | 17 +++++++++++++++++ tools/validate.typ | 8 +++++--- 6 files changed, 89 insertions(+), 3 deletions(-) diff --git a/docs/report-contract.md b/docs/report-contract.md index eb05e68..14aa426 100644 --- a/docs/report-contract.md +++ b/docs/report-contract.md @@ -79,9 +79,25 @@ are rejected, including legacy `diagnostics`, top-level `organization` and named | `callout` | `text` | `title`, `kind` (severity token) | | `code` | `text` | — | | `subsection` | `title`, nonempty nested `content` | — | +| `card` | `title`, nonempty nested `content` | `tone` (severity token) | Unknown or misspelled blocks fail validation. Text and commands are data, not code for the validator to execute. The renderer must preserve that boundary. +Cards render as rounded, shaded panels. Omit `tone` for a neutral panel or set +it to a severity token to tint its border and background. A card may contain +the same block types as a section, including lists and nested subsections. + +```yaml +sections: + - title: Review + content: + - type: card + title: Evidence preserved + tone: success + content: + - type: text + text: The original capture and its hash are retained. +``` ## Branding and path resolution diff --git a/schema/report.schema.json b/schema/report.schema.json index 533bad9..5e6d56c 100644 --- a/schema/report.schema.json +++ b/schema/report.schema.json @@ -514,6 +514,34 @@ ], "additionalProperties": false }, + { + "type": "object", + "properties": { + "type": { + "const": "card" + }, + "title": { + "type": "string", + "pattern": "\\S" + }, + "tone": { + "enum": ["info", "low", "medium", "high", "critical", "warning", "ok", "success", "unanalysed"] + }, + "content": { + "type": "array", + "items": { + "$ref": "#/$defs/block" + }, + "minItems": 1 + } + }, + "required": [ + "type", + "title", + "content" + ], + "additionalProperties": false + }, { "type": "object", "properties": { diff --git a/templates/report.typ b/templates/report.typ index 68522e8..acd4785 100644 --- a/templates/report.typ +++ b/templates/report.typ @@ -56,6 +56,17 @@ block(above: 5pt, below: 3pt)[#text(weight: "bold", fill: ink)[#as-text(get(item, "title", default: ""))]] for child in get(item, "content", default: ()) { render-block(child); v(3pt) } } + else if kind == "card" { + let tone = get(item, "tone", default: none) + let border = if tone == none { line-color } else { severity-color(tone) } + let background = if tone == none { soft } else { border.lighten(93%) } + block(width: 100%, inset: 9pt, radius: 3pt, below: 6pt, + fill: background, stroke: 0.6pt + border)[ + #text(weight: "bold", fill: if tone == none { accent } else { border })[#as-text(item.title)] + #parbreak() + #for child in item.content { render-block(child); v(3pt) } + ] + } } #let logo = get(branding, "logo", default: none) #let organization = get(branding, "organization", default: "Report") diff --git a/tests/test_contract.py b/tests/test_contract.py index feecbaa..8c42259 100644 --- a/tests/test_contract.py +++ b/tests/test_contract.py @@ -77,6 +77,18 @@ class ReportContractTests(unittest.TestCase): blocks[0]["extra"] = "typo" self.assertTrue(validation.validate_document(self.document)) + def test_card_block_has_valid_nested_content_and_tone(self): + card = {"type": "card", "title": "Review", "tone": "warning", + "content": [{"type": "text", "text": "Check the evidence."}, + {"type": "bullets", "items": ["Preserve the capture."]}]} + self.document["sections"] = [{"title": "Cards", "content": [card]}] + self.assertEqual(validation.validate_document(self.document), []) + card["tone"] = "purple" + self.assertTrue(validation.validate_document(self.document)) + card["tone"] = "warning" + card["content"] = [] + self.assertTrue(validation.validate_document(self.document)) + def test_bad_branding_and_references(self): for path in ("../secret.svg", "/logo.svg", "C:\\logo.svg", "assets/../logo.svg", "logo.svg\n"): with self.subTest(path=path): diff --git a/tests/test_render.py b/tests/test_render.py index 9fb470d..992ea30 100644 --- a/tests/test_render.py +++ b/tests/test_render.py @@ -78,6 +78,23 @@ class RenderTests(unittest.TestCase): with self.assertRaisesRegex(ValueError, "invalid report"): renderer.render(input_path, self.work / "unknown-theme.pdf", TYPST) + def test_card_block_renders_nested_content(self): + report = {"schema_version": 1, "title": "Card example", "metadata": { + "Date": "2026-09-15", "Author": "Synthetic Author"}, + "sections": [{"title": "Overview", "content": [{"type": "card", + "title": "Evidence review", "tone": "success", "content": [ + {"type": "text", "text": "The capture is preserved."}, + {"type": "bullets", "items": ["Verify its hash.", "Keep the original."]}]}]}]} + input_path = self.work / "cards.json" + input_path.write_text(json.dumps(report), encoding="utf-8") + output = self.work / "cards.pdf" + renderer.render(input_path, output, TYPST) + self.assert_pdf(output) + if PDFTOTEXT: + extracted = subprocess.check_output([PDFTOTEXT, str(output), "-"], text=True) + for phrase in ("Evidence review", "The capture is preserved.", "Verify its hash."): + self.assertIn(phrase, extracted) + def test_existing_output_requires_force_and_input_is_never_output(self): input_path = ROOT / "examples" / "minimal-report.json" output = self.work / "report.pdf" diff --git a/tools/validate.typ b/tools/validate.typ index 3d743dc..a636e7f 100644 --- a/tools/validate.typ +++ b/tools/validate.typ @@ -24,10 +24,12 @@ } else if kind == "callout" { assert(keys-allowed(item, ("type", "title", "kind", "text")) and nonempty(item.at("text", default: none)) and nonempty(item.at("title", default: "x")) and item.at("kind", default: "info") in values, message: "invalid callout block") - } else if kind == "subsection" { + } else if kind in ("subsection", "card") { let content = item.at("content", default: none) - assert(keys-allowed(item, ("type", "title", "content")) and nonempty(item.at("title", default: none)) and - type(content) == array and content.len() > 0, message: "invalid subsection block") + let allowed = if kind == "card" { ("type", "title", "content", "tone") } else { ("type", "title", "content") } + assert(keys-allowed(item, allowed) and nonempty(item.at("title", default: none)) and + type(content) == array and content.len() > 0, message: "invalid card/subsection block") + if kind == "card" { assert(item.at("tone", default: "info") in values, message: "invalid card tone") } for child in content { validate-block(child) } } else { assert(false, message: "unsupported content block") } }