@@ -13,10 +13,13 @@ This document is a guide for adding content to the [spine.io](https://spine.io)
1313 * [ Main navigation] ( #main-navigation )
1414 * [ Documentation side navigation] ( #documentation-side-navigation )
1515 * [ Documentation “Next/Prev” buttons] ( #documentation-nextprev-buttons )
16- * [ Adding code samples to the site] ( #adding-code-samples-to-the-site )
16+ * [ Adding code samples to the site] ( #adding-code-samples-to-the-site )
1717* [ Testing broken links] ( #testing-broken-links )
18- * [ Cloak email] ( #cloak-email )
19- * [ Note blocks] ( #note-blocks )
18+ * [ Cloak email] ( #cloak-email )
19+ * [ Note blocks] ( #note-blocks )
20+ * [ Code blocks] ( #code-blocks )
21+ * [ With triple backticks] ( #1-with-triple-backticks )
22+ * [ Using ` highlight ` shortcode] ( #2-using-highlight-shortcode )
2023
2124<small ><i ><a href =' http://ecotrust-canada.github.io/markdown-toc/ ' >Table of contents generated with markdown-toc</a ></i ></small >
2225
@@ -156,3 +159,60 @@ You can use only predefined classes such as: `note`, `warning`, or `lead`.
156159The test lead block.
157160{{% /note-block %}}
158161```
162+
163+ # Code blocks
164+
165+ There are two ways to add code blocks with syntax highlighting.
166+
167+ ### 1. With triple backticks
168+
169+ Please always specify the [ language syntax] [ syntax-highlighting-languages ]
170+ to avoid problems with the layout.
171+
172+ ```` markdown
173+ ``` bash
174+ git clone
[email protected] :spine-examples/hello.git
175+ ```
176+ ````
177+
178+ You can configure the appearance of Hugo code blocks using parameters,
179+ as described in the official [ documentation] [ code-fences-doc ] :
180+
181+ * ` linenos=table ` – configures line numbers and renders them in a table view.
182+ The table view is necessary for correct copying of code.
183+ * ` hl_lines=[8,"15-17"] ` – lists a set of line numbers or line number ranges
184+ to be additionally highlighted.
185+ * ` linenostart=199 ` – starts the line number count from 199.
186+
187+ ```` markdown
188+ ``` java {linenos=table,hl_lines=[8,"15-17"],linenostart=199}
189+ // ... code
190+ ```
191+ ````
192+
193+ ### 2. Using ` highlight ` shortcode"
194+
195+ The ` highlight ` shortcode allows to set custom visibility options related to this project,
196+ such as custom CSS classes, the text highlighting on the selected line, a file name bar, etc.
197+
198+ ``` markdown
199+ {{< highlight lang="java" params="hl_lines=10 19, linenos=table" class="hl-text-only" >}}
200+ @BeforeEach
201+ void sendCommand() {
202+ ...
203+ }
204+ {{< /highlight >}}
205+ ```
206+
207+ Where:
208+
209+ * ` lang ` – the language syntax. See the [ supported languages] [ syntax-highlighting-languages ] .
210+ * ` params ` – optional standard Hugo highlighting parameters as a string.
211+ * ` file ` – an optional name of the code file to display on the code header panel.
212+ * ` class ` – an optional class name that the code block will be wrapped in.
213+
214+ The class ` hl-text-only ` is predefined and used to highlight only the text without highlighting
215+ the entire line with background.
216+
217+ [ code-fences-doc ] : https://gohugo.io/content-management/syntax-highlighting/#highlighting-in-code-fences
218+ [ syntax-highlighting-languages ] : https://gohugo.io/content-management/syntax-highlighting/#languages
0 commit comments