Project: MetalLB (Orchestration & Management / Service Proxy)
File: highlight.en.md

+++ description = "Render code with a syntax highlighter" title = "Highlight" +++ The `highlight` shortcode renders your code with a syntax highlighter. {{< highlight lineNos="true" type="py" wrap="true" title="python" >}} print("Hello World!") {{< /highlight >}} This shortcode is fully compatible with Hugo's but offers some extensions. It is called interchangeably in the same way as Hugo's own shortcode providing positional parameter or by simply using codefences. You are free to also call this shortcode from your own partials. In this case it resembles Hugo's syntax if you call this shortcode as a partial using compatibility syntax. While the examples are using shortcodes with named parameter it is recommended to use codefences instead. This is because more and more other software supports codefences (eg. GitHub) and so your markdown becomes more portable. {{< tabs groupid="shortcode-parameter">}} {{% tab title="codefence" %}} ````md ```py { lineNos="true" wrap="true" title="python" } print("Hello World!") ``` ```` {{% /tab %}} {{% tab title="shortcode" %}} ````go {{</ highlight lineNos="true" type="py" wrap="true" title="python" />}} print("Hello World!") {{</ /highlight />}} ```` {{% /tab %}} {{% tab title="shortcode (positional)" %}} ````go {{</ highlight py "lineNos=true,wrap=true,title=python" />}} print("Hello World!") {{</ /highlight />}} ```` {{% /tab %}} {{% tab title="partial" %}} ````go {{ partial "shortcodes/highlight.html" (dict "page" . "content" "print(\"Hello World!\")" "lineNos" "true" "type" "py" "wrap" "true" "title" "python" )}} ```` {{% /tab %}} {{% tab title="partial (compat)" %}} ````go {{ partial "shortcodes/highlight.html" (dict "page" . "content" "print(\"Hello World!\")" "options" "lineNos=true,wrap=true,title=python" "type" "py" )}} ```` {{% /tab %}} {{< /tabs >}} | Name | Position | Default | Notes | |--| | --|-| | type | 1 | &lt;empty&gt; | The language of the code to highlight. Choose from one of the . Case-insensitive. | | title | | &lt;empty&gt; | Extension. Arbitrary title for code. This displays the code like a if `hl_inline=false` (which is Hugos default). | | wrap | | see notes | Extension. When `true` the content may wrap on long lines otherwise it will be scrollable.<br><br>The default value can be set in your `hugo.toml` and overwritten via frontmatter.

| | options | 2 | &lt;empty&gt; | An optional, comma-separated list of zero or more as well as extension parameter from this table. | | **&lt;option&gt;** | | &lt;empty&gt; | Any of . | | **&lt;content&gt;** | | &lt;empty&gt; | Your code to highlight. | Default values for can be set via in your `hugo.toml` Default values for extension options can be set via params settings in your `hugo.toml` or be overwritten by frontmatter for each individual page. You can configure the color style used for code blocks in your file. {{< multiconfig file=hugo >}} [markup] [markup.highlight] lineNumbersInTable = false noClasses = false {{< /multiconfig >}} {{< multiconfig file=hugo >}} [params] highlightWrap = true {{< /multiconfig >}} {{< multiconfig fm=true >}} highlightWrap = true {{< /multiconfig >}} As mentioned above, line numbers in a `table` layout will shift if code is wrapping, so better use `inline`. To make things easier for you, set `lineNumbersInTable = false` in your `hugo.toml` and add `lineNos = true` when calling the shortcode instead of the specific values `table` or `inline`. ````go {{</ highlight lineNos="true" lineNoStart="666" type="py" />}} print("Hello") print(" ") print("World") print("!") {{</ /highlight />}} ```` {{< highlight lineNos="true" lineNoStart="666" type="py" >}} print("Hello") print(" ") print("World") print("!") {{< /highlight >}} ````md ```py { title="python" } print("Hello World!") ``` ```` ```py { title="python" } print("Hello World!") ``` ````go {{</ highlight type="py" wrap="true" hl_lines="2" />}} lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]]) {{</ /highlight />}} ```` {{< highlight type="py" wrap="true" hl_lines="2" >}} lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]]) {{< /highlight >}} ````go {{</ highlight type="py" wrap="false" hl_lines="2" />}} lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]]) {{</ /highlight />}} ```` {{< highlight type="py" wrap="false" hl_lines="2">}} lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]]) {{< /highlight >}}