ein freies Lehrmittel auf der Basis von eduskript

Code Blocks (Read-Only)

Display code with syntax highlighting. For runnable, editable code, see the next chapter on Code Editors.


Basic syntax

Use triple-backtick fenced code blocks. The language identifier after the opening fence enables syntax highlighting.

```python
def factorial(n):
    if n <= 1:
        return 1
    return n * factorial(n - 1)
```
def factorial(n):
    if n <= 1:
        return 1
    return n * factorial(n - 1)

A copy button appears in the top-right corner of every code block when the student hovers.


Supported languages

Eduskript uses highlight.js for syntax highlighting, supporting hundreds of languages out of the box. Common ones:

LanguageIdentifier(s)
Pythonpython, py
JavaScriptjavascript, js
TypeScripttypescript, ts
SQLsql
HTMLhtml, xml
CSScss, scss
Javajava
C / C++c, cpp
Gogo
Rustrust
Bashbash, sh, shell
JSONjson
YAMLyaml, yml
Markdownmarkdown, md
Diffdiff
Plain text(omit language)

Unrecognized languages get plain (no-color) rendering.


Plain text (no highlighting)

For console output, ASCII diagrams, or anything you don't want colorized:

```
+----+----+
| A  | B  |
+----+----+
| 1  | 2  |
+----+----+
```

Inline code

Single backticks for inline:

Use the `print()` function to output text. Variables like `count` are case-sensitive.

Use the print() function to output text. Variables like count are case-sensitive.


Code block vs code editor

FeatureCode blockCode editor
Syntax highlighting
Copy button
Editable by student
Runnable in browser✓ (Python, JS, SQL)
Saves student changes✓ (per student)
Auto-graded✓ (with python-check)
Page weighttinylarger (loads CodeMirror, Pyodide, etc.)

Use code blocks for:

  • Examples you want students to read but not modify
  • Reference material (configuration, command-line syntax)
  • Output/expected results to compare against
  • Code in languages Eduskript can't run (Java, C++, Go, etc.)

Use code editors when students should experiment, run, or be graded.


Multi-line examples

Long code blocks just work — students can scroll within the block. For very long code (50+ lines), consider:

  1. Splitting into smaller blocks with prose between them
  2. Linking to a code file students can download (via the Files panel)
  3. Using a code editor with multiple files (each file becomes a tab)

Code blocks inside other components

Code blocks work inside callouts, tabs, list items, table cells, and pretty much anywhere markdown allows nested content. Note that fenced code blocks inside a callout need each line prefixed with >:

> [!example] An example
> ```python
> print("Hello")
> ```

Code block cheat sheet

GoalSyntax
Highlighted code block```python ... ``` (or any language)
Plain text block``` ... ``` (no language)
Inline code`name`
Code in a calloutPrefix each line with > (including the fence lines)