trwnh.com/unified.test.hugo/layouts/_default/_markup/render-codeblock.html

53 lines
1.4 KiB
HTML
Raw Normal View History

{{- $result := transform.HighlightCodeBlock . }}
{{- $caption := .Attributes.caption }}
{{- $title := .Attributes.title }}
{{- if $caption }}
{{- printf "<!-- begin figure with codeblock %s -->" (string (add .Ordinal 1)) | safeHTML }}
<figure class="figure-with-codeblock"{{if $title}} title="{{$title}}"{{end}}>
{{ with $title }}<header class="codeblock__header"><p class="codeblock__title">{{.}}</p></header>{{ end }}
2024-10-12 18:45:14 +00:00
<div class="codeblock highlight">
<pre class="chroma">
{{
(
replaceRE
`(?s)<span class="gi">(.*?)</span>`
`<ins class="gi">$1</ins>`
(
replaceRE
`(?s)<span class="gd">(.*?)</span>`
`<del class="gd">$1</del>`
$result.Inner
)
) | safeHTML
}}
</pre>
</div>
<figcaption>{{$caption | markdownify}}</figcaption>
</figure>
{{ printf "<!-- end figure with codeblock %s -->" (string (add .Ordinal 1)) | safeHTML }}
{{ else }}{{/* not a figure, just a regular codeblock */}}
{{- printf "<!-- begin codeblock %s -->" (string (add .Ordinal 1)) | safeHTML }}
<article class="codeblock highlight">
{{- with $title }}
<header class="codeblock__header">
<p class="codeblock__title">{{.}}</p>
</header>
{{- end }}
<pre class="chroma">
{{
(
replaceRE
`(?s)<span class="gi">(.*?)</span>`
`<ins class="gi">$1</ins>`
(
replaceRE
`(?s)<span class="gd">(.*?)</span>`
`<del class="gd">$1</del>`
$result.Inner
)
) | safeHTML
}}
</pre>
</article>
{{- printf "<!-- end codeblock %s -->" (string (add .Ordinal 1)) | safeHTML }}
{{ end }}