Code examples and syntax colours

Add a language after the opening Markdown fence. Grapharch colours code when it builds the HTML and PDF, using the same light palette in both. The optional example marker adds a numbered example caption.

```python example
from pathlib import Path

print(Path("data").name)
```
LanguageFence names
Pythonpython, py
Bash and shellbash, sh, shell
JavaScript and Node.jsjavascript, js, node, nodejs
TypeScripttypescript, ts
JSONjson
JSON-LDjson-ld, jsonld
Turtleturtle, ttl, rdf-turtle
SPARQLsparql, rq

JSON-LD and SPARQL

Example
{
  "@context": { "name": "https://schema.org/name" },
  "@id": "https://example.org/products/bonds",
  "name": "UK Bonds"
}
Example
PREFIX dct: <http://purl.org/dc/terms/>
SELECT ?dataset $title WHERE {
  ?dataset dct:title $title .
  FILTER(LANG($title) = "en")
}

See the multilingual code showcase for complete Python, Bash, JavaScript, TypeScript, JSON, JSON-LD, Turtle and SPARQL examples with a matching PDF. Its publication definition also demonstrates fenced Markdown stored in an RDF documentation fragment.

Source and display

Code is displayed, never executed. Strings, Unicode, environment variables, backticks, JSON-LD keywords and SPARQL IRIs remain source text. PDF code wraps within the page; tabs display at four-column stops. Wrapped lines retain their syntax colours, including inside multiline strings.

Grapharch also recognises languages in its bundled syntax library. Fences without a language, or with an unrecognised language name, display as plain code. A fence language controls presentation and does not validate the code.

Highlighting works offline: the generated website needs no syntax-highlighting script or external service, and the PDF needs no additional Typst package. The engine uses Syntect and the syntax bundle already used by Typst; SPARQL and Turtle use the bundled LinkedData grammar.

Search documentation

Enter words to search this site.