2020-05-31 18:17:32 +02:00
There are multiple ways to add code blocks. Most of them works out of the box only the Hugo shortcode `<highlight>` need some configuration to work properly.
2020-01-12 15:33:02 +01:00
## Inline code
2020-06-02 00:01:49 +02:00
2020-01-12 15:33:02 +01:00
To display an inline shortcode use single quotes:
2020-06-02 00:01:49 +02:00
```plain
2020-01-12 15:33:02 +01:00
`some code`
```
**Example:** `some code`
## Code blocks
2020-06-02 00:01:49 +02:00
2020-05-31 18:17:32 +02:00
Code blocks can be uses without language specification:
2020-01-12 15:33:02 +01:00
2020-06-02 00:01:49 +02:00
````markdown
2020-01-12 15:33:02 +01:00
```
some code
```
````
**Example:**
2020-06-02 00:01:49 +02:00
```plain
2020-01-12 15:33:02 +01:00
some code
```
... or if you need language specific syntax highlighting:
2020-06-02 00:01:49 +02:00
````markdown
2020-01-12 15:33:02 +01:00
```Shell
# some code
echo "Hello world"
```
````
**Example:**
```Shell
# some code
echo "Hello World"
```
## Highlight shortcode
2020-05-31 18:17:32 +02:00
Hugo has a build-in shortcode for syntax highlighting. To work properly with this theme, you have to set following options in your site configuration:
2020-01-12 15:33:02 +01:00
{{< tabs " uniqueid " > }}
{{< tab " TOML " > }}
2020-06-02 00:01:49 +02:00
2020-01-12 15:33:02 +01:00
```TOML
pygmentsUseClasses=true
pygmentsCodeFences=true
```
2020-06-02 00:01:49 +02:00
2020-01-12 15:33:02 +01:00
{{< / tab > }}
{{< tab " YAML " > }}
2020-06-02 00:01:49 +02:00
2020-01-12 15:33:02 +01:00
```YAML
pygmentsUseClasses: true
pygmentsCodeFences: true
```
2020-06-02 00:01:49 +02:00
2020-01-12 15:33:02 +01:00
{{< / tab > }}
{{< / tabs > }}
You can use it like every other shortcode:
2020-06-02 00:01:49 +02:00
```markdown
2020-01-12 15:33:02 +01:00
{{< /* highlight Shell "linenos=table" */>}}
# some code
echo "Hello World"
{{< /* /highlight */>}}
```
**Example:**
2020-06-02 00:01:49 +02:00
<!-- markdownlint - disable -->
2020-01-12 15:33:02 +01:00
{{< highlight Shell " linenos = table" > }}
# some code
echo "Hello World"
{{< / highlight > }}
2020-06-02 00:01:49 +02:00
<!-- markdownlint - enable -->