Skip to content

Commit eddbdc0

Browse files
authored
Merge branch 'main' into patch-1
2 parents 5ec47db + 496aefc commit eddbdc0

8 files changed

Lines changed: 97 additions & 21 deletions

File tree

sphinx_design/tabs.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def run_with_defaults(self) -> list[nodes.Node]:
3535
)
3636
self.set_source_info(tab_set)
3737
self.state.nested_parse(self.content, self.content_offset, tab_set)
38+
valid_children = []
3839
for item in tab_set.children:
3940
if not is_component(item, "tab-item"):
4041
LOGGER.warning(
@@ -44,9 +45,12 @@ def run_with_defaults(self) -> list[nodes.Node]:
4445
type=WARNING_TYPE,
4546
subtype="tab",
4647
)
47-
break
48+
continue # Skip invalid children instead of breaking
4849
if "sync_id" in item.children[0]:
4950
item.children[0]["sync_group"] = self.options.get("sync-group", "tab")
51+
valid_children.append(item)
52+
53+
tab_set.children = valid_children
5054
return [tab_set]
5155

5256

@@ -240,10 +244,17 @@ def run(self) -> None:
240244
selected_idx = 0 if selected_idx is None else selected_idx
241245

242246
for idx, tab_item in enumerate(tab_set.children):
243-
try:
244-
tab_label, tab_content = tab_item.children
245-
except ValueError:
246-
raise
247+
if not is_component(tab_item, "tab-item"):
248+
continue # Skip non tab-item children
249+
if len(tab_item.children) != 2:
250+
LOGGER.warning(
251+
f"Malformed 'tab-item' directive [{WARNING_TYPE}.tab]",
252+
location=tab_item,
253+
type=WARNING_TYPE,
254+
subtype="tab",
255+
)
256+
continue
257+
tab_label, tab_content = tab_item.children
247258
tab_item_identity = tab_item_id_base + str(tab_item_id_num)
248259
tab_item_id_num += 1
249260

style/_button.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright 2011-2019 The Bootstrap Authors
33
// Copyright 2011-2019 Twitter, Inc.
44
// Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
5+
@use "colors" as *;
56

67
.sd-btn {
78
background-color: transparent;

style/_display.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use "spacing" as *;
2+
13
.sd-d-none {
24
display: none !important;
35
}

style/_grids.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// Copyright 2011-2019 Twitter, Inc.
55
// Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
66
@use 'sass:math';
7+
@use "spacing" as *;
78

89
$gutter-widths: $spacings;
910

style/_variables.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use "colors" as *;
2+
13
:root {
24
// semantic colors
35
@each $color, $value in $semantic-colors {

style/index.scss

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
@import './colors';
2-
@import './spacing';
3-
@import './sizing';
4-
@import './display';
5-
@import './text';
6-
@import './borders';
7-
@import './animations';
8-
@import './badge';
9-
@import './button';
10-
@import './icons';
11-
@import './cards';
12-
@import './grids';
13-
@import './dropdown';
14-
@import './tabs';
15-
@import './overrides';
16-
@import './variables'
1+
@use './colors' as *;
2+
@use './spacing' as *;
3+
@use './sizing' as *;
4+
@use './display' as *;
5+
@use './text' as *;
6+
@use './borders' as *;
7+
@use './animations' as *;
8+
@use './badge' as *;
9+
@use './button' as *;
10+
@use './icons' as *;
11+
@use './cards' as *;
12+
@use './grids' as *;
13+
@use './dropdown' as *;
14+
@use './tabs' as *;
15+
@use './overrides' as *;
16+
@use './variables' as *;

tests/test_misc.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,45 @@ def test_material(style, file_regression):
3030
for name in sorted(data):
3131
content += f"{name}: {','.join(data[name]['heights'])}\n"
3232
file_regression.check(content)
33+
34+
35+
def test_tab_set_with_invalid_children(
36+
sphinx_builder, file_regression, normalize_doctree_xml
37+
):
38+
"""Test that tab-set with invalid children does not crash.
39+
40+
This reproduces the issue from https://github.com/executablebooks/sphinx-design/issues/243
41+
where a ValueError was raised when a tab-set contained non-tab-item children.
42+
"""
43+
builder = sphinx_builder(conf_kwargs={"extensions": ["sphinx_design"]})
44+
builder.src_path.joinpath("index.rst").write_text(
45+
"""
46+
Tab Test document
47+
=================
48+
49+
.. tab-set::
50+
51+
.. tab-item:: A
52+
53+
A content
54+
55+
foo
56+
57+
.. tab-item:: B
58+
59+
B content
60+
""",
61+
encoding="utf8",
62+
)
63+
# Build should not crash, but should produce a warning
64+
builder.build(assert_pass=False)
65+
assert "All children of a 'tab-set' should be 'tab-item'" in builder.warnings
66+
67+
# Valid tab items should still be processed
68+
doctree = builder.get_doctree("index", post_transforms=True)
69+
doctree.attributes.pop("translation_progress", None)
70+
file_regression.check(
71+
normalize_doctree_xml(doctree.pformat()),
72+
extension=".xml",
73+
encoding="utf8",
74+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<document source="index">
2+
<section ids="tab-test-document" names="tab\ test\ document">
3+
<title>
4+
Tab Test document
5+
<container classes="sd-tab-set" design_component="tab-set" is_div="True">
6+
<sd_tab_input checked="True" id="sd-tab-item-0" set_id="sd-tab-set-0" type="radio">
7+
<sd_tab_label classes="sd-tab-label" input_id="sd-tab-item-0">
8+
A
9+
<container classes="sd-tab-content" design_component="tab-content" is_div="True">
10+
<paragraph>
11+
A content
12+
<sd_tab_input checked="False" id="sd-tab-item-1" set_id="sd-tab-set-0" type="radio">
13+
<sd_tab_label classes="sd-tab-label" input_id="sd-tab-item-1">
14+
B
15+
<container classes="sd-tab-content" design_component="tab-content" is_div="True">
16+
<paragraph>
17+
B content

0 commit comments

Comments
 (0)