Skip to content

Commit 3b1e066

Browse files
Add tables to examples with PST styling (#571)
1 parent 1563874 commit 3b1e066

4 files changed

Lines changed: 119 additions & 3 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Tables
3+
*/
4+
5+
// ensure table will fit in the article width and make them y-scrollable
6+
table {
7+
display: table;
8+
overflow: auto;
9+
10+
// default to table-center
11+
margin-left: auto;
12+
margin-right: auto;
13+
14+
&.table-right {
15+
margin-right: 0;
16+
}
17+
18+
&.table-left {
19+
margin-left: 0;
20+
}
21+
}
22+
23+
// customize table caption from bootstrap
24+
// to display them on top and centered
25+
table caption {
26+
text-align: center;
27+
caption-side: top;
28+
color: var(--pst-color-text-muted);
29+
}
30+
31+
// MyST Markdown tables use these classes to control alignment
32+
th,
33+
td {
34+
&.text-align\:left {
35+
text-align: left;
36+
}
37+
38+
&.text-align\:right {
39+
text-align: right;
40+
}
41+
42+
&.text-align\:center {
43+
text-align: center;
44+
}
45+
}
46+
47+
// override bootstrap table colors
48+
.table {
49+
--bs-table-bg: transparent; //background
50+
--bs-table-color: var(
51+
--pst-color-text-base
52+
); // ensure text and bullets are visible
53+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
@import "./content/lists";
5959
@import "./content/quotes";
6060
//@import "./content/spans";
61-
//@import "./content/tables";
61+
@import "./content/tables";
6262
@import "./content/toctree";
6363
//@import "./content/math";
6464

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: Tables
3+
---
4+
5+
## Markdown Tables
6+
7+
The theme supports [GFM table markdown](https://github.github.com/gfm/#tables-extension-).
8+
9+
| Syntax | Description |
10+
| --------- | ----------- |
11+
| Header | Title |
12+
| Paragraph | Text |
13+
14+
Markdown tables can be aligned:
15+
16+
| Syntax | Description | Test Text |
17+
| :-------- | :---------: | ----------: |
18+
| Header | Title | Here's this |
19+
| Paragraph | Text | And more |
20+
21+
## Table shortcode
22+
23+
This is a feature preview and is not ready for adoption:
24+
25+
{{< yamlToTable >}}
26+
headers:
27+
28+
- Project
29+
- Available Packages
30+
- Download location
31+
32+
format:
33+
34+
- align: left
35+
- align: left
36+
- align: right
37+
38+
rows:
39+
40+
- columns:
41+
42+
- "NumPy"
43+
- |
44+
Official _source code_ (all platforms) and _binaries_ for<br/>
45+
**Windows**, **Linux**, and **Mac OS X**
46+
- "[PyPi page for NumPy](https://pypi.python.org/pypi/numpy)"
47+
48+
- columns:
49+
- SciPy
50+
- |
51+
Official _source code_ (all platforms) and _binaries_ for<br/>
52+
**Windows**, **Linux** and **Mac OS X**
53+
- |
54+
[SciPy release page](https://github.com/scipy/scipy/releases) (sources)<br/>
55+
[PyPI page for SciPy](https://pypi.python.org/pypi/scipy) (all)
56+
57+
{{< /yamlToTable >}}

layouts/shortcodes/yamlToTable.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{{/*
22

33
{{< yamlToTable >}}
4+
caption: 'Table caption'
5+
46
headers:
57
- Project
68
- Available Packages
@@ -34,9 +36,13 @@
3436

3537
{{ $arg := .Get 0 }}
3638
{{ $data := .Inner | transform.Unmarshal }}
39+
{{- $id := printf "id%03d" $.Ordinal -}}
3740

3841
{{ with $data }}
39-
<table>
42+
<table class="table" id="{{ $id }}">
43+
{{- with .caption -}}
44+
<caption><span class="caption-text">{{ . }}</span><a class="headerlink" href="#{{ $id }}" title="Link to this table">#</a></caption>
45+
{{- end }}
4046
{{ range .format }}
4147
<col
4248
{{ range $key, $val := . }}
@@ -46,7 +52,7 @@
4652
{{ end }}
4753

4854
{{ range .headers }}
49-
<th>{{ . | markdownify }}</th>
55+
<th class="head">{{ . | markdownify }}</th>
5056
{{ end }}
5157

5258
{{ range $row := .rows }}

0 commit comments

Comments
 (0)