Add rounded card content blocks to reports
This commit is contained in:
parent
e44820591e
commit
5d37b6340d
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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": {
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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") }
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue