hugo-theme-hilfe/exampleSite/content/usage/code_blocks.md

76 lines
1.2 KiB
Markdown
Raw Normal View History

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
To display an inline shortcode use single quotes:
```
`some code`
```
**Example:** `some code`
## Code blocks
2020-05-31 18:17:32 +02:00
Code blocks can be uses without language specification:
2020-01-12 15:33:02 +01:00
````
```
some code
```
````
**Example:**
```
some code
```
... or if you need language specific syntax highlighting:
````
```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" >}}
```TOML
pygmentsUseClasses=true
pygmentsCodeFences=true
```
{{< /tab >}}
{{< tab "YAML" >}}
```YAML
pygmentsUseClasses: true
pygmentsCodeFences: true
```
{{< /tab >}}
{{< /tabs >}}
You can use it like every other shortcode:
```Markdown
{{</* highlight Shell "linenos=table" */>}}
# some code
echo "Hello World"
{{</* /highlight */>}}
```
**Example:**
{{< highlight Shell "linenos=table" >}}
# some code
echo "Hello World"
{{< /highlight >}}