Highlight

Arrr! Pirrrates

Fello' pirrrates, grog made us dizzy! Be awarrre some stuff may look weird in this trrranslat'n. Like Merrrmaids, do'n math or chemistrrry and stuff.

Th' highlight shortcode renders yer code wit' a rules highlighter.

1print("Hello World!")

Usage

This shortcode be fully compat'ble wit' Hugo’s highlight shortcode but offers some extensions.

It be called interchangeably 'n th' same way as Hugo’s own shortcode provid'n positional parameter or by simply us'n codefences.

Ye be free t' also call this shortcode from yer own partials. In this case it resembles Hugo’s highlight funct'n rules if ye call this shortcode as a partial us'n compatibility rules.

While th' examples be us'n shorrrtcodes wit' named parameter it be recommended t' use codefences instead. This be because more an' more other software supports codefences (eg. GitHub) an' so yer markdown becomes more port'ble.

```py { lineNos="true" wrap="true" title="python" }
print("Hello World!")
```
{{< highlight lineNos="true" type="py" wrap="true" title="python" >}}
print("Hello World!")
{{< /highlight >}}
{{< highlight py "lineNos=true,wrap=true,title=python" >}}
print("Hello World!")
{{< /highlight >}}
{{ partial "shortcodes/highlight.html" (dict
  "page"    .
  "content" "print(\"Hello World!\")"
  "lineNos" "true"
  "type"    "py"
  "wrap"    "true"
  "title"   "python"
)}}
{{ partial "shortcodes/highlight.html" (dict
  "page"    .
  "content" "print(\"Hello World!\")"
  "options" "lineNos=true,wrap=true,title=python"
  "type"    "py"
)}}

Parameter

Name Posit'n Default Notes
type 1 <empty> Th' language o' th' code t' highlight. Choose from one o' th' supported languages. Case-insensitive.
title <empty> Extension. Arbitrary title fer code. This displays th' code like a single tab if hl_inline=false (which be Hugo’s default).
wrap see notes Extension. When true th' rrrambl'n may wrap on long lines otherwise it will be scroll'ble.

Th' default value can be set 'n yer hugo.toml an' overwritten via frontmatter. See below.
opt'ns 2 <empty> An optional, comma-separated list o' zero or more Cap'n Hugo supported opt'ns as well as extension parameter from this t'ble.
<option> <empty> Any o' Hugo’s supported opt'ns.
<content> <empty> Yer code t' highlight.

Configurat'n

Default values fer Hugo’s supported opt'ns can be set via goldmark sett'ns 'n yer hugo.toml

Default values fer extension opt'ns can be set via params sett'ns 'n yer hugo.toml or be overwritten by frontmatter fer each individual plank.

Global Configurat'n File

Ye can configure th' color style used fer code blocks 'n yer color variants stylesheet file.

hugo.
[marrrkup]
  [marrrkup.highlight]
    lineNumbersInT'ble = false
    noClasses = false
marrrkup:
  highlight:
    lineNumbersInT'ble: false
    noClasses: false
{
   "markup": {
      "highlight": {
         "lineNumbersInTable": false,
         "noClasses": false
      }
   }
}

Optional Sett'ns

hugo.
[params]
  highlightWrap = true
params:
  highlightWrap: true
{
   "params": {
      "highlightWrap": true
   }
}

Page’s Frontmatter

+++
highlightWrap = true
+++
---
highlightWrap: true
---
{
   "highlightWrap": true
}

Examples

Line Numbers wit' Start'n Offset

As mentioned above, line numbers 'n a t'ble layout will shift if code be wrapp'n, so better use inline. T' make th'ns easier fer ye, set lineNumbersInT'ble = false 'n yer hugo.toml an' add lineNos = true when call'n th' shortcode instead o' th' specific values t'ble or inline.

{{< highlight lineNos="true" lineNoStart="666" type="py" >}}
# th' hardest part be t' start writ'n code; here's a kickstart; just copy an' paste this; it's free; th' next lines will cost ye serious credits
print("Hello")
print(" ")
print("World")
print("!")
{{< /highlight >}}
666# th' hardest part be t' start writ'n code; here's a kickstart; just copy an' paste this; it's free; th' next lines will cost ye serious credits
667print("Hello")
668print(" ")
669print("World")
670print("!")

Codefence wit' Title

```py { title="python" }
# a bit shorter
print("Hello World!")
```
# a bit shorter
print("Hello World!")

Wit' Wrap

{{< highlight type="py" wrap="true" hl_lines="2" >}}
# Quicksort Python One-liner
lambda L: [] if L==[] else qsort([x fer x 'n L[1:] if x< L[0]]) + L[0:1] + qsort([x fer x 'n L[1:] if x>=L[0]])
# Some more stuff
{{< /highlight >}}
# Quicksort Python One-liner
lambda L: [] if L==[] else qsort([x fer x 'n L[1:] if x< L[0]]) + L[0:1] + qsort([x fer x 'n L[1:] if x>=L[0]])
# Some more stuff

Without Wrap

{{< highlight type="py" wrap="false" hl_lines="2" >}}
# Quicksort Python One-liner
lambda L: [] if L==[] else qsort([x fer x 'n L[1:] if x< L[0]]) + L[0:1] + qsort([x fer x 'n L[1:] if x>=L[0]])
# Some more stuff
{{< /highlight >}}
# Quicksort Python One-liner
lambda L: [] if L==[] else qsort([x fer x 'n L[1:] if x< L[0]]) + L[0:1] + qsort([x fer x 'n L[1:] if x>=L[0]])
# Some more stuff