From 1ac9a6a73e653bc13441a3606a2af6888223b151 Mon Sep 17 00:00:00 2001 From: djungelorm Date: Mon, 5 Nov 2018 19:52:55 +0000 Subject: [PATCH] Fix naming a tab as a number (Fix #24) --- CHANGES.txt | 1 + sphinx_tabs/tabs.py | 11 +++++++---- sphinx_tabs/test/basic/index.html | 6 ++++++ sphinx_tabs/test/basic/index.rst | 4 ++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d55c8d5..11365e0 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -2,6 +2,7 @@ v1.1.8 * Add support for :linenos: to code tabs (#22) * Improve fallback for non-HTML builders (#19) * Add spelling builder to list of builders (#20) + * Fix naming a tab as a number (#24) v1.1.7 * Fix css files not being removed when tabs are not used on a page diff --git a/sphinx_tabs/tabs.py b/sphinx_tabs/tabs.py index ede506b..5a565b2 100644 --- a/sphinx_tabs/tabs.py +++ b/sphinx_tabs/tabs.py @@ -90,10 +90,13 @@ def run(self): env = self.state.document.settings.env args = self.content[0].strip() - try: - args = json.loads(args) - self.content.trim_start(1) - except ValueError: + if args.startswith('{'): + try: + args = json.loads(args) + self.content.trim_start(1) + except ValueError: + args = {} + else: args = {} tab_name = nodes.container() diff --git a/sphinx_tabs/test/basic/index.html b/sphinx_tabs/test/basic/index.html index 7649365..71fda3c 100644 --- a/sphinx_tabs/test/basic/index.html +++ b/sphinx_tabs/test/basic/index.html @@ -12,6 +12,10 @@
Oranges
+
+
+404
+
Apples are green, or sometimes red.
@@ -19,4 +23,6 @@ Pears are green.
Oranges are orange.
+
+A number in the name.
diff --git a/sphinx_tabs/test/basic/index.rst b/sphinx_tabs/test/basic/index.rst index b528f61..d1e8c41 100644 --- a/sphinx_tabs/test/basic/index.rst +++ b/sphinx_tabs/test/basic/index.rst @@ -11,3 +11,7 @@ .. tab:: Oranges Oranges are orange. + + .. tab:: 404 + + A number in the name.