|
5 | 5 |
|
6 | 6 | Sphinx extension with Python doc-specific markup. |
7 | 7 |
|
8 | | - :copyright: 2008, 2009, 2010, 2011, 2012 by Georg Brandl. |
| 8 | + :copyright: 2008-2013 by Georg Brandl. |
9 | 9 | :license: Python license. |
10 | 10 | """ |
11 | 11 |
|
12 | 12 | ISSUE_URI = 'http://bugs.python.org/issue%s' |
13 | 13 | SOURCE_URI = 'http://hg.python.org/cpython/file/3.3/%s' |
14 | 14 |
|
15 | 15 | from docutils import nodes, utils |
| 16 | + |
| 17 | +import sphinx |
16 | 18 | 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 |
17 | 22 |
|
18 | 23 | # monkey-patch reST parser to disable alphabetic and roman enumerated lists |
19 | 24 | from docutils.parsers.rst.states import Body |
|
22 | 27 | Body.enum.converters['lowerroman'] = \ |
23 | 28 | Body.enum.converters['upperroman'] = lambda x: None |
24 | 29 |
|
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 |
40 | 41 |
|
41 | 42 | # monkey-patch HTML and LaTeX translators to keep doctest blocks in the |
42 | 43 | # doctest docs themselves |
|
0 commit comments