Use styles for syntax highlighting in XML

This commit is contained in:
Will Faught
2025-03-04 22:48:09 -08:00
parent 9fafcc5215
commit 9d657b47e3
3 changed files with 44 additions and 2 deletions

View File

@@ -1,3 +1,14 @@
{{ $result := transform.HighlightCodeBlock . (merge .Options (dict "noclasses" true "style" "github")) }}
{{ $context := . }}
{{ $options := dict }}
{{ $overrides := dict "noclasses" true }}
{{ with $context.Options }}
{{ $options = merge $overrides . }}
{{ else }}
{{ $options = $overrides }}
{{ end }}
{{ $result := transform.HighlightCodeBlock $context $options }}
{{ $result.Wrapped }}

View File

@@ -1,3 +1,14 @@
{{ $result := transform.HighlightCodeBlock . (merge .Options (dict "noclasses" true "style" "github")) }}
{{ $context := . }}
{{ $options := dict }}
{{ $overrides := dict "noclasses" true }}
{{ with $context.Options }}
{{ $options = merge $overrides . }}
{{ else }}
{{ $options = $overrides }}
{{ end }}
{{ $result := transform.HighlightCodeBlock $context $options }}
{{ $result.Wrapped }}

View File

@@ -0,0 +1,20 @@
{{ $content := .InnerDeindent | strings.TrimLeft "\f\n\r\v" | strings.TrimRight "\f\n\r\t\v " }}
{{ $lang := .Get 0 | default (.Get "lang") | default "plaintext" }}
{{ $options := .Get "options" }}
{{ $unescape := .Get "unescape" }}
{{ if not $content }}
{{ errorf "layouts/shortcodes/paige/code.xml: no content" }}
{{ end }}
{{ if $options }}
{{ $options = printf "%s,noclasses=true" $options }}
{{ else }}
{{ $options = "noclasses=true" }}
{{ end }}
{{ if $unescape }}
{{ $content = htmlUnescape $content }}
{{ end }}
<div class="paige-shortcode-code">{{ highlight $content $lang $options }}</div>