Skip to content

Commit 239990d

Browse files
committed
Fix compatibility with upcoming Sphinx 1.2.
1 parent e23b2d0 commit 239990d

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

Doc/tools/sphinxext/pyspecific.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@
55
66
Sphinx extension with Python doc-specific markup.
77
8-
:copyright: 2008, 2009, 2010, 2011, 2012 by Georg Brandl.
8+
:copyright: 2008-2013 by Georg Brandl.
99
:license: Python license.
1010
"""
1111

1212
ISSUE_URI = 'http://bugs.python.org/issue%s'
1313
SOURCE_URI = 'http://hg.python.org/cpython/file/3.3/%s'
1414

1515
from docutils import nodes, utils
16+
17+
import sphinx
1618
from sphinx.util.nodes import split_explicit_title
19+
from sphinx.writers.html import HTMLTranslator
20+
from sphinx.writers.latex import LaTeXTranslator
21+
from sphinx.locale import versionlabels
1722

1823
# monkey-patch reST parser to disable alphabetic and roman enumerated lists
1924
from docutils.parsers.rst.states import Body
@@ -22,21 +27,17 @@
2227
Body.enum.converters['lowerroman'] = \
2328
Body.enum.converters['upperroman'] = lambda x: None
2429

25-
# monkey-patch HTML translator to give versionmodified paragraphs a class
26-
def new_visit_versionmodified(self, node):
27-
self.body.append(self.starttag(node, 'p', CLASS=node['type']))
28-
text = versionlabels[node['type']] % node['version']
29-
if len(node):
30-
text += ':'
31-
else:
32-
text += '.'
33-
self.body.append('<span class="versionmodified">%s</span> ' % text)
34-
35-
from sphinx.writers.html import HTMLTranslator
36-
from sphinx.writers.latex import LaTeXTranslator
37-
from sphinx.locale import versionlabels
38-
HTMLTranslator.visit_versionmodified = new_visit_versionmodified
39-
HTMLTranslator.visit_versionmodified = new_visit_versionmodified
30+
if sphinx.__version__[:3] < '1.2':
31+
# monkey-patch HTML translator to give versionmodified paragraphs a class
32+
def new_visit_versionmodified(self, node):
33+
self.body.append(self.starttag(node, 'p', CLASS=node['type']))
34+
text = versionlabels[node['type']] % node['version']
35+
if len(node):
36+
text += ':'
37+
else:
38+
text += '.'
39+
self.body.append('<span class="versionmodified">%s</span> ' % text)
40+
HTMLTranslator.visit_versionmodified = new_visit_versionmodified
4041

4142
# monkey-patch HTML and LaTeX translators to keep doctest blocks in the
4243
# doctest docs themselves

0 commit comments

Comments
 (0)