Skip to content

Commit 7a8494a

Browse files
committed
Fix possible exception when adding/removing JS/CSS assets to the context (#7)
1 parent 7bd4cbf commit 7a8494a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

sphinx_tabs/tabs.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,20 @@ def add_assets(app, pagename, templatename, context, doctree):
208208
script_files = [posixpath.join('_static', path)
209209
for path in assets if path.endswith('js')]
210210
if visitor.found_tabs_directive:
211-
context['css_files'].extend(css_files)
212-
context['script_files'].extend(script_files)
211+
if 'css_files' not in context:
212+
context['css_files'] = css_files
213+
else:
214+
context['css_files'].extend(css_files)
215+
if 'script_files' not in context:
216+
context['script_files'] = script_files
217+
else:
218+
context['script_files'].extend(script_files)
213219
else:
214220
for path in css_files:
215-
if path in context['css_files']:
221+
if 'css_files' in context and path in context['css_files']:
216222
context['css_files'].remove(path)
217223
for path in script_files:
218-
if path in context['script_files']:
224+
if 'script_files' in context and path in context['script_files']:
219225
context['script_files'].remove(path)
220226
# pylint: enable=unused-argument
221227

0 commit comments

Comments
 (0)