fix(tabs): improve tab shortcode rendering and restore sticky code header (#772)

* fix(tabs): improve tab shortcode rendering and trim whitespace

* fix(tabs): restore sticky code header for left/right placement
This commit is contained in:
Cell
2026-05-28 12:56:07 +08:00
committed by GitHub
parent 038f602bc5
commit 5b43c2b6a3
5 changed files with 13 additions and 15 deletions
@@ -115,7 +115,7 @@ Nested tab C with a table:
{{% tab title="Outer Tab 3" %}} {{% tab title="Outer Tab 3" %}}
This tab contains vertical nested tabs: This tab contains vertical nested tabs:
{{< tabs type="card" vertical=true >}} {{< tabs type="card" placement="left" >}}
{{% tab title="Vertical A" %}} {{% tab title="Vertical A" %}}
Content for vertical nested tab A. Content for vertical nested tab A.
@@ -76,7 +76,6 @@ tab-container {
&[placement='left'], &[placement='left'],
&[placement='right'] { &[placement='right'] {
max-width: 100%; max-width: 100%;
overflow: hidden;
&::part(tablist-wrapper) { &::part(tablist-wrapper) {
min-height: 100px; min-height: 100px;
+1 -1
View File
@@ -3,7 +3,7 @@
{{- if $password -}} {{- if $password -}}
{{- /* Content */ -}} {{- /* Content */ -}}
{{- $content := .Inner | .Page.RenderString -}} {{- $content := .Inner | strings.TrimSpace | .Page.RenderString -}}
{{- /* Content Encryption */ -}} {{- /* Content Encryption */ -}}
{{- dict "Content" $content "Password" $password "Message" $message "IsPartial" true "Page" .Page | partial "plugin/fixit-encryptor.html" -}} {{- dict "Content" $content "Password" $password "Message" $message "IsPartial" true "Page" .Page | partial "plugin/fixit-encryptor.html" -}}
{{- .Page.Store.Set "hasEncryptor" true -}} {{- .Page.Store.Set "hasEncryptor" true -}}
+1 -4
View File
@@ -9,10 +9,7 @@
{{- $id := dict "Page" .Page | partial "function/id.html" -}} {{- $id := dict "Page" .Page | partial "function/id.html" -}}
{{- $title := .Get "title" -}} {{- $title := .Get "title" -}}
{{- .Parent.Store.Add "tabs" (slice (dict "title" $title "id" $id)) -}} {{- .Parent.Store.Add "tabs" (slice (dict "title" $title "id" $id)) -}}
{{- $content := trim .Inner "\r\n" -}}
{{- /* Remove p tags around complete tab-container structure */ -}}
{{- $content = $content | replaceRE `<p>(<tab-container[^>]*>[\s\S]*?</button>)</p>` "$1" -}}
{{- /* Tab panel */ -}} {{- /* Tab panel */ -}}
<div role="tabpanel" aria-labelledby="tab-{{ $id }}" class="tab-panel">{{ $content | safeHTML }}</div> <div role="tabpanel" aria-labelledby="tab-{{ $id }}" class="tab-panel">{{ .Inner | strings.TrimSpace | .Page.RenderString }}</div>
{{- /* EOF */ -}} {{- /* EOF */ -}}
+10 -8
View File
@@ -40,14 +40,16 @@
{{- end -}} {{- end -}}
{{- /* Tabs Container */ -}} {{- /* Tabs Container */ -}}
<tab-container default-tab="{{ $defaultTab }}" placement="{{ $placement }}"{{ with $type }} type="{{ . }}"{{ end }}> <div class="shortcode-tabs">
{{- range $index, $tab := $tabs -}} <tab-container default-tab="{{ $defaultTab }}" placement="{{ $placement }}"{{ with $type }} type="{{ . }}"{{ end }}>
{{- $title := $tab.title | default (printf "Untitled%v" $index) -}} {{- range $index, $tab := $tabs -}}
{{- $id := $tab.id -}} {{- $title := $tab.title | default (printf "Untitled%v" $index) -}}
<button class="tab-button" type="button" role="tab" id="tab-{{ $id }}" aria-selected="{{ eq $index $defaultTab }}">{{ $title | $.Page.RenderString }}</button> {{- $id := $tab.id -}}
{{- end -}} <button class="tab-button" type="button" role="tab" id="tab-{{ $id }}" aria-selected="{{ eq $index $defaultTab }}">{{ $title | $.Page.RenderString }}</button>
{{- .Inner -}} {{- end -}}
</tab-container> {{- .Inner | strings.TrimSpace | .Page.RenderString -}}
</tab-container>
</div>
{{- .Page.Store.Set "hasTabs" true -}} {{- .Page.Store.Set "hasTabs" true -}}