Skip to content

Commit 0bb187f

Browse files
Add image support for dark and light themes (#599)
* Add image support for dark and light themes * Minor fix * Display data-theme images only once the theme is defined * Document light/dark image display CSS --------- Co-authored-by: Stefan van der Walt <stefanv@berkeley.edu>
1 parent 4543388 commit 0bb187f

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

assets/theme-css/styles.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,29 @@ body {
1212
text-align: center !important;
1313
}
1414

15+
/* Handle selective display depending on light/dark theme */
16+
17+
html:not([data-theme]) {
18+
.light-theme {
19+
display: none;
20+
}
21+
.dark-theme {
22+
display: none;
23+
}
24+
}
25+
26+
html[data-theme="dark"] {
27+
.light-theme {
28+
display: none;
29+
}
30+
}
31+
32+
html[data-theme="light"] {
33+
.dark-theme {
34+
display: none;
35+
}
36+
}
37+
1538
img {
1639
max-width: 100%;
1740
}
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
1-
{{ if .data.target -}}<a href="{{ .data.target }}">{{ end -}}
1+
{{- if .data.src }}
2+
{{- if .data.target -}}<a href="{{ .data.target }}">{{ end -}}
23
<img src="{{ .data.src }}" alt="{{ .data.alt }}"
34
{{- with .data.align }} class="align-{{ . }}"{{ end -}}
45
{{- with .data.width }} width="{{ . }}"{{ end -}}
56
{{- with .data.height }} height="{{ . }}"{{ end -}}
67
{{- with .data.loading }} loading="{{ . }}"{{ end -}}
78
>
89
{{- if .data.target }}</a>{{ end -}}
10+
{{- else if ( and .data.lightsrc .data.darksrc ) }}
11+
{{- with .data.lightsrc }}
12+
{{ if $.data.target -}}<a href="{{ $.data.target }}">{{ end -}}
13+
<img src="{{ . }}" class="light-theme" alt="{{ $.data.alt }}"
14+
{{- with $.data.align }} class="align-{{ . }}"{{ end -}}
15+
{{- with $.data.width }} width="{{ . }}"{{ end -}}
16+
{{- with $.data.height }} height="{{ . }}"{{ end -}}
17+
{{- with $.data.loading }} loading="{{ . }}"{{ end -}}
18+
>
19+
{{- if $.data.target }}</a>{{ end -}}
20+
{{- end }}
21+
{{- with .data.darksrc }}
22+
{{ if $.data.target -}}<a href="{{ $.data.target }}">{{ end -}}
23+
<img src="{{ . }}" class="dark-theme" alt="{{ $.data.alt }}"
24+
{{- with $.data.align }} class="align-{{ . }}"{{ end -}}
25+
{{- with $.data.width }} width="{{ . }}"{{ end -}}
26+
{{- with $.data.height }} height="{{ . }}"{{ end -}}
27+
{{- with $.data.loading }} loading="{{ . }}"{{ end -}}
28+
>
29+
{{- if $.data.target }}</a>{{ end -}}
30+
{{- end }}
31+
{{ end }}
32+
33+
{{ define "partials/_elements/inlineimage.html" }}
34+
{{ end }}

0 commit comments

Comments
 (0)