Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style code toggle #809

Merged
merged 3 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>