Skip to content

Commit f7cafbb

Browse files
committed
Disable cross-referencing for ivars
http://stackoverflow.com/a/41184353/1932023
1 parent 94906f9 commit f7cafbb

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

docs/conf.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
import sys
2121
from datetime import datetime
2222

23+
from docutils import nodes
24+
from sphinx.util.docfields import TypedField
25+
from sphinx import addnodes
26+
2327

2428
sys.path.insert(0, os.path.abspath('..'))
2529

@@ -176,3 +180,43 @@
176180
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
177181

178182
# 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

Comments
 (0)