Skip to content

Commit c1ad998

Browse files
committed
Allow multiple group tabs with the same name (the ordering of the tabs is used to determine the group ids) (#12)
1 parent 1f42fab commit c1ad998

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

sphinx_tabs/tabs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def run(self):
4747
classes = 'ui top attached tabular menu sphinx-menu'
4848
tabs_node['classes'] = classes.split(' ')
4949

50+
env.temp_data['tab_ids'] = []
5051
env.temp_data['tab_titles'] = []
5152
env.temp_data['is_first_tab'] = True
5253
self.state.nested_parse(self.content, self.content_offset, node)
@@ -89,6 +90,11 @@ def run(self):
8990

9091
if 'tab_id' not in args:
9192
args['tab_id'] = env.new_serialno('tab_id')
93+
i = 1
94+
while args['tab_id'] in env.temp_data['tab_ids']:
95+
args['tab_id'] = '%s-%d' % (args['tab_id'], i)
96+
i += 1
97+
env.temp_data['tab_ids'].append(args['tab_id'])
9298

9399
data_tab = "sphinx-data-tab-{}".format(args['tab_id'])
94100

test/basic/index.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,34 @@ Code Tabs
9393
PROGRAM main
9494
END PROGRAM main
9595

96+
.. tabs::
97+
98+
.. code-tab:: json 400
99+
100+
{
101+
"message": "Possible issue 1"
102+
}
103+
104+
.. code-tab:: json 400
105+
106+
{
107+
"message": "Possible issue 2"
108+
}
109+
110+
.. tabs::
111+
112+
.. code-tab:: json 400
113+
114+
{
115+
"message": "Possible issue 1"
116+
}
117+
118+
.. code-tab:: json 400
119+
120+
{
121+
"message": "Possible issue 2"
122+
}
123+
96124
Group Tabs
97125
========================================
98126

0 commit comments

Comments
 (0)