Skip to content

Commit 992dde9

Browse files
committed
Add Sphinx directive/roles: "infocard" and "tag(s)"
A composite component offering a title, description text, and both verbose and short tags. It is suitable for authoring pages enumerating items with dense information, without the maintenance nightmares of tables. References: - https://hiveeyes.org/docs/arduino/firmware/overview.html - https://kotori.readthedocs.io/en/latest/integration/
1 parent f2afea1 commit 992dde9

21 files changed

+865
-0
lines changed

docs/get_started.md

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

6565
- [](#gridtable-directive)
66+
- [](#infocard-directive)
67+
- [](#tag-role)
6668

6769
Both [reStructuredText] and [Markedly Structured Text] syntax are supported equally well.
6870

docs/index.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ get_started
7070
:hidden:
7171
7272
gridtable
73+
infocard
74+
```
75+
76+
```{toctree}
77+
:caption: Roles
78+
:hidden:
79+
80+
tag
7381
```
7482

7583
```{toctree}
@@ -93,6 +101,20 @@ sandbox
93101
HTML table based on a grid layout, with ergonomic top-down configuration.
94102
:::
95103

104+
:::{grid-item-card} {octicon}`note` Info card
105+
:link: infocard
106+
:link-type: doc
107+
108+
Composite info card container element, to be used as a grid item.
109+
:::
110+
111+
:::{grid-item-card} {octicon}`plus-circle` Special badges
112+
:link: tag
113+
:link-type: doc
114+
115+
Special {bdg-primary}`badges` and other components.
116+
:::
117+
96118
::::
97119

98120
-----------

docs/infocard.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
(infocard-directive)=
2+
3+
# Info Card
4+
5+
6+
## About
7+
8+
A composite info card container element, to be used as an item within
9+
a [grid layout](inv:sd#grids). It provides the Sphinx directive `info-card`.
10+
11+
12+
## Details
13+
14+
The info card is a composite element offering a title, description text, and
15+
both verbose and short tags. It is suitable for authoring pages enumerating
16+
items with dense information, without the maintenance nightmares of tables.
17+
18+
For a compact notation of the short tag elements, it uses the corresponding
19+
[](#tag-role) for efficiently rendering [](inv:sd#badges), which is also
20+
provided by this package.
21+
22+
23+
## Synopsis
24+
25+
::::{info-card}
26+
27+
:::{grid-item}
28+
:columns: 8
29+
[example.org/beagles](https://example.org/beagles)
30+
31+
A module for collecting votes from beagles, \
32+
and for consolidating them.
33+
34+
**Author:** C. Schultz, Universal Features Syndicate \
35+
**Contact:** Los Angeles, CA; <cschultz@peanuts.example.org>
36+
:::
37+
38+
:::{grid-item}
39+
:columns: 4
40+
41+
{tags-primary}`foo, bar`
42+
43+
{tags-success}`baz`
44+
45+
{tags-secondary}`qux`
46+
47+
{tags-info}`anything`
48+
:::
49+
50+
::::
51+
52+
53+
## Usage
54+
````{tab-set-code}
55+
```{literalinclude} ./snippets/myst/infocard.md
56+
:language: markdown
57+
```
58+
```{literalinclude} ./snippets/rst/infocard.rst
59+
:language: rst
60+
```
61+
````
62+
63+
64+
_This page is written in Markedly Structured Text (MyST Markdown)._

docs/snippets/myst/infocard.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
::::{info-card}
2+
3+
:::{grid-item}
4+
:columns: 8
5+
[example.org/beagles](https://example.org/beagles)
6+
7+
A module for collecting votes from beagles, \
8+
and for consolidating them.
9+
10+
**Author:** C. Schultz, Universal Features Syndicate \
11+
**Contact:** Los Angeles, CA; <cschultz@peanuts.example.org>
12+
:::
13+
14+
:::{grid-item}
15+
:columns: 4
16+
17+
{tags-primary}`foo, bar`
18+
19+
{tags-success}`baz`
20+
21+
{tags-secondary}`qux`
22+
23+
{tags-info}`anything`
24+
:::
25+
26+
::::

docs/snippets/myst/tag.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{tag}`foo, bar`
2+
{tags}`foo, bar`

docs/snippets/rst/infocard.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.. info-card::
2+
3+
.. grid-item::
4+
:columns: 8
5+
6+
`example.org/beagles <https://example.org/beagles>`_
7+
8+
| A module for collecting votes from beagles,
9+
| and for consolidating them.
10+
11+
| **Author:** C. Schultz, Universal Features Syndicate
12+
| **Contact:** Los Angeles, CA; <cschultz@peanuts.example.org>
13+
14+
.. grid-item::
15+
:columns: 4
16+
17+
:tags-primary:`foo, bar`
18+
19+
:tags-success:`baz`
20+
21+
:tags-secondary:`qux`
22+
23+
:tags-info:`anything`

docs/snippets/rst/tag.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:tag:`foo, bar`
2+
:tags:`foo, bar`

docs/tag.md

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
(tag-role)=
2+
3+
# `tag(s)` role
4+
5+
6+
## About
7+
8+
The `tag` and `tags` roles are shortcuts to the `badge` roles of sphinx{design},
9+
see [](inv:sd#badges).
10+
11+
12+
## Details
13+
14+
The idea is to need less code for defining "tag"-like badges within the
15+
[](#infocard-directive) element. All of them will use the `outline` option flag
16+
by default, to give them a corresponding visual appearance.
17+
18+
19+
## Synopsis
20+
21+
There is the `{tag}`, and the `{tags}` role. A `{tag}` will render its text content
22+
1:1 into a single badge element, while `{tags}` will split the text by comma (`,`),
23+
and renders the outcome using individual badge elements.
24+
25+
26+
::::{sd-table}
27+
:widths: 3 3 3 3
28+
:row-class: top-border
29+
30+
:::{sd-row}
31+
```{sd-item} **Description**
32+
```
33+
```{sd-item} **Appearance**
34+
```
35+
```{sd-item} **MyST syntax**
36+
```
37+
```{sd-item} **rST syntax**
38+
```
39+
:::
40+
41+
:::{sd-row}
42+
```{sd-item} Single tag
43+
```
44+
```{sd-item}
45+
{tag}`foo, bar`
46+
```
47+
```{sd-item}
48+
```markdown
49+
{tag}`foo, bar`
50+
```
51+
```{sd-item}
52+
```restructuredtext
53+
:tag:`foo, bar`
54+
```
55+
:::
56+
57+
:::{sd-row}
58+
```{sd-item} Multiple tags
59+
```
60+
```{sd-item}
61+
{tags}`foo, bar`
62+
```
63+
```{sd-item}
64+
```markdown
65+
{tags}`foo, bar`
66+
```
67+
```{sd-item}
68+
```restructuredtext
69+
:tags:`foo, bar`
70+
```
71+
:::
72+
73+
::::
74+
75+
76+
## Color variants
77+
78+
All colors of badges are supported, by appending a color label from the list of
79+
[semantic colors] as a suffix to the role name, like presented below.
80+
81+
::::{sd-table}
82+
:widths: 3 3 6
83+
:row-class: top-border
84+
85+
:::{sd-row}
86+
```{sd-item} **Description**
87+
```
88+
```{sd-item} **Appearance**
89+
```
90+
```{sd-item} **MyST syntax**
91+
```
92+
:::
93+
94+
:::{sd-row}
95+
```{sd-item} Primary and secondary
96+
```
97+
```{sd-item}
98+
{tags-primary}`foo, bar` \
99+
{tags-secondary}`foo, bar`
100+
```
101+
```{sd-item}
102+
```markdown
103+
{tags-primary}`foo, bar` \
104+
{tags-secondary}`foo, bar`
105+
```
106+
:::
107+
108+
:::{sd-row}
109+
```{sd-item} Admonitions
110+
```
111+
```{sd-item}
112+
{tags-success}`foo, bar` \
113+
{tags-info}`foo, bar` \
114+
{tags-warning}`foo, bar` \
115+
{tags-danger}`foo, bar`
116+
```
117+
```{sd-item}
118+
```markdown
119+
{tags-success}`foo, bar` \
120+
{tags-info}`foo, bar` \
121+
{tags-warning}`foo, bar` \
122+
{tags-danger}`foo, bar`
123+
```
124+
:::
125+
126+
:::{sd-row}
127+
```{sd-item}
128+
Light to dark
129+
```
130+
```{sd-item}
131+
{tags-white}`foo, bar` \
132+
{tags-light}`foo, bar` \
133+
{tags-muted}`foo, bar` \
134+
{tags-dark}`foo, bar` \
135+
{tags-black}`foo, bar`
136+
```
137+
```{sd-item}
138+
```markdown
139+
{tags-white}`foo, bar` \
140+
{tags-light}`foo, bar` \
141+
{tags-muted}`foo, bar` \
142+
{tags-dark}`foo, bar` \
143+
{tags-black}`foo, bar`
144+
```
145+
:::
146+
147+
::::
148+
149+
````{note}
150+
While the table above only presents Markdown syntax, reStructuredText syntax is
151+
also supported.
152+
153+
```{eval-rst}
154+
:tag-warning:`REVIEW!`
155+
:tags-primary:`foo, bar`
156+
```
157+
158+
```restructuredtext
159+
:tag-warning:`REVIEW!`
160+
:tags-primary:`foo, bar`
161+
```
162+
````
163+
164+
165+
---
166+
167+
_This page is written in Markedly Structured Text (MyST Markdown)._
168+
169+
170+
[semantic colors]: https://sphinx-design.readthedocs.io/en/latest/css_classes.html#colors

sphinx_design_elements/compiled/style.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,12 @@
1919
.sd-col > .highlight-restructuredtext {
2020
margin: unset;
2121
}
22+
23+
24+
/* Info card */
25+
26+
/* Fix grid item formatting. */
27+
.sd-col > div.line-block {
28+
margin-top: unset;
29+
margin-bottom: unset;
30+
}

sphinx_design_elements/extension.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
from . import compiled as static_module
1111
from .gridtable import setup_gridtable
12+
from .infocard import setup_infocard
13+
from .tag import setup_tags
1214

1315

1416
def setup_extension(app: Sphinx) -> None:
@@ -21,6 +23,8 @@ def setup_extension(app: Sphinx) -> None:
2123
app.add_node(nodes.container, override=True, html=(visit_container, depart_container))
2224

2325
setup_gridtable(app)
26+
setup_infocard(app)
27+
setup_tags(app)
2428

2529

2630
def update_css_js(app: Sphinx):

0 commit comments

Comments
 (0)