Skip to content

Commit f452be7

Browse files
authored
🐛 FIX: Links in card titles (#59)
Sphinx expects that references are within another `TextElement` (e.g. a paragraph), see: https://github.com/sphinx-doc/sphinx/blob/068f802df90ea790f89319094e407c4d5f6c26ff/sphinx/writers/html5.py#L224 To "simulate" this, we wrap the rendered title nodes within a `PassthroughTextElement`, which is ignored on visits.
1 parent 93955f5 commit f452be7

24 files changed

+134
-45
lines changed

docs/cards.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(cards)=
1+
(sd-cards)=
22

33
# Cards
44

docs/dropdowns.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(dropdowns)=
1+
(sd-dropdowns)=
22

33
# Dropdowns
44

docs/grids.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(grids)=
1+
(sd-grids)=
22

33
# Grids
44

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(target)=
2+
:::{card} Card Title <https://example.com> {ref}`link <target>`
3+
4+
Card content
5+
:::
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.. _target:
2+
.. card:: Card Title https://example.com :ref:`link <target>`
3+
4+
Card content

docs/tabs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(tabs)=
1+
(sd-tabs)=
22

33
# Tabs
44

sphinx_design/cards.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ def create_card(
134134
+ options.get("class-title", []),
135135
)
136136
textnodes, _ = inst.state.inline_text(arguments[0], inst.lineno)
137-
title.extend(textnodes)
137+
title_container = PassthroughTextElement()
138+
title_container.extend(textnodes)
139+
title.append(title_container)
138140
body.insert(0, title)
139141
container.append(body)
140142

sphinx_design/shared.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,6 @@ class PassthroughTextElement(nodes.TextElement):
103103
"""A text element which will not render anything.
104104
105105
This is required for reference node to render correctly outside of paragraphs.
106+
Since sphinx expects them to be within a ``TextElement``:
107+
https://github.com/sphinx-doc/sphinx/blob/068f802df90ea790f89319094e407c4d5f6c26ff/sphinx/writers/html5.py#L224
106108
"""

tests/test_snippets/snippet_post_card-basic.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<container classes="sd-card sd-sphinx-override sd-mb-3 sd-shadow-sm" design_component="card" is_div="True">
66
<container classes="sd-card-body" design_component="card-body" is_div="True">
77
<container classes="sd-card-title sd-font-weight-bold" design_component="card-title" is_div="True">
8-
Card Title
8+
<PassthroughTextElement>
9+
Card Title
910
<paragraph classes="sd-card-text">
1011
Card content

tests/test_snippets/snippet_post_card-carousel.xml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,36 @@
66
<container classes="sd-card sd-sphinx-override sd-mb-3 sd-shadow-sm" design_component="card" is_div="True">
77
<container classes="sd-card-body" design_component="card-body" is_div="True">
88
<container classes="sd-card-title sd-font-weight-bold" design_component="card-title" is_div="True">
9-
card 1
9+
<PassthroughTextElement>
10+
card 1
1011
<paragraph classes="sd-card-text">
1112
content
1213
<container classes="sd-card sd-sphinx-override sd-mb-3 sd-shadow-sm" design_component="card" is_div="True">
1314
<container classes="sd-card-body" design_component="card-body" is_div="True">
1415
<container classes="sd-card-title sd-font-weight-bold" design_component="card-title" is_div="True">
15-
card 2
16+
<PassthroughTextElement>
17+
card 2
1618
<paragraph classes="sd-card-text">
1719
Longer
1820
<paragraph classes="sd-card-text">
1921
content
2022
<container classes="sd-card sd-sphinx-override sd-mb-3 sd-shadow-sm" design_component="card" is_div="True">
2123
<container classes="sd-card-body" design_component="card-body" is_div="True">
2224
<container classes="sd-card-title sd-font-weight-bold" design_component="card-title" is_div="True">
23-
card 3
25+
<PassthroughTextElement>
26+
card 3
2427
<container classes="sd-card sd-sphinx-override sd-mb-3 sd-shadow-sm" design_component="card" is_div="True">
2528
<container classes="sd-card-body" design_component="card-body" is_div="True">
2629
<container classes="sd-card-title sd-font-weight-bold" design_component="card-title" is_div="True">
27-
card 4
30+
<PassthroughTextElement>
31+
card 4
2832
<container classes="sd-card sd-sphinx-override sd-mb-3 sd-shadow-sm" design_component="card" is_div="True">
2933
<container classes="sd-card-body" design_component="card-body" is_div="True">
3034
<container classes="sd-card-title sd-font-weight-bold" design_component="card-title" is_div="True">
31-
card 5
35+
<PassthroughTextElement>
36+
card 5
3237
<container classes="sd-card sd-sphinx-override sd-mb-3 sd-shadow-sm" design_component="card" is_div="True">
3338
<container classes="sd-card-body" design_component="card-body" is_div="True">
3439
<container classes="sd-card-title sd-font-weight-bold" design_component="card-title" is_div="True">
35-
card 6
40+
<PassthroughTextElement>
41+
card 6

0 commit comments

Comments
 (0)