Skip to content

Commit 1fba82e

Browse files
committed
Add figure shortcode with PST styling
1 parent 1f89ba9 commit 1fba82e

File tree

5 files changed

+80
-12
lines changed

5 files changed

+80
-12
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
figure {
2+
a.headerlink {
3+
// So that header link doesn't push caption to be off-center.
4+
position: absolute;
5+
font-size: inherit;
6+
}
7+
// Default headerlink hover doesn't trigger on figures
8+
&:hover a.headerlink {
9+
visibility: visible;
10+
}
11+
12+
figcaption {
13+
font-family: var(--pst-font-family-heading);
14+
font-weight: var(--pst-font-weight-caption);
15+
color: var(--pst-color-text-muted);
16+
margin-left: auto;
17+
margin-right: auto;
18+
19+
table.table {
20+
width: fit-content;
21+
margin-left: auto;
22+
margin-right: auto;
23+
}
24+
}
25+
}

assets/theme-css/pst/pydata-sphinx-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
@import "./content/admonitions";
5353
//@import "./content/api";
5454
@import "./content/code";
55-
//@import "./content/figures";
55+
@import "./content/figures";
5656
//@import "./content/footnotes";
5757
//@import "./content/hacks";
5858
@import "./content/lists";

doc/content/features.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,6 @@ By default, `javaScript` points to the server at
116116
`https://views.scientific-python.org`. Contact the Scientific
117117
Python team to have your analytics hosted there.
118118

119-
## Figures
120-
121-
{{< figure src="https://source.unsplash.com/200x200/daily?cute+puppy"
122-
alt="Cute puppies"
123-
target="https://unsplash.com/"
124-
caption="Cute puppies"
125-
loading="lazy"
126-
height=200
127-
width=200 >}}
128-
129119
## Icons
130120

131121
You can add custom icons (for use in, e.g., the footer) by downloading Material-UI SVGs from [Google Fonts](https://fonts.google.com/icons) to the `/assets/icons` directory.

layouts/partials/_elements/image.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if .data.target -}}<a href="{{ .data.target }}">{{- end -}}
1+
{{ if .data.target -}}<a href="{{ .data.target }}">{{ end -}}
22
<img src="{{ .data.src }}" alt="{{ .data.alt }}"
33
{{- with .data.align }} class="align-{{ . }}"{{ end -}}
44
{{- with .data.width }} width="{{ . }}"{{ end -}}

layouts/shortcodes/figure.html

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{{/*
2+
3+
doc: Figures
4+
5+
{{< figure >}}
6+
src = 'https://source.unsplash.com/200x200/daily?cute+puppy'
7+
alt = 'Cute puppies'
8+
height = 200
9+
width = 200
10+
caption = 'A figure is an image with a caption and/or a legend:'
11+
legend = '''
12+
**TODO: need to convert yamltotable to tomltotable**
13+
14+
This paragraph is also part of the legend.
15+
'''
16+
{{< /figure >}}
17+
18+
{{< figure >}}
19+
src = 'https://source.unsplash.com/200x200/daily?cute+puppy'
20+
alt = 'Cute puppies'
21+
align = 'left'
22+
height = 150
23+
width = 150
24+
caption = '''
25+
A figure with left alignment.
26+
'''
27+
{{< /figure >}}
28+
29+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
30+
31+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
32+
33+
*/}}
34+
35+
{{- $figure := .Inner | transform.Unmarshal -}}
36+
{{- $align := default "default" $figure.align -}}
37+
{{- $id := printf "id%03d" $.Ordinal -}}
38+
<figure class="align-{{ $align }}" id="{{ $id }}">
39+
{{- $m := newScratch -}}
40+
{{- $m.Set "image" $figure -}}
41+
{{- $m.SetInMap "image" "align" "center" -}}
42+
{{ partial "_elements/image.html" (dict "data" $m.Values.image) }}
43+
<figcaption>
44+
<p><span class="caption-text">
45+
{{- $figure.caption | markdownify -}}
46+
</span><a class="headerlink" href="#{{ $id }}" title="Link to this image">#</a></p>
47+
{{- with $figure.legend }}
48+
<div class="legend">
49+
{{ . | markdownify -}}
50+
</div>
51+
{{- end }}
52+
</figcaption>
53+
</figure>

0 commit comments

Comments
 (0)