2021-11-23 15:53:25 +00:00
---
title: Code Blocks
date: 2021-11-21T15:00:00+01:00
authors:
- john-doe
tags:
- Documentation
- Features
---
There are several ways to add code blocks. Most of them work out of the box, only the Hugo short code `<highlight>` needs to be configured to work properly. The theme also provides some additional features like a copy button and an option to set the maximum length of code blocks. Both of these functions and the dependent formatting rely on the `.highlight` CSS class. You must ensure that you always assign a language to your code blocks if you want to use these functions. If you do not want to apply syntax highlighting, you can also specify `plain` or `text` as the language.
{{< toc > }}
## Inline code
To display an inline shortcode use single quotes:
2023-06-22 08:52:32 +00:00
```plain
2021-11-23 15:53:25 +00:00
`some code`
```
2022-02-02 21:27:10 +00:00
**Example:** `some code` with a [`link` ](# )
2021-11-23 15:53:25 +00:00
## Code blocks
Code blocks can be uses without language specification:
2023-06-22 08:52:32 +00:00
````markdown
```plain
2021-11-23 15:53:25 +00:00
some code
```
````
**Example:**
2023-06-22 08:52:32 +00:00
```plain
2021-11-23 15:53:25 +00:00
some code
```
... or if you need language specific syntax highlighting:
2023-06-22 08:52:32 +00:00
````markdown
```shell
2021-11-23 15:53:25 +00:00
# some code
echo "Hello world"
```
````
**Example:**
2023-06-22 08:52:32 +00:00
```shell
2021-11-23 15:53:25 +00:00
# some code
echo "Hello World"
```
## Highlight shortcode
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:
{{< tabs " uniqueid " > }}
{{< tab " TOML " > }}
2023-06-22 08:52:32 +00:00
```toml
2021-11-23 15:53:25 +00:00
pygmentsUseClasses=true
pygmentsCodeFences=true
```
{{< / tab > }}
{{< tab " YAML " > }}
2023-06-22 08:52:32 +00:00
```yaml
2021-11-23 15:53:25 +00:00
pygmentsUseClasses: true
pygmentsCodeFences: true
```
{{< / tab > }}
{{< / tabs > }}
You can use it like every other shortcode:
<!-- prettier - ignore -->
2023-06-22 08:52:32 +00:00
```markdown
2021-11-23 15:53:25 +00:00
{{< /* highlight Shell "linenos=table" */>}}
# some code
echo "Hello World"
{{< /* /highlight */>}}
```
**Example:**
<!-- prettier - ignore - start -->
2023-05-03 12:00:13 +00:00
<!-- markdownlint - capture -->
<!-- markdownlint - disable -->
2021-11-23 15:53:25 +00:00
{{< highlight Shell " linenos = table" > }}
# some code
echo "Hello World"
{{< / highlight > }}
2023-05-03 12:00:13 +00:00
<!-- markdownlint - restore -->
2021-11-23 15:53:25 +00:00
<!-- prettier - ignore - end -->