{}OPF
DocsObject referenceView source

Code

Code content with optional rendering metadata. Use 'source' for the code text, 'language' for syntax highlighting, and 'filename' when the rendered block should show a file label. A string value in a code fiel…

Metadata

Definition
#/$defs/Code
Type
object
Source
spec/schemas/opf.schema.json

Field index

FieldTypeReq.Description
sourcestringyesSource code text to display.
languagestringLanguage identifier used for syntax highlighting.
filenamestringOptional file label shown with the code block.

source

typestringrequiredyesdefault

Source code text to display.

source.json
{
  "source": "def greet(name: str) -> str:\n    return f\"Hello, {name}!\""
}

language

typestringrequirednodefault

Language identifier used for syntax highlighting.

language.json
{
  "language": "python"
}

filename

typestringrequirednodefault

Optional file label shown with the code block.

filename.json
{
  "filename": "app.py"
}