Skip to content

Commit

Permalink
style: update the code toggle shortcode
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Nov 22, 2022
1 parent 9c044c4 commit 81e5b96
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
6 changes: 6 additions & 0 deletions assets/main/scss/_code.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@ pre {
user-select: all;
}
}

.code-toggle {
.highlight-wrapper {
margin-top: .5rem;
}
}
Binary file modified exampleSite/content/docs/shortcodes/code-toggle/featured.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 28 additions & 27 deletions layouts/shortcodes/code-toggle.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@
{{- $filename := default "" (.Get "filename") -}}
{{- $idSuffix := printf "%s%s" (replace $filename "/" "-") (delimit (shuffle (seq 1 9)) "") -}}
{{- $langs := slice "toml" "yaml" "json" -}}
<ul class="nav nav-tabs" role="tablist">
{{- $i := 0 -}}
{{- with $filename -}}
<li class="nav-item mb-0">
<span class="nav-link disabled text-secondary px-2 py-1">{{ . }}.</span>
</li>
{{- end -}}
{{- range $langs -}}
{{- $id := printf "%s-%s" . $idSuffix -}}
<li class="nav-item mb-0" role="presentation">
<button class="nav-link px-2 py-1 border-0{{ if eq $i 0 }} active{{ end }}" id="{{ $id }}-tab" data-bs-toggle="tab" data-bs-target="#{{ $id }}" type="button" role="tab"
aria-controls="home" aria-selected="{{ if eq $i 0 }}true{{ else }}false{{ end }}">
{{ . }}
</button>
</li>
<div class="code-toggle border border-secondary rounded px-2 pt-2">
<ul class="nav nav-tabs border-secondary mb-0" role="tablist">
{{- $i := 0 -}}
{{- range $langs -}}
{{- $id := printf "%s-%s" . $idSuffix -}}
<li class="nav-item mb-0" role="presentation">
<button class="nav-link p-1{{ if eq $i 0 }} active{{ end }}" id="{{ $id }}-tab" data-bs-toggle="tab" data-bs-target="#{{ $id }}" type="button" role="tab"
aria-controls="home" aria-selected="{{ if eq $i 0 }}true{{ else }}false{{ end }}">
{{ . | upper }}
</button>
</li>
{{- $i = add $i 1 -}}
{{- end -}}
</ul>
<div class="tab-content">
{{- $i := 0 -}}
{{- range $langs -}}
{{- $lang := . }}
{{- $id := printf "%s-%s" . $idSuffix -}}
{{- $code := $.Inner | transform.Unmarshal | transform.Remarshal . -}}
{{- $code = replaceRE "\n+" "\n" $code -}}
<div class="tab-pane fade{{ if eq $i 0 }} show active{{ end }}" id="{{ $id }}" role="tabpanel" aria-labelledby="{{ $id }}-tab">
{{- with $filename -}}
<p class="user-select-all mt-2 mb-0 text-primary fw-bold">{{ . }}.{{ $lang }}</p>
{{- end -}}
{{- highlight $code . -}}
</div>
{{- $i = add $i 1 -}}
{{- end -}}
</ul>
<div class="tab-content">
{{- $i := 0 -}}
{{- range $langs -}}
{{- $id := printf "%s-%s" . $idSuffix -}}
{{- $code := $.Inner | transform.Unmarshal | transform.Remarshal . -}}
{{- $code = replaceRE "\n+" "\n" $code -}}
<div class="tab-pane fade{{ if eq $i 0 }} show active{{ end }}" id="{{ $id }}" role="tabpanel" aria-labelledby="{{ $id }}-tab">
{{- highlight $code . -}}
{{- end -}}
</div>
{{- $i = add $i 1 -}}
{{- end -}}
</div>

0 comments on commit 81e5b96

Please sign in to comment.