syntax-highlighting.md - hugo - [fork] hugo port for 9front
(HTM) git clone https://git.drkhsh.at/hugo.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Submodules
(DIR) README
(DIR) LICENSE
---
syntax-highlighting.md (2282B)
---
1 ---
2 title: Syntax highlighting
3 description: Add syntax highlighting to code examples.
4 categories: []
5 keywords: [highlight]
6 aliases: [/extras/highlighting/,/extras/highlight/,/tools/syntax-highlighting/]
7 ---
8
9 Hugo provides several methods to add syntax highlighting to code examples:
10
11 - Use the [`transform.Highlight`] function within your templates
12 - Use the [`highlight`] shortcode with any [content format](g)
13 - Use fenced code blocks with the Markdown content format
14
15 [`transform.Highlight`]: /functions/transform/highlight/
16 [`highlight`]: /shortcodes/highlight/
17
18 ## Fenced code blocks
19
20 In its default configuration, Hugo highlights code examples within fenced code blocks, following this form:
21
22 ````text {file="content/example.md"}
23 ```LANG [OPTIONS]
24 CODE
25 ```
26 ````
27
28 CODE
29 : The code to highlight.
30
31 LANG
32 : The language of the code to highlight. Choose from one of the [supported languages]. This value is case-insensitive.
33
34 OPTIONS
35 : One or more space-separated or comma-separated key-value pairs wrapped in braces. Set default values for each option in your [site configuration]. The key names are case-insensitive.
36
37 [supported languages]: #languages
38 [site configuration]: /configuration/markup/#highlight
39
40 For example, with this Markdown:
41
42 ````text {file="content/example.md"}
43 ```go {linenos=inline hl_lines=[3,"6-8"] style=emacs}
44 package main
45
46 import "fmt"
47
48 func main() {
49 for i := 0; i < 3; i++ {
50 fmt.Println("Value of i:", i)
51 }
52 }
53 ```
54 ````
55
56 Hugo renders this:
57
58 ```go {linenos=inline, hl_lines=[3, "6-8"], style=emacs}
59 package main
60
61 import "fmt"
62
63 func main() {
64 for i := 0; i < 3; i++ {
65 fmt.Println("Value of i:", i)
66 }
67 }
68 ```
69
70 ## Options
71
72 {{% include "_common/syntax-highlighting-options.md" %}}
73
74 ## Escaping
75
76 When documenting shortcode usage, escape the tag delimiters:
77
78 ````text {file="content/example.md"}
79 ```text {linenos=inline}
80 {{</*/* shortcode-1 */*/>}}
81
82 {{%/*/* shortcode-2 */*/%}}
83 ```
84 ````
85
86 Hugo renders this to:
87
88 ```text {linenos=inline}
89 {{</* shortcode-1 */>}}
90
91 {{%/* shortcode-2 */%}}
92 ```
93
94 ## Languages
95
96 These are the supported languages. Use one of the identifiers, not the language name, when specifying a language for:
97
98 - The [`transform.Highlight`] function
99 - The [`highlight`] shortcode
100 - Fenced code blocks
101
102 {{< chroma-lexers >}}