mirror of
https://github.com/thegeeklab/hugo-geekdoc.git
synced 2024-11-23 05:10:39 +00:00
1.4 KiB
1.4 KiB
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.
{{< toc >}}
Inline code
To display an inline shortcode use single quotes:
`some code`
Example: some code
Code blocks
Code blocks can be uses without language specification:
```
some code
```
Example:
some code
... or if you need language specific syntax highlighting:
```Shell
# some code
echo "Hello world"
```
Example:
# 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" >}}
pygmentsUseClasses=true
pygmentsCodeFences=true
{{< /tab >}} {{< tab "YAML" >}}
pygmentsUseClasses: true
pygmentsCodeFences: true
{{< /tab >}} {{< /tabs >}}
You can use it like every other shortcode:
{{</* highlight Shell "linenos=table" */>}}
# some code
echo "Hello World"
{{</* /highlight */>}}
Example:
{{< highlight Shell "linenos=table" >}}
some code
echo "Hello World" {{< /highlight >}}