Skip to content

Code highlighting

A title identifies the file, line numbers support discussion, and a highlight directs attention.

greeting.py
1
2
3
4
def greet(name: str) -> str:
    return f"Hello, {name}!"

print(greet("reader"))

Inline highlighting works too: greet("reader").

Show Markdown source
```python title="greeting.py" linenums="1" hl_lines="2"
def greet(name: str) -> str:
    return f"Hello, {name}!"

print(greet("reader"))
```

Inline highlighting works too: `#!python greet("reader")`.

Shell example

A second language demonstrates that the highlighter follows the selected lexer.

inspect.sh
printf 'Current directory: '
pwd
Show Markdown source
```sh title="inspect.sh" linenums="1"
printf 'Current directory: '
pwd
```

References