OPF

Search docs

Loading documentation…
    OpenPresentation/opf
    Browse docs
    On this page
    View source

    Code

    Code content with optional rendering metadata. Use 'source' for the code text, 'language' for syntax highlighting, 'filename' when the rendered block should show a file label, and 'highlight' to emphasize lines. A string value in a code field is shorthand for { "source": value }.

    Metadata

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

    Field index

    FieldTypeReq.Description
    sourcestringyesSource code text to display.
    languagestring—Language identifier used for syntax highlighting.
    filenamestring—Optional file label shown with the code block.
    highlightarray<integer | array<integer>>—Source lines to emphasize, 1-based: each entry is a line number or an inclusive [start, end] range, so [3, [5, 7]] marks lines 3 and 5 to 7. Lines are counted by line break in 'source', so a line that wraps stays one line. Engines draw a theme-derived band behind the marked lines and dim the other lines slightly, keeping every line at least 4.5:1 against its background; PPTX export draws one native rectangle behind the line text boxes and import restores the list. A line number past the last line, or a range written end before start, gets a validation warning (code-highlight-out-of-range, code-highlight-range-reversed) and is ignored. When a code block is paginated across slides each page keeps the lines that fall on it, renumbered from 1.

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

    highlight

    typearray<integer | array<integer>>requirednodefault—

    Source lines to emphasize, 1-based: each entry is a line number or an inclusive [start, end] range, so [3, [5, 7]] marks lines 3 and 5 to 7. Lines are counted by line break in 'source', so a line that wraps stays one line. Engines draw a theme-derived band behind the marked lines and dim the other lines slightly, keeping every line at least 4.5:1 against its background; PPTX export draws one native rectangle behind the line text boxes and import restores the list. A line number past the last line, or a range written end before start, gets a validation warning (code-highlight-out-of-range, code-highlight-range-reversed) and is ignored. When a code block is paginated across slides each page keeps the lines that fall on it, renumbered from 1.

    highlight.json
    {
      "highlight": [
        3
      ]
    }
    Complete definition constraints
    Schema constraints
    {
      "type": "object",
      "description": "Code content with optional rendering metadata. Use 'source' for the code text, 'language' for syntax highlighting, 'filename' when the rendered block should show a file label, and 'highlight' to emphasize lines. A string value in a code field is shorthand for { \"source\": value }.",
      "additionalProperties": false,
      "required": [
        "source"
      ],
      "properties": {
        "source": {
          "type": "string",
          "description": "Source code text to display.",
          "examples": [
            "def greet(name: str) -> str:\n    return f\"Hello, {name}!\""
          ]
        },
        "language": {
          "type": "string",
          "description": "Language identifier used for syntax highlighting.",
          "examples": [
            "python",
            "ts",
            "tsx",
            "rust",
            "go",
            "bash",
            "json",
            "yaml"
          ]
        },
        "filename": {
          "type": "string",
          "description": "Optional file label shown with the code block.",
          "examples": [
            "app.py",
            "components/Button.tsx",
            "terraform/main.tf"
          ]
        },
        "highlight": {
          "type": "array",
          "minItems": 1,
          "items": {
            "oneOf": [
              {
                "type": "integer",
                "minimum": 1
              },
              {
                "type": "array",
                "minItems": 2,
                "maxItems": 2,
                "items": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            ]
          },
          "description": "Source lines to emphasize, 1-based: each entry is a line number or an inclusive [start, end] range, so [3, [5, 7]] marks lines 3 and 5 to 7. Lines are counted by line break in 'source', so a line that wraps stays one line. Engines draw a theme-derived band behind the marked lines and dim the other lines slightly, keeping every line at least 4.5:1 against its background; PPTX export draws one native rectangle behind the line text boxes and import restores the list. A line number past the last line, or a range written end before start, gets a validation warning (code-highlight-out-of-range, code-highlight-range-reversed) and is ignored. When a code block is paginated across slides each page keeps the lines that fall on it, renumbered from 1.",
          "examples": [
            [
              3
            ],
            [
              3,
              [
                5,
                7
              ]
            ],
            [
              [
                2,
                4
              ]
            ]
          ]
        }
      }
    }