This lesson is still being designed and assembled (Pre-Alpha version)

Adding Code With Syntax Highlighting

Overview

Teaching: 0 min
Exercises: 0 min
Questions
  • How does one add code?

  • How does one add syntax highlighting for a specific language?

Objectives
  • Adding code and syntax highlighting

Code and Syntax Highlighting

You have probably seen how code is displayed in the Carpentries lessons in a grey block and with syntax highlighting. Since most of what we do is about coding, this is a very handy feature. Whenever you surround text with three back quotes (`) the text will be displayed monospace and in a gray box:

```
s = "This is a Python string"
print(s)
```

To get syntax highlighting, just add the name of the programming language directly after the first three back quotes:

```python
s = "This is a Python string"
print(s)
```

This will be displayed as:

s = "This is a Python string"
print(s)

Key Points

  • Using back quotes for code