shortcodes: fix whitespace issues #907

This commit is contained in:
Sören Weber 2024-09-05 20:02:38 +02:00
parent 50165ddc93
commit 33f9cb6e78
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
15 changed files with 95 additions and 97 deletions

View file

@ -15,8 +15,7 @@
"title" $alerttitle
"expanded" (cond (eq $alertsign "+") true (cond (eq $alertsign "-") false ""))
) }}
{{- else }}
{{ else -}}
<blockquote>
{{- $text | safeHTML }}
</blockquote>
{{- end }}
{{ $text | safeHTML }}</blockquote>
{{ end }}

View file

@ -5,7 +5,6 @@
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'attachments' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#5180" $page.File.Filename }}
{{- end }}
{{- $color := .color | default "" }}
{{- $content := .content }}
{{- $style := .style | default "default" }}
{{- if and (not $color) (eq (len $color) 0) }}
{{- $style = .style | default "transparent" }}
@ -46,7 +45,7 @@
{{- with $page }}
{{- if ne .BundleType "leaf" }}
{{- warnf "%q: UNSUPPORTED usage of 'attachments' shortcode found while using Hugo >= 0.112.0, use a leaf bundle instead; see https://mcshelby.github.io/hugo-theme-relearn/shortcodes/attachments/index.html#single-language" $page.File.Filename }}
{{- end }}
{{- end -}}
<div class="box attachments cstyle {{ $style }}"{{ if $color }} style="--VARIABLE-BOX-color: {{ $color }};"{{ end }}>
<div class="box-label">{{ if $icon }}<i class="{{ $icon }}"></i>{{ end }}{{ if and $icon $title }} {{ end }}{{ $title | .RenderString }}</div>
<ul class="box-content attachments-files">
@ -82,6 +81,5 @@
{{- end }}
{{- end }}
</ul>
{{- $content }}
</div>
{{- end }}

View file

