Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #14033 -- Fixed another problem with xrefs and Sphinx 1.X in th…

…e Django doc extension. Thanks for the report and patch, Ramiro Morales and Georg Brandl.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13602 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7098f8444e0f122d5d29c74bd0c41929ad66d83c 1 parent 68aff2f
Jannis Leidel authored August 18, 2010

Showing 1 changed file with 39 additions and 30 deletions. Show diff stats Hide diff stats

  1. 69  docs/_ext/djangodocs.py
69  docs/_ext/djangodocs.py
@@ -19,6 +19,7 @@
19 19
 from sphinx.builders.html import StandaloneHTMLBuilder
20 20
 from sphinx.writers.html import SmartyPantsHTMLTranslator
21 21
 from sphinx.util.console import bold
  22
+from sphinx.util.compat import Directive
22 23
 
23 24
 
24 25
 def setup(app):
@@ -55,38 +56,46 @@ def setup(app):
55 56
         parse_node    = parse_django_adminopt_node,
56 57
     )
57 58
     app.add_config_value('django_next_version', '0.0', True)
58  
-    app.add_directive('versionadded', parse_version_directive, 1, (1, 1, 1))
59  
-    app.add_directive('versionchanged', parse_version_directive, 1, (1, 1, 1))
  59
+    app.add_directive('versionadded', VersionDirective)
  60
+    app.add_directive('versionchanged', VersionDirective)
60 61
     app.add_transform(SuppressBlockquotes)
61 62
     app.add_builder(DjangoStandaloneHTMLBuilder)
62 63
 
63  
-def parse_version_directive(name, arguments, options, content, lineno,
64  
-                      content_offset, block_text, state, state_machine):
65  
-    env = state.document.settings.env
66  
-    is_nextversion = env.config.django_next_version == arguments[0]
67  
-    ret = []
68  
-    node = addnodes.versionmodified()
69  
-    ret.append(node)
70  
-    if not is_nextversion:
71  
-        if len(arguments) == 1:
72  
-            linktext = 'Please, see the release notes <releases-%s>' % (arguments[0])
73  
-            try:
74  
-                xrefs = roles.XRefRole()('ref', linktext, linktext, lineno, state) # Sphinx >= 1.0
75  
-            except:
76  
-                xrefs = roles.xfileref_role('ref', linktext, linktext, lineno, state) # Sphinx < 1.0
77  
-            node.extend(xrefs[0])
78  
-        node['version'] = arguments[0]
79  
-    else:
80  
-        node['version'] = "Development version"
81  
-    node['type'] = name
82  
-    if len(arguments) == 2:
83  
-        inodes, messages = state.inline_text(arguments[1], lineno+1)
84  
-        node.extend(inodes)
85  
-        if content:
86  
-            state.nested_parse(content, content_offset, node)
87  
-        ret = ret + messages
88  
-    env.note_versionchange(node['type'], node['version'], node, lineno)
89  
-    return ret
  64
+
  65
+class VersionDirective(Directive):
  66
+    has_content = True
  67
+    required_arguments = 1
  68
+    optional_arguments = 1
  69
+    final_argument_whitespace = True
  70
+    option_spec = {}
  71
+
  72
+    def run(self):
  73
+        env = self.state.document.settings.env
  74
+        arg0 = self.arguments[0]
  75
+        is_nextversion = env.config.django_next_version == arg0
  76
+        ret = []
  77
+        node = addnodes.versionmodified()
  78
+        ret.append(node)
  79
+        if not is_nextversion:
  80
+            if len(self.arguments) == 1:
  81
+                linktext = 'Please, see the release notes <releases-%s>' % (arg0)
  82
+                try:
  83
+                    xrefs = roles.XRefRole()('std:ref', linktext, linktext, self.lineno, self.state) # Sphinx >= 1.0
  84
+                except AttributeError:
  85
+                    xrefs = roles.xfileref_role('ref', linktext, linktext, self.lineno, self.state) # Sphinx < 1.0
  86
+                node.extend(xrefs[0])
  87
+            node['version'] = arg0
  88
+        else:
  89
+            node['version'] = "Development version"
  90
+        node['type'] = self.name
  91
+        if len(self.arguments) == 2:
  92
+            inodes, messages = self.state.inline_text(self.arguments[1], self.lineno+1)
  93
+            node.extend(inodes)
  94
+            if self.content:
  95
+                self.state.nested_parse(self.content, self.content_offset, node)
  96
+            ret = ret + messages
  97
+        env.note_versionchange(node['type'], node['version'], node, self.lineno)
  98
+        return ret
90 99
 
91 100
 
92 101
 class SuppressBlockquotes(transforms.Transform):
@@ -185,7 +194,7 @@ def parse_django_adminopt_node(env, sig, signode):
185 194
     """A copy of sphinx.directives.CmdoptionDesc.parse_signature()"""
186 195
     try:
187 196
         from sphinx.domains.std import option_desc_re # Sphinx >= 1.0
188  
-    except:
  197
+    except ImportError:
189 198
         from sphinx.directives.desc import option_desc_re # Sphinx < 1.0
190 199
     count = 0
191 200
     firstname = ''

0 notes on commit 7098f84

Please sign in to comment.
Something went wrong with that request. Please try again.