Skip to content

Commit

Permalink
Shortcode 'card': Use Hugo's native support for processing HTML & mar…
Browse files Browse the repository at this point in the history
…kdown (#906)
  • Loading branch information
deining authored and chalin committed May 4, 2023
1 parent 38eb6ed commit 6f696fd
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 88 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ For a list of issues targeted for the next release, see the [23Q1][] milestone.
- `blocks/section`: **default** and accepted values of the `type` argument
have changed! For details see [blocks/section] ([#1472]).

- **[Adaptation of shortcode 'cardpane'][1376]. renamed CSS class `td-card-deck`
to `td-card-group`.
- **[Adaptation of shortcodes for diplay of cards (#1376)][1376]:
- shortcode `cardpane`: renamed CSS class `td-card-deck` to `td-card-group`.
- shortcode `card`, `card-code`: markup of inner content (html/markdown)
now depends on the syntax of the calling shortcode, not on extension
of page file any more [#906][906].
- shortcode `card-code` is now deprecated, use shortcode `card` with named
parameter `code=true` instead.

**Other changes**:

Expand Down
24 changes: 10 additions & 14 deletions layouts/shortcodes/card-code.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
{{ warnf `shortcode 'card-code' is deprecated: use shortcode 'card' with named parameter 'code=true' instead.` -}}
{{ $lang := default "" ($.Get "lang") -}}
{{ $highlight := default "" ($.Get "highlight") -}}

<div class="td-card card border me-4">
{{ $lang := "" }}
{{ with $.Get "lang" }}
{{ $lang = $.Get "lang" }}
{{ end }}
{{ $highlight := "" }}
{{ with $.Get "highlight" }}
{{ $highlight = $.Get "highlight" }}
{{ end }}
{{- with $.Get "header" -}}
{{ with $.Get "header" -}}
<div class="card-header bg-white">
{{- $.Get "header" | markdownify -}}
{{ . | markdownify -}}
</div>
{{end}}
{{ end -}}
<div class="card-body code p-0 m-0">
{{ with $.Inner }}
{{- highlight $.Inner $lang $highlight -}}
{{ end }}
{{ with $.Inner -}}
{{ highlight . $lang $highlight -}}
{{ end -}}
</div>
</div>
72 changes: 35 additions & 37 deletions layouts/shortcodes/card.html
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
{{/* Check parameter type */ -}}
{{ $code := false -}}
{{ with .Get "code" -}}
{{ $type := printf "%T" . -}}
{{ if ne $type "bool" -}}
{{ errorf `shortcode 'card': boolean value expected for parameter 'code', but got %s` $type -}}
{{ else }}
{{ $code = . -}}
{{ end -}}
{{ end -}}

{{ $lang := default "" (.Get "lang") -}}
{{ $highlight := default "" (.Get "highlight") -}}

<div class="td-card card border me-4">
{{ with $.Get "header" }}
<div class="card-header">
{{ if eq $.Page.File.Ext "md" }}
{{ $.Get "header" | markdownify }}
{{ else }}
{{ $.Get "header" | htmlUnescape | safeHTML }}
{{ end }}
{{ with $.Get "header" -}}
<div class="card-header{{- cond $code " bg-white" "" -}}">
{{ . | markdownify }}
</div>
{{ end }}
<div class="card-body">
{{ with $.Get "title" }}
{{ end -}}
<div class="card-body{{- cond $code " code p-0 m-0" "" -}}">
{{ with $.Get "title" -}}
<h5 class="card-title">
{{ if eq $.Page.File.Ext "md" }}
{{ $.Get "title" | markdownify }}
{{ else }}
{{ $.Get "title" | htmlUnescape | safeHTML }}
{{ end }}
{{ . | markdownify -}}
</h5>
{{ end }}
{{ with $.Get "subtitle" }}
{{ end -}}
{{ with $.Get "subtitle" -}}
<h6 class="card-title ms-2 text-muted">
{{ if eq $.Page.File.Ext "md" }}
{{ $.Get "subtitle" | markdownify }}
{{ else }}
{{ $.Get "subtitle" | htmlUnescape | safeHTML }}
{{ end }}
{{ . | markdownify -}}
</h6>
{{ end }}
{{ with $.Inner }}
{{ end -}}
{{ with $.Inner -}}
{{ if $code -}}
{{ highlight . $lang $highlight -}}
{{ else -}}
<p class="card-text">
{{ if eq $.Page.File.Ext "md" }}
{{ $.Inner | markdownify }}
{{ else }}
{{ $.Inner | htmlUnescape | safeHTML }}
{{ end }}
{{ . -}}
</p>
{{ end }}
{{ end -}}
{{ end -}}
</div>
{{ with $.Get "footer" }}
{{ with $.Get "footer" -}}
<div class="card-footer">
{{ if eq $.Page.File.Ext "md" }}
{{ $.Get "footer" | markdownify }}
{{ else }}
{{ $.Get "footer" | htmlUnescape | safeHTML }}
{{ end }}
{{ . | markdownify -}}
</div>
{{ end }}
{{ end -}}
</div>
Loading

0 comments on commit 6f696fd

Please sign in to comment.