@ -5,80 +5,63 @@
{{- end }}
{{- $showhidden := .showhidden | default false }}
{{- if eq (printf "%T" $showhidden) "string" }}
{{- $showhidden = (eq $showhidden "true") }}
{{- $showhidden = (eq $showhidden "true") }}
{{- end }}
{{- $style := .style | default "li" }}
{{- $depth := .depth | default 1 }}
{{- $withDescription := .description | default false }}
{{- if eq (printf "%T" $withDescription) "string" }}
{{- $withDescription = (eq $withDescription "true") }}
{{- $withDescription = (eq $withDescription "true") }}
{{- end }}
{{- $sortTerm := .sort | lower }}
{{- $containerstyle := .containerstyle | default "ul" }}
{{- if( and (not (eq $style "li") ) (eq $containerstyle "ul" ) ) }}
{{- $containerstyle = "div" }}
{{- $containerstyle = "div" }}
{{- end }}
{{- with $page }}
{{- with $page -}}
{{ (printf "<%s class=\"children children-%s children-sort-%s\">" $containerstyle $style $sortTerm)|safeHTML }}
{{- $pages := partial "pageHelper/pagesBy.html" (dict "page" . "by" $sortTerm) }}
{{- template "childs" dict "menu" $pages "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm "page" . }}
{{- $pages := partial "pageHelper/pagesBy.html" (dict "page" . "by" $sortTerm) }}
{{- template "childs" dict "menu" $pages "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm "page" . }}
{{ (printf "</%s>" $containerstyle)|safeHTML }}
{{- end }}
{{- define "childs" }}
{{ $page := .page }}
{{- range .menu }}
{{- $hidden := and (or (.Params.hidden) (eq .Title "")) (not $.showhidden) }}
{{- if not $hidden }}
{{- if not .IsHome }}
{{- if hasPrefix $.style "h" }}
{{- $num := sub ( int (trim $.style "h") ) 1 }}
{{- $numn := add $num $.count }}
{{ (printf "<h%d>" $numn)|safeHTML }}{{ if .RelPermalink }}<a href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" .) }}">{{ .Title }}</a>{{ else }}<span>{{ .Title }}</span>{{ end }}{{ (printf "</h%d>" $numn)|safeHTML }}
{{- if $.description }}
{{- with or .Description .Summary -}}
{{- $page := .page }}
{{- range .menu }}
{{- $hidden := and (or (.Params.hidden) (eq .Title "")) (not $.showhidden) }}
{{- if not $hidden }}
{{- if not .IsHome }}
{{- if hasPrefix $.style "h" }}
{{- $num := sub ( int (trim $.style "h") ) 1 }}
{{- $numn := add $num $.count }}
{{ (printf " <h%d>" $numn)|safeHTML }}{{ if .RelPermalink }}<a href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" .) }}">{{ .Title }}</a>{{ else }}<span>{{ .Title }}</span>{{ end }}{{ (printf "</h%d>" $numn)|safeHTML }}
{{- else if eq $.style "li" }}
{{ (printf " <%s>" $.style)|safeHTML }}{{ if .RelPermalink }}<a href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" .) }}">{{ .Title }}</a>{{ else }}<span>{{ .Title }}</span>{{ end }}
{{- else }}
{{ (printf " <%s>" $.style)|safeHTML }}{{ if .RelPermalink }}<a href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" .) }}">{{ .Title }}</a>{{ else }}<span>{{ .Title }}</span>{{ end }}{{ (printf "</%s>" $.style)|safeHTML }}
{{- end }}
{{- if $.description }}
{{- with or .Description .Summary -}}
<p>{{ . }}</p>
{{- end }}
{{- end }}
{{- else if eq $.style "li" }}
{{ (printf "<%s>" $.style)|safeHTML }}{{ if .RelPermalink }}<a href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" .) }}">{{ .Title }}</a>{{ else }}<span>{{ .Title }}</span>{{ end }}
{{- if $.description }}
{{- with or .Description .Summary -}}
<p>{{ . }}</p>
{{- end }}
{{- end }}
{{- else }}
{{ (printf "<%s>" $.style)|safeHTML }}{{ if .RelPermalink }}<a href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" .) }}">{{ .Title }}</a>{{ else }}<span>{{ .Title }}</span>{{ end }}{{ (printf "</%s>" $.style)|safeHTML }}
{{- if $.description }}
{{- with or .Description .Summary -}}
<p>{{ . }}</p>
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- if lt $.count $.depth }}
{{- if eq $.style "li" }}
{{- end }}
{{- end }}
{{- end }}
{{- if lt $.count $.depth }}
{{- if eq $.style "li" }}
{{- (printf "<%s>" $.containerstyle)|safeHTML }}
{{- end }}
{{- $pages := partial "pageHelper/pagesBy.html" (dict "page" . "by" $.sortTerm) }}
{{- template "childs" dict "menu" $pages "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm "page" $page }}
{{- if eq $.style "li" }}
{{- end }}
{{- $pages := partial "pageHelper/pagesBy.html" (dict "page" . "by" $.sortTerm) }}
{{- template "childs" dict "menu" $pages "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm "page" $page }}
{{- if eq $.style "li" }}
{{- (printf "</%s>" $.containerstyle)|safeHTML }}
{{- end }}
{{- end }}
{{- if not .IsHome }}
{{- if eq $.style "li" }}
{{- end }}
{{- end }}
{{- if not .IsHome }}
{{- if eq $.style "li" }}
{{- (printf "</%s>" $.style)|safeHTML -}}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

View file

@ -3,7 +3,11 @@
{{- $page = .context }}
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'expand' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#5180" $page.File.Filename }}
{{- end }}
{{- $content := .content }}
{{- $content := trim .content "\n\r\t " }}
{{- $hasContent := ne (strings.TrimLeft "<p>" $content) "" }}
{{- if not (hasPrefix $content "<") }}
{{- $content = printf "<p>\n%s" $content }}
{{- end }}
{{- $title := .title | default (T "Expand-title") }}
{{- $title = trim $title " " }}
{{- $expanded := .expanded | default false }}
@ -16,14 +20,16 @@
{{- end }}
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $page) .id }}
{{- with $page }}
{{- if $hasContent -}}
<div class="expand">
<input type="checkbox" id="R-expand-{{ $id }}" aria-controls="R-expandcontent-{{ $id }}" {{ if $expanded }} checked{{ end }}>
<input type="checkbox" id="R-expand-{{ $id }}" aria-controls="R-expandcontent-{{ $id }}"{{ if $expanded }} checked{{ end }}>
<label class="expand-label" for="R-expand-{{ $id }}">
<i class="expander-icon fa-fw fas fa-chevron-down"></i>
<i class="expander-icon fa-fw fas fa-chevron-right"></i> {{ $title | .RenderString }}
</label>
<div id="R-expandcontent-{{ $id }}" class="expand-content">
{{ if ne "<" (substr (strings.TrimLeft "\n\r\t " $content) 0 1) }}<p>{{ end }}<!-- we add a DOM element here if there is none to make collapsing marings work -->
{{ $content | safeHTML }}</div><!-- no line break allowed here because of awkward behavior of Hugo 110 or this theme when tag shortcode is called standalone outside of tags shortcode ? -->
{{ $content | safeHTML }}
</div>
</div>
{{- end }}
{{- end }}

View file

@ -106,4 +106,6 @@
)}}
{{- else }}
{{- $content | safeHTML }}
{{- if and (not $hl_inline) (not (hasSuffix $content "\n")) }}
{{ end }}
{{- end }}

View file

@ -21,7 +21,7 @@
{{- $attributes = merge $attributes (dict "class" (delimit (append (index $attributes "class" | default slice) "math" slice) " ")) }}
{{- $attributes = merge $attributes (dict "class" (delimit (append (index $attributes "class" | default slice) (printf "align-%s" $align) slice) " ")) }}
{{- with $page }}
{{- with $page -}}
<span
{{- range $k, $v := $attributes }}
{{- if $v }}

View file

@ -36,7 +36,7 @@
{{- $attributes = merge $attributes (dict "class" (delimit (append (index $attributes "class" | default slice) (printf "align-%s" $align) slice) " ")) }}
{{- $attributes = merge $attributes (dict "class" (delimit (append (index $attributes "class" | default slice) (printf "%s" (cond $zoom "zoomable" "")) slice) " ")) }}
{{- with $page }}
{{- with $page -}}
<pre
{{- range $k, $v := $attributes }}
{{- if $v }}

View file

@ -4,8 +4,11 @@
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'notice' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#5180" $page.File.Filename }}
{{- end }}
{{- $color := .color | default "" }}
{{- $content := .content }}
{{- $hasContent := ne (strings.TrimLeft "<p>" (trim $content "\n\r\t ")) "" }}
{{- $content := trim .content "\n\r\t " }}
{{- $hasContent := ne (strings.TrimLeft "<p>" $content) "" }}
{{- if not (hasPrefix $content "<") }}
{{- $content = printf "<p>\n%s" $content }}
{{- end }}
{{- $style := .style | default "default" }}
{{- $title := .title }}
{{- if not $title }}
@ -44,10 +47,10 @@
{{- end }}
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $page) .id }}
{{- with $page }}
{{- if or $icon $title $hasContent }}
{{- if or $icon $title $hasContent -}}
<div class="{{ if $expander }}expand {{ end }}box notices cstyle {{ $style }}"{{ if $color }} style="--VARIABLE-BOX-color: {{ $color }};"{{ end }}>
{{- if $expander }}
<input type="checkbox" id="R-expand-{{ $id }}" aria-controls="R-expandcontent-{{ $id }}" {{ if $expanded }} checked{{ end }}>
<input type="checkbox" id="R-expand-{{ $id }}" aria-controls="R-expandcontent-{{ $id }}"{{ if $expanded }} checked{{ end }}>
<label class="expand-label box-label" for="R-expand-{{ $id }}">
<i class="expander-icon fa-fw fas fa-chevron-down"></i>
<i class="expander-icon fa-fw fas fa-chevron-right"></i> {{ if $icon }}<i class="{{ $icon }}"></i>{{ end }}{{ if and $icon $title }} {{ end }}{{ $title | .RenderString }}
@ -60,8 +63,8 @@
{{- end }}
{{- if $hasContent }}
<div{{ if $expander }} id="R-expandcontent-{{ $id }}"{{ end }} class="{{ if $expander }}expand-content {{ end }}box-content">
{{ if ne "<" (substr (strings.TrimLeft "\n\r\t " $content) 0 1) }}<p>{{ end }}<!-- we add a DOM element here if there is none to make collapsing marings work -->
{{ $content | safeHTML }}</div><!-- no line break allowed here because of awkward behavior of Hugo 110 or this theme when tag shortcode is called standalone outside of tags shortcode ? -->
{{ $content | safeHTML }}
</div>
{{- end }}
</div>
{{- end }}

View file

@ -24,7 +24,7 @@
{{- end }}
{{- end }}
{{- end }}
{{- with $page }}
{{- with $page -}}
<div class="sc-openapi-wrapper is-loading helper-loading-container">
<div
class="sc-openapi-container"

View file

@ -4,7 +4,6 @@
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'resources' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#5180" $page.File.Filename }}
{{- end }}
{{- $color := .color | default "" }}
{{- $content := .content }}
{{- $style := .style | default "default" }}
{{- if and (not $color) (eq (len $color) 0) }}
{{- $style = .style | default "transparent" }}
@ -38,7 +37,7 @@
{{- with $page }}
{{- if eq .BundleType "" }}
{{- warnf "%q: UNSUPPORTED usage of 'resources' shortcode found, use a page bundle instead; see https://mcshelby.github.io/hugo-theme-relearn/shortcodes/resources" $page.File.Filename }}
{{- end }}
{{- end -}}
<div class="box attachments cstyle {{ $style }}"{{ if $color }} style="--VARIABLE-BOX-color: {{ $color }};"{{ end }}>
<div class="box-label">{{ if $icon }}<i class="{{ $icon }}"></i>{{ end }}{{ if and $icon $title }} {{ end }}{{ $title | .RenderString }}</div>
<ul class="box-content attachments-files">
@ -59,6 +58,5 @@
{{- end }}
{{- end }}
</ul>
{{- $content }}
</div>
{{- end }}

View file

@ -16,6 +16,11 @@
{{- end }}
{{- with $tab }}
{{- $color := .color | default $color | default "" }}
{{- $content := trim .content "\n\r\t " }}
{{- $hasContent := ne (strings.TrimLeft "<p>" $content) "" }}
{{- if not (hasPrefix $content "<") }}
{{- $content = printf "<p>\n%s" $content }}
{{- end }}
{{- $style := .style | default $style | default (cond (ne $color "") "filled" "initial") }}
{{- $title := .title }}
{{- if not $title }}
@ -40,14 +45,16 @@
{{- if and $icon (not (findRE ".*?\\bfa-\\w.*?" $icon)) }}
{{- $icon = printf "fa-fw fas fa-%s" $icon }}
{{- end }}
{{- $tabs = $tabs | append (dict
"color" $color
"content" .content
"icon" $icon
"itemid" (printf "%s%s" ($title | $page.RenderString | plainify | anchorize) ($icon | plainify | anchorize))
"style" $style
"title" $title
) }}
{{- if $hasContent }}
{{- $tabs = $tabs | append (dict
"color" $color
"content" $content
"icon" $icon
"itemid" (printf "%s%s" ($title | $page.RenderString | plainify | anchorize) ($icon | plainify | anchorize))
"style" $style
"title" $title
) }}
{{- end }}
{{- end }}
{{- end }}
{{- $color = .color | default "" }}
@ -76,10 +83,11 @@
{{- $icon = printf "fa-fw fas fa-%s" $icon }}
{{- end }}
{{- with $page }}
{{- if len $tabs -}}
<div class="tab-panel" data-tab-group="{{ $groupid }}">
<div class="tab-nav">
<div class="tab-nav-title">{{ if $icon }}<i class="{{ $icon }}"></i>{{ end }}{{ if and $icon $title }} {{ end }}{{ $title | $page.RenderString }}{{ if (not $title) }}&#8203;{{ end }}</div>
{{- range $idx, $tab := $tabs }}
{{- range $idx, $tab := $tabs }}
<button
data-tab-item="{{ .itemid }}"
class="tab-nav-button tab-panel-style cstyle {{ .style }}{{ cond (eq $idx 0) " active" ""}}"{{ if .color }} style="--VARIABLE-BOX-color: {{ .color }};"{{ end }}{{ if eq $idx 0 }} tabindex="-1"{{ end }}
@ -87,18 +95,19 @@
>
<span class="tab-nav-text">{{ if .icon }}<i class="{{ .icon }}"></i>{{ end }}{{ if and .icon .title }} {{ end }}{{ .title | $page.RenderString }}{{ if (not .title) }}&#8203;{{ end }}</span>
</button>
{{- end }}
{{- end }}
</div>
<div class="tab-content-container">
{{- range $idx, $tab := $tabs }}
{{- range $idx, $tab := $tabs }}
<div
data-tab-item="{{ .itemid }}"
class="tab-content tab-panel-style cstyle {{ .style }}{{ cond (eq $idx 0) " active" ""}}"{{ if .color }} style="--VARIABLE-BOX-color: {{ .color }};"{{ end }}>
<div class="tab-content-text">
{{ if ne "<" (substr (strings.TrimLeft "\n\r\t " .content) 0 1) }}<p>{{ end }}<!-- we add a DOM element here if there is none to make collapsing marings work -->
{{ .content | safeHTML }}</div><!-- no line break allowed here because of awkward behavior of Hugo 110 or this theme when tag shortcode is called standalone outside of tags shortcode ? -->
{{ .content | safeHTML }}
</div>
</div>
{{- end }}
{{- end }}
</div>
</div>
{{- end }}
{{- end }}

View file

@ -1,8 +1,8 @@
{{- $_hugo_config := `{ "version": 1 }` }}
{{- $unused := .Inner }}
{{- partial "shortcodes/attachments.html" (dict
"page" .Page
"color" (.Get "color")
"content" .Inner
"icon" (.Get "icon")
"pattern" (.Get "pattern")
"style" (.Get "style")

View file

@ -1,8 +1,8 @@
{{- $_hugo_config := `{ "version": 1 }` }}
{{- $unused := .Inner }}
{{- partial "shortcodes/resources.html" (dict
"page" .Page
"color" (.Get "color")
"content" .Inner
"icon" (.Get "icon")
"pattern" (.Get "pattern")
"style" (.Get "style")