Skip to content

Commit 3eede6d

Browse files
committed
Add Sphinx directive "gridtable"
A generic, beautiful, yet efficient table element based on a grid layout with top-down configuration capabilities. It provides the Sphinx directives `sd-table`, `sd-row`, and `sd-item`, and a few convenience directive options and flags on them.
1 parent 7ac0fec commit 3eede6d

File tree

12 files changed

+582
-1
lines changed

12 files changed

+582
-1
lines changed

docs/get_started.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ myst_enable_extensions = [
6262
Head over to the "directives" and "roles" sections to learn about the web elements
6363
provided by this collection, and how to use them in your documentation markup.
6464

65+
- [](#gridtable-directive)
66+
6567
Both [reStructuredText] and [Markedly Structured Text] syntax are supported equally well.
6668

6769
## Outlook

docs/gridtable.md

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
(gridtable-directive)=
2+
3+
# Grid Table
4+
5+
6+
## About
7+
8+
_sd-table -- Tables with sphinx{design}_.
9+
10+
A generic, beautiful, yet efficient table element based on a [grid layout](inv:sd#grids),
11+
with top-down configuration capabilities.
12+
13+
It provides the Sphinx directives `sd-table`, `sd-row`, and `sd-item`,
14+
and a few convenience directive options and flags on them.
15+
16+
17+
## Details
18+
19+
The idea of this element is to implement a table based on a grid layout, which can
20+
be parameterized using directives on the table level, so that styling details will
21+
not clutter the leaf nodes (row and item) too much.
22+
23+
To goal is to provide a table element as an alternative to the `list-table` and
24+
`csv-table` directives, which explores a few needs of authors not offered by
25+
other Sphinx directives.
26+
27+
28+
## Synopsis
29+
30+
Basic table, two columns, no formatting.
31+
32+
::::{sd-table}
33+
:widths: 3 9
34+
35+
:::{sd-row}
36+
```{sd-item} **What**
37+
```
38+
```{sd-item} **Description**
39+
```
40+
:::
41+
42+
:::{sd-row}
43+
```{sd-item} Fox
44+
```
45+
```{sd-item}
46+
The quick brown fox jumps
47+
over the lazy dog.
48+
```
49+
:::
50+
:::{sd-row}
51+
```{sd-item} Franz
52+
```
53+
```{sd-item}
54+
Franz jagt im komplett verwahrlosten
55+
Taxi quer durch Bayern.
56+
```
57+
:::
58+
59+
::::
60+
61+
62+
## Usage
63+
64+
sphinx{design} uses a classic 12-column grid layout, so, in order to use
65+
it optimally, make sure that your table item/column widths sum up to 12.
66+
67+
The example table defines two columns, using individual widths of `3` and `9`.
68+
69+
````{tab-set-code}
70+
```{literalinclude} ./snippets/myst/gridtable.md
71+
:language: markdown
72+
```
73+
```{literalinclude} ./snippets/rst/gridtable.rst
74+
:language: rst
75+
```
76+
````
77+
78+
79+
## Variants
80+
81+
A few more variants how to change the visual appearance.
82+
83+
### Visual line separators
84+
85+
Using `:row-class:` to assign row-level styles on the table-level component.
86+
87+
::::{sd-table}
88+
:widths: 3 9
89+
:row-class: top-border
90+
91+
:::{sd-row}
92+
```{sd-item} **What**
93+
```
94+
```{sd-item} **Description**
95+
```
96+
:::
97+
98+
:::{sd-row}
99+
```{sd-item} Fox
100+
```
101+
```{sd-item}
102+
The quick brown fox jumps
103+
over the lazy dog.
104+
```
105+
:::
106+
:::{sd-row}
107+
```{sd-item} Franz
108+
```
109+
```{sd-item}
110+
Franz jagt im komplett verwahrlosten
111+
Taxi quer durch Bayern.
112+
```
113+
:::
114+
115+
::::
116+
117+
118+
### Outlines
119+
120+
This section demonstrates different kinds of outlines, on different component levels.
121+
122+
#### Table outline
123+
124+
Using the `:outline:` directive flag will draw a single border around the whole **table**.
125+
126+
```markdown
127+
::::{sd-table}
128+
:outline:
129+
```
130+
131+
::::{sd-table}
132+
:widths: 3 9
133+
:outline:
134+
135+
:::{sd-row}
136+
```{sd-item} **What**
137+
```
138+
```{sd-item} **Description**
139+
```
140+
:::
141+
142+
:::{sd-row}
143+
```{sd-item} Fox
144+
```
145+
```{sd-item}
146+
The quick brown fox jumps
147+
over the lazy dog.
148+
```
149+
:::
150+
:::{sd-row}
151+
```{sd-item} Franz
152+
```
153+
```{sd-item}
154+
Franz jagt im komplett verwahrlosten
155+
Taxi quer durch Bayern.
156+
```
157+
:::
158+
159+
::::
160+
161+
162+
#### Row outline
163+
164+
Using the `:row-outline:` directive flag will draw borders around each **row** component.
165+
166+
```markdown
167+
::::{sd-table}
168+
:row-outline:
169+
```
170+
171+
::::{sd-table}
172+
:widths: 3 9
173+
:row-outline:
174+
175+
:::{sd-row}
176+
```{sd-item} **What**
177+
```
178+
```{sd-item} **Description**
179+
```
180+
:::
181+
182+
:::{sd-row}
183+
```{sd-item} Fox
184+
```
185+
```{sd-item}
186+
The quick brown fox jumps
187+
over the lazy dog.
188+
```
189+
:::
190+
:::{sd-row}
191+
```{sd-item} Franz
192+
```
193+
```{sd-item}
194+
Franz jagt im komplett verwahrlosten
195+
Taxi quer durch Bayern.
196+
```
197+
:::
198+
199+
::::
200+
201+
202+
#### Item outline
203+
204+
Using the `:item-outline:` directive flag will draw borders around each **item** component.
205+
206+
```markdown
207+
::::{sd-table}
208+
:item-outline:
209+
```
210+
211+
::::{sd-table}
212+
:widths: 3 9
213+
:item-outline:
214+
215+
:::{sd-row}
216+
```{sd-item} **What**
217+
```
218+
```{sd-item} **Description**
219+
```
220+
:::
221+
222+
:::{sd-row}
223+
```{sd-item} Fox
224+
```
225+
```{sd-item}
226+
The quick brown fox jumps
227+
over the lazy dog.
228+
```
229+
:::
230+
:::{sd-row}
231+
```{sd-item} Franz
232+
```
233+
```{sd-item}
234+
Franz jagt im komplett verwahrlosten
235+
Taxi quer durch Bayern.
236+
```
237+
:::
238+
239+
::::
240+
241+
242+
---
243+
244+
_This page is written in Markedly Structured Text (MyST Markdown)._

docs/index.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ README <readme>
6565
get_started
6666
```
6767

68+
```{toctree}
69+
:caption: Directives
70+
:hidden:
71+
72+
gridtable
73+
```
74+
6875
```{toctree}
6976
:caption: Development
7077
:hidden:
@@ -79,7 +86,11 @@ sandbox
7986
:margin: 4 4 0 0
8087
:gutter: 1
8188

82-
:::{grid-item-card} {octicon}`table` Placeholder
89+
:::{grid-item-card} {octicon}`table` Grid table
90+
:link: gridtable
91+
:link-type: doc
92+
93+
HTML table based on a grid layout, with ergonomic top-down configuration.
8394
:::
8495

8596
::::

docs/snippets/myst/gridtable.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
::::{sd-table}
2+
:widths: 3 9
3+
4+
:::{sd-row}
5+
```{sd-item} **What**
6+
```
7+
```{sd-item} **Description**
8+
```
9+
:::
10+
11+
:::{sd-row}
12+
```{sd-item} Fox
13+
```
14+
```{sd-item}
15+
The quick brown fox jumps over the lazy dog.
16+
```
17+
:::
18+
:::{sd-row}
19+
```{sd-item} Franz
20+
```
21+
```{sd-item}
22+
Franz jagt im komplett verwahrlosten Taxi quer durch Bayern.
23+
```
24+
:::
25+
26+
::::

docs/snippets/rst/gridtable.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.. sd-table::
2+
:widths: 3 9
3+
4+
.. sd-row::
5+
.. sd-item:: **What**
6+
.. sd-item:: **Description**
7+
8+
.. sd-row::
9+
.. sd-item:: Fox
10+
.. sd-item::
11+
The quick brown fox jumps over the lazy dog.
12+
13+
.. sd-row::
14+
.. sd-item:: Franz
15+
.. sd-item::
16+
Franz jagt im komplett verwahrlosten Taxi quer durch Bayern.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* Grid table */
2+
3+
/* Beautiful light-weight table outline flavor. */
4+
.top-border {
5+
border-top-width: thin;
6+
border-top-style: solid;
7+
border-top-color: lightgray;
8+
}
9+
.bottom-border {
10+
border-bottom-width: thin;
11+
border-bottom-style: solid;
12+
border-top-color: lightgray;
13+
}
14+
15+
/* Remove margins of child elements inside table items. */
16+
.sd-col > .highlight-markdown {
17+
margin: unset;
18+
}
19+
.sd-col > .highlight-restructuredtext {
20+
margin: unset;
21+
}

sphinx_design_elements/extension.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from sphinx_design.extension import depart_container, visit_container
99

1010
from . import compiled as static_module
11+
from .gridtable import setup_gridtable
1112

1213

1314
def setup_extension(app: Sphinx) -> None:
@@ -19,6 +20,8 @@ def setup_extension(app: Sphinx) -> None:
1920
# of adding the `container` class to all nodes.container
2021
app.add_node(nodes.container, override=True, html=(visit_container, depart_container))
2122

23+
setup_gridtable(app)
24+
2225

2326
def update_css_js(app: Sphinx):
2427
"""Copy the CSS to the build directory."""

0 commit comments

Comments
 (0)