You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.0 KiB
HTML

{{ $params := . }}
{{ $caption := $params.caption | markdownify }}
{{ $compact := $params.compact }}
{{ $content := $params.content | markdownify }}
{{ $float := $params.float }}
{{ $gap := $params.gap }}
{{ $height := $params.height }}
{{ $horizontal := $params.horizontal | default "center" }}
{{ $maxheight := $params.maxheight }}
{{ $maxwidth := $params.maxwidth }}
{{ $number := $params.number }}
{{ $numbered := $params.numbered }}
{{ $vertical := $params.vertical | default "center" }}
{{ $width := $params.width }}
{{ $heightish := or $maxheight $height }}
{{ $showcaption := $caption }}
{{ $sidemargin := "" }}
{{ $style := slice }}
{{ $table := false }}
{{ $widthish := or $maxwidth $width }}
{{ if and $caption (or $compact $float) }}
{{ $table = true }}
{{ end }}
{{ if $height }}
{{ $style = $style | append (printf "height: %v" $height) }}
{{ end }}
{{ if $maxheight }}
{{ $style = $style | append (printf "max-height: %v" $maxheight) }}
{{ end }}
{{ if $maxwidth }}
{{ $style = $style | append (printf "max-width: %v" $maxwidth) }}
{{ end }}
{{ if $width }}
{{ $style = $style | append (printf "width: %v" $width) }}
{{ end }}
{{ $style = delimit ($style | sort | uniq) "; " }}
{{ if $float }}
{{ if eq $float "start" }}
{{ $sidemargin = "me-4" }}
{{ else if eq $float "end" }}
{{ $sidemargin = "ms-4" }}
{{ else }}
{{ errorf "invalid float: %q" $float }}
{{ end }}
{{ end }}
{{ if $caption }}
{{ if $number }}
{{ $caption = printf "%v %v: %v" (i18n "paige_figure") $number $caption }}
{{ end }}
{{ else }}
{{ if $number }}
{{ $caption = printf "%v %v" (i18n "paige_figure") $number }}
{{ $showcaption = true }}
{{ else if $numbered }}
{{ $showcaption = true }}
{{ end }}
{{ end }}
<figure class="{{ if $widthish }} d-flex {{ end }} {{ with $float }} float-{{ . }} {{ end }} {{ if $widthish }} justify-content-{{ $horizontal }} {{ end }} {{ if $compact }} mb-0 {{ end }} {{ if $float }} {{ $sidemargin }} {{ end }} paige-figure {{ if $numbered }} paige-figure-numbered {{ end }}" {{ if and $float $style }} style="{{ $style | safeCSS }}" {{ end }}>
{{ if or $heightish $widthish (and (not $float) $style) }}
<div {{ if or $heightish $widthish }} class="{{ if $height }} d-flex flex-column justify-content-{{ $vertical }} {{ end }} overflow-auto" {{ end }} {{ if and (not $float) $style }} style="{{ $style | safeCSS }}" {{ end }}>
{{ end }}
{{ if $table }}
<div class="d-table">
{{ end }}
<div class="text-{{ $horizontal }}">{{ $content }}</div>
{{ if $showcaption }}
<figcaption class="figure-caption {{ with $gap }} mt-{{ . }} {{ end }} text-{{ $horizontal }}" {{ if $table }} style="caption-side: bottom; display: table-caption" {{ end }}>{{ $caption }}</figcaption>
{{ end }}
{{ if $table }}
</div>
{{ end }}
{{ if or $heightish $widthish (and (not $float) $style) }}
</div>
{{ end }}
</figure>