Render balanced backticks as inline code in text blocks

This commit is contained in:
Dandaedre 2026-09-16 17:36:59 +02:00
parent 5d37b6340d
commit 64c30968a2
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
3 changed files with 29 additions and 1 deletions

View File

@ -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.

View File

@ -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: ""))],

View File

@ -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"