Skip to content

Commit 6ec1cd8

Browse files
authored
Add 'align' option to figure shortcode (adityatelange#256)
Usage: {{< figure align=center src="image.jpg" >}} Parameter values: - 'center': align image and captions to center of page - anything else neglected * Appends "#center" to the image's URL in order to utilize existing CSS rules for centering images.
1 parent 5b1591b commit 6ec1cd8

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

assets/css/post-single.css

+4
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@
242242
margin: auto
243243
}
244244

245+
.post-content figure.align-center {
246+
text-align: center;
247+
}
248+
245249
.post-content figure > figcaption {
246250
color: var(--primary);
247251
font-size: 16px;

layouts/shortcodes/figure.html

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
<figure{{ with .Get "class" }} class="{{ . }}"{{ end }}>
1+
<figure{{ if or (.Get "class") (eq (.Get "align") "center") }} class="
2+
{{- if eq (.Get "align") "center" }}align-center {{ end }}
3+
{{- with .Get "class" }}{{ . }}{{- end }}"
4+
{{- end -}}>
25
{{- if .Get "link" -}}
36
<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>
47
{{- end }}
5-
<img src="{{ .Get "src" }}"
8+
<img src="{{ .Get "src" }}{{- if eq (.Get "align") "center" }}#center{{- end }}"
69
{{- if or (.Get "alt") (.Get "caption") }}
710
alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify| plainify }}{{ end }}"
811
{{- end -}}

0 commit comments

Comments
 (0)