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 compat'ble wit' Hugo’s highlight shortcode but offers some extensions.

Ye can call it interchangeably 'n th' same way as Hugo’s own shortcode us'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 somewhat resemble Hugo’s highlight funct'n rules if ye call this shortcode as a partial us'n compatiblity 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" }
print("Hello World!")
```
{{< highlight lineNos="true" type="py" wrap="true" >}}
print("Hello World!")
{{< /highlight >}}
{{< highlight py "lineNos=true,wrap=true" >}}
print("Hello World!")
{{< /highlight >}}
{{ partial "shortcodes/highlight.html" (dict
  "page"    .
  "content" "print(\"Hello World!\")"
  "lineNos" "true"
  "type"    "py"
  "wrap"    "true"
)}}
{{ partial "shortcodes/highlight.html" (dict
  "page"    .
  "content" "print(\"Hello World!\")"
  "options" "lineNos=true,wrap=true"
  "type"    "py"
)}}

Parameter

Name Default Notes
type <empty> Th' language o' th' code t' highlight. Choose from one o' th' supported languages. Case-insensitive.
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 config.toml an' overwritten via frontmatter. See below.
opt'ns <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 config.toml

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

Global Configurat'n File

[marrrkup]
  [marrrkup.highlight]
    # line numbers 'n a t'ble layout will shift if code be wrapp'n, so better
    # use inline; besides that visually both layouts have th' same look an' behavior
    lineNumbersInT'ble = false

    # if `guessSyntax = true`, there will be no unstyled code even if no language
    # was given BUT Merrrmaid an' Math codefences will not work anymore! So this be a
    # mandatory sett'n fer yer ship if ye want t' use Merrrmaid or Math codefences
    guessSyntax = false

    # th' shipped variants come wit' their own modified chroma rules highlightn'n
    # style which be imported 'n theme-relearn-light.css, theme-relearn-dark.css, etc.;
    # if ye want t' use a predefined style instead:
    # - remove `noClasses` or set `noClasses = true`
    # - set `style` t' a predefined style name
    noClasses = false
    # style = "tango"

Optional Sett'ns

[params]
  highlightWrap = true

Page’s Frontmatter

+++
highlightWrap = true
+++

Examples

Line Numbers

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 config.toml an' add lineNos = true when call'n th' shortcode instead o' th' specific values t'ble or inline.

{{< highlight lineNos="true" type="py" >}}
# 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 >}}
1# Quicksort Python One-liner
2lambda 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]])
3# Some more stuff

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