aboutsummaryrefslogtreecommitdiff
path: root/themes/default/layouts/_default/_markup/render-codeblock.html
blob: ab9a786a67ed293ae1ae4f33ba3b8ae51d44d767 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{{- $caption   := .Attributes.caption -}}
{{- $type      := .Type | default "text" -}}
{{- $options   := .Attributes.options | default "default=1" -}}
{{- $hash      := print (truncate 3 "" (sha256 .Inner)) (truncate 3 "" (sha256 .Page.RelPermalink)) .Ordinal -}}
{{- $id        := print "code-block:" $hash | safeURL -}}
{{- $highlight := highlight .Inner $type (print $options ",lineAnchors=" "code-line:" $hash) -}}

<code-block id="{{ $id }}" {{ if in (lower $options) "linenos" }}data-lines=""{{ end }}>
  <header>
  <language-label>
    <a href="#{{ $id }}">{{ $type }}</a>
  </language-label>
  </header>
  <code-content contenteditable="true" spellcheck="false">
    {{- replace $highlight
      `class="lnlinks"`
      `contenteditable="false" class="lnlinks"`
      | safeHTML
    -}}
  </code-content>
</code-block>

{{- with $caption -}}
  <footer>{{ . | markdownify }}</footer>
{{- end -}}