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

@ -19,7 +19,7 @@
{{- $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" . }}
@ -27,7 +27,7 @@
{{- end }}
{{- define "childs" }}
{{ $page := .page }}
{{- $page := .page }}
{{- range .menu }}
{{- $hidden := and (or (.Params.hidden) (eq .Title "")) (not $.showhidden) }}
{{- if not $hidden }}
@ -35,45 +35,28 @@
{{- 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 -}}
<p>{{ . }}</p>
{{- end }}
{{- end }}
{{ (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 }}
{{- if $.description }}
{{- with or .Description .Summary -}}
<p>{{ . }}</p>
{{- end }}
{{- end }}
{{ (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 }}
{{- if $.description }}
{{ (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 }}
{{- 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" }}
{{- (printf "</%s>" $.containerstyle)|safeHTML }}
{{- end }}
{{- end }}
{{- if not .IsHome }}
{{- if eq $.style "li" }}
{{- (printf "</%s>" $.style)|safeHTML -}}

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,15 +45,17 @@
{{- if and $icon (not (findRE ".*?\\bfa-\\w.*?" $icon)) }}
{{- $icon = printf "fa-fw fas fa-%s" $icon }}
{{- end }}
{{- if $hasContent }}
{{- $tabs = $tabs | append (dict
"color" $color
"content" .content
"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 "" }}
{{- $style = .style | default (cond (ne $color "") "filled" "initial") }}
@ -76,6 +83,7 @@
{{- $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>
@ -95,10 +103,11 @@
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 }}
</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")