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 committed Feb 14, 2023
1 parent 8d04b00 commit b660d93
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 89 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ For a list of issues targeted for the next release, see the [23Q1][] milestone.
- Dropped `$primary-light`.
- Dropped `color-diff()`.

- **[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**:

- Non-breaking changes that result from the Bootstrap v5 upgrade:
- Draw.io diagram edit button: replace custom colors by BS's outline primary.

[470]: https://github.com/google/docsy/issues/470
[906]: https://github.com/google/docsy/issues/906
[bsv5mig]: https://getbootstrap.com/docs/5.2/migration/

## [0.6.0][]
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 b660d93

Please sign in to comment.