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 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" 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 Default Notes
type <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 Hugos 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 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 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 config.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