|
20 | 20 | import sys |
21 | 21 | from datetime import datetime |
22 | 22 |
|
| 23 | +from docutils import nodes |
| 24 | +from sphinx.util.docfields import TypedField |
| 25 | +from sphinx import addnodes |
| 26 | + |
23 | 27 |
|
24 | 28 | sys.path.insert(0, os.path.abspath('..')) |
25 | 29 |
|
|
176 | 180 | html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] |
177 | 181 |
|
178 | 182 | # otherwise, readthedocs.org uses their theme by default, no need to specify it |
| 183 | + |
| 184 | +# disable cross-reference for ivar |
| 185 | +# patch taken from http://stackoverflow.com/a/41184353/1932023 |
| 186 | +def patched_make_field(self, types, domain, items): |
| 187 | + # type: (List, unicode, Tuple) -> nodes.field |
| 188 | + def handle_item(fieldarg, content): |
| 189 | + par = nodes.paragraph() |
| 190 | + par += addnodes.literal_strong('', fieldarg) # Patch: this line added |
| 191 | + # par.extend(self.make_xrefs(self.rolename, domain, fieldarg, |
| 192 | + # addnodes.literal_strong)) |
| 193 | + if fieldarg in types: |
| 194 | + par += nodes.Text(' (') |
| 195 | + # NOTE: using .pop() here to prevent a single type node to be |
| 196 | + # inserted twice into the doctree, which leads to |
| 197 | + # inconsistencies later when references are resolved |
| 198 | + fieldtype = types.pop(fieldarg) |
| 199 | + if len(fieldtype) == 1 and isinstance(fieldtype[0], nodes.Text): |
| 200 | + typename = u''.join(n.astext() for n in fieldtype) |
| 201 | + par.extend(self.make_xrefs(self.typerolename, domain, typename, |
| 202 | + addnodes.literal_emphasis)) |
| 203 | + else: |
| 204 | + par += fieldtype |
| 205 | + par += nodes.Text(')') |
| 206 | + par += nodes.Text(' -- ') |
| 207 | + par += content |
| 208 | + return par |
| 209 | + |
| 210 | + fieldname = nodes.field_name('', self.label) |
| 211 | + if len(items) == 1 and self.can_collapse: |
| 212 | + fieldarg, content = items[0] |
| 213 | + bodynode = handle_item(fieldarg, content) |
| 214 | + else: |
| 215 | + bodynode = self.list_type() |
| 216 | + for fieldarg, content in items: |
| 217 | + bodynode += nodes.list_item('', handle_item(fieldarg, content)) |
| 218 | + fieldbody = nodes.field_body('', bodynode) |
| 219 | + return nodes.field('', fieldname, fieldbody) |
| 220 | + |
| 221 | + |
| 222 | +TypedField.make_field = patched_make_field |
0 commit comments