From 64c30968a29981371c5be283e335443d67b99732 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Wed, 16 Sep 2026 17:36:59 +0200 Subject: [PATCH] Render balanced backticks as inline code in text blocks --- docs/report-contract.md | 3 +++ templates/report.typ | 11 ++++++++++- tests/test_render.py | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/report-contract.md b/docs/report-contract.md index 14aa426..2ba27e7 100644 --- a/docs/report-contract.md +++ b/docs/report-contract.md @@ -83,6 +83,9 @@ are rejected, including legacy `diagnostics`, top-level `organization` and named Unknown or misspelled blocks fail validation. Text and commands are data, not code for the validator to execute. The renderer must preserve that boundary. +Within a `text` block, balanced single backticks mark inline code, for example +`` `5661ea1` ``. The renderer uses Typst's inline raw text for the marked span; +unmatched backticks remain literal. This formatting never executes report text. 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. diff --git a/templates/report.typ b/templates/report.typ index acd4785..2fe3acb 100644 --- a/templates/report.typ +++ b/templates/report.typ @@ -26,6 +26,15 @@ } else if value in ("ok", "success") { color("success", "#356344") } else { color("info", "#385f7a") } #let as-text(value) = str(value) +#let inline-code(value) = { + let parts = str(value).split("`") + if parts.len() == 1 or calc.rem(parts.len(), 2) == 0 { return str(value) } + let result = () + for (index, part) in parts.enumerate() { + result.push(if calc.rem(index, 2) == 1 { raw(part, block: false) } else { text(part) }) + } + result.join() +} #let report-type-label(value) = if value == "technical" { "Technical report" } else if value == "briefing" { "Stakeholder briefing" } else { str(value) } #let heading(title) = block(above: 12pt, below: 5pt)[ @@ -44,7 +53,7 @@ ] #let render-block(item) = { let kind = get(item, "type", default: "text") - if kind == "text" { [#as-text(get(item, "text", default: ""))] } + if kind == "text" { inline-code(get(item, "text", default: "")) } else if kind == "bullets" { list(..get(item, "items", default: ()).map(value => [#as-text(value)])) } else if kind == "steps" { enum(..get(item, "items", default: ()).map(value => [#as-text(value)])) } else if kind == "callout" { callout([#as-text(get(item, "text", default: ""))], diff --git a/tests/test_render.py b/tests/test_render.py index 992ea30..425ca63 100644 --- a/tests/test_render.py +++ b/tests/test_render.py @@ -95,6 +95,22 @@ class RenderTests(unittest.TestCase): for phrase in ("Evidence review", "The capture is preserved.", "Verify its hash."): self.assertIn(phrase, extracted) + def test_text_block_formats_balanced_inline_code(self): + report = {"schema_version": 1, "title": "Inline code", "metadata": { + "Date": "2026-09-15", "Author": "Synthetic Author"}, + "sections": [{"title": "Revisions", "content": [ + {"type": "text", "text": "Pinned `5661ea1` and `5969196`."}, + {"type": "text", "text": "Unmatched ` stays literal."}]}]} + input_path = self.work / "inline.json" + input_path.write_text(json.dumps(report), encoding="utf-8") + output = self.work / "inline.pdf" + renderer.render(input_path, output, TYPST) + self.assert_pdf(output) + if PDFTOTEXT: + extracted = subprocess.check_output([PDFTOTEXT, str(output), "-"], text=True) + self.assertIn("Pinned 5661ea1 and 5969196.", extracted) + self.assertIn("Unmatched ` stays literal.", 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"