Welcome to mirror list, hosted at ThFree Co, Russian Federation.

tabbed-codeblock.html « shortcodes « layouts - github.com/kakawait/hugo-tranquilpeak-theme.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8cacb7d64a3d556dda6aefde8d3aeb96578f7c3f (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{{ $tabs := findRE "<!-- *[Tt][Aa][Bb] +(\\w*) *-->\\n([\\w\\W\\s\\S]*?)<!-- *[Ee][Nn][Dd][Tt][Aa][Bb] *-->" .Inner }}
{{ range $index,$value := $tabs }}
  {{ $language := replaceRE "<!-- *[Tt][Aa][Bb] +(\\w*) *-->" "$1" (index (findRE "<!-- *[Tt][Aa][Bb] +(\\w*) *-->" .) 0) }}
  {{ $language := lower $language }}
  {{ $content := replaceRE "<!-- *[Tt][Aa][Bb] +(\\w*) *-->\\n([\\w\\W\\s\\S]*?)<!-- *[Ee][Nn][Dd][Tt][Aa][Bb] *-->" "$2" . }}
  {{ $.Scratch.Add "tc-languages" (slice $language) }}
  {{ $.Scratch.Add "tc-content" (slice $content) }}
{{ end }}
{{ if .IsNamedParams }}
  {{ $.Scratch.Add "tc-title" (.Get "title") }}
  {{ $.Scratch.Add "tc-url" (.Get "url") }}
{{ else }}
  {{ if ge (len .Params) 1 }}
    {{ $.Scratch.Add "tc-title" (.Get 0) }}
  {{ end }}
  {{ if len .Params | eq 2 }}
    {{ $.Scratch.Add "tc-url" (.Get 1) }}
  {{ end }}
{{ end }}
<figure class="codeblock codeblock--tabbed">
  <figcaption>
    {{ if and (($.Scratch.Get "tc-url") ($.Scratch.Get "tc-title")) }}
      <span><a href="{{ ($.Scratch.Get "tc-url") | safeURL }}">{{ $.Scratch.Get "tc-title" }}</a></span>
    {{ else if $.Scratch.Get "tc-title" }}
      <span>{{ $.Scratch.Get "tc-title" }}</span>
    {{ end }}
    <ul class="tabs">
      {{ range $index, $value := $.Scratch.Get "tc-languages" }}
        <li class="tab {{ if eq $index 0 }}active{{ end }}">{{ . }}</li>
      {{ end }}
    </ul>
  </figcaption> 
  <div class="tabs-content">
    {{ range $index, $value := $.Scratch.Get "tc-content" }}
      {{ $trimmedContent := trim $value "\n" }}
      <figure class="highlight language-{{ index ($.Scratch.Get "tc-languages") $index }}" style="display: {{ if eq $index 0 }}block{{ else }}none{{ end }};">   
        <table>
          <tbody>
            <tr>
              <td class="gutter">
                <pre>{{ range $index,$value := (split $trimmedContent "\n") }}<span>{{ add $index 1 }}</span><br>{{ end }}</pre>
              </td>
              <td class="code">
                <pre class="code-highlight language-{{ index ($.Scratch.Get "tc-languages") $index }}"><code class="{{ index ($.Scratch.Get "tc-languages") $index }}">{{ $trimmedContent }}</code></pre>
              </td>
            </tr>
          </tbody>
        </table>
      </figure>
    {{ end }}
  </div>
</figure>