mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-09-03 20:52:55 -05:00
#480: Fix handling of target naming in intersphinx.
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
Release 1.0.2 (in development)
|
Release 1.0.2 (in development)
|
||||||
==============================
|
==============================
|
||||||
|
|
||||||
|
* #480: Fix handling of target naming in intersphinx.
|
||||||
|
|
||||||
* #486: Fix removal of ``!`` for all cross-reference roles.
|
* #486: Fix removal of ``!`` for all cross-reference roles.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import sphinx
|
|||||||
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.todo',
|
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.todo',
|
||||||
'sphinx.ext.autosummary', 'sphinx.ext.extlinks']
|
'sphinx.ext.autosummary', 'sphinx.ext.extlinks']
|
||||||
|
|
||||||
|
#intersphinx_mapping = {'python': ('http://docs.python.org/dev', None)}
|
||||||
|
|
||||||
master_doc = 'contents'
|
master_doc = 'contents'
|
||||||
templates_path = ['_templates']
|
templates_path = ['_templates']
|
||||||
exclude_patterns = ['_build']
|
exclude_patterns = ['_build']
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ linking:
|
|||||||
To add links to modules and objects in the Python standard library
|
To add links to modules and objects in the Python standard library
|
||||||
documentation, use::
|
documentation, use::
|
||||||
|
|
||||||
intersphinx_mapping = {'python': ('http://docs.python.org/', None)}
|
intersphinx_mapping = {'python': ('http://docs.python.org/3.2', None)}
|
||||||
|
|
||||||
This will download the corresponding :file:`objects.inv` file from the
|
This will download the corresponding :file:`objects.inv` file from the
|
||||||
Internet and generate links to the pages under the given URI. The downloaded
|
Internet and generate links to the pages under the given URI. The downloaded
|
||||||
@@ -94,12 +94,12 @@ linking:
|
|||||||
A second example, showing the meaning of a non-``None`` value of the second
|
A second example, showing the meaning of a non-``None`` value of the second
|
||||||
tuple item::
|
tuple item::
|
||||||
|
|
||||||
intersphinx_mapping = {'python': ('http://docs.python.org/',
|
intersphinx_mapping = {'python': ('http://docs.python.org/3.2',
|
||||||
'python-inv.txt')}
|
'python-inv.txt')}
|
||||||
|
|
||||||
This will read the inventory from :file:`python-inv.txt` in the source
|
This will read the inventory from :file:`python-inv.txt` in the source
|
||||||
directory, but still generate links to the pages under
|
directory, but still generate links to the pages under
|
||||||
``http://docs.python.org/``. It is up to you to update the inventory file as
|
``http://docs.python.org/3.2``. It is up to you to update the inventory file as
|
||||||
new objects are added to the Python documentation.
|
new objects are added to the Python documentation.
|
||||||
|
|
||||||
.. confval:: intersphinx_cache_limit
|
.. confval:: intersphinx_cache_limit
|
||||||
|
|||||||
@@ -205,9 +205,20 @@ def missing_reference(app, env, node, contnode):
|
|||||||
proj, version, uri, dispname = inventory[objtype][target]
|
proj, version, uri, dispname = inventory[objtype][target]
|
||||||
newnode = nodes.reference('', '', internal=False, refuri=uri,
|
newnode = nodes.reference('', '', internal=False, refuri=uri,
|
||||||
reftitle='(in %s v%s)' % (proj, version))
|
reftitle='(in %s v%s)' % (proj, version))
|
||||||
if dispname == '-':
|
if node.get('refexplicit'):
|
||||||
dispname = target
|
# use whatever title was given
|
||||||
newnode.append(contnode.__class__(dispname, dispname))
|
newnode.append(contnode)
|
||||||
|
elif dispname == '-':
|
||||||
|
# use whatever title was given, but strip prefix
|
||||||
|
title = contnode.astext()
|
||||||
|
if in_set and title.startswith(in_set+':'):
|
||||||
|
newnode.append(contnode.__class__(title[len(in_set)+1:],
|
||||||
|
title[len(in_set)+1:]))
|
||||||
|
else:
|
||||||
|
newnode.append(contnode)
|
||||||
|
else:
|
||||||
|
# else use the given display name (used for :ref:)
|
||||||
|
newnode.append(contnode.__class__(dispname, dispname))
|
||||||
return newnode
|
return newnode
|
||||||
# at least get rid of the ':' in the target if no explicit title given
|
# at least get rid of the ':' in the target if no explicit title given
|
||||||
if in_set is not None and not node.get('refexplicit', True):
|
if in_set is not None and not node.get('refexplicit', True):
|
||||||
|
|||||||
+36
-24
@@ -94,46 +94,58 @@ def test_missing_reference(tempdir, app):
|
|||||||
('foo', '2.0', 'http://docs.python.org/foo.html#module-module2', '-')
|
('foo', '2.0', 'http://docs.python.org/foo.html#module-module2', '-')
|
||||||
|
|
||||||
# create fake nodes and check referencing
|
# create fake nodes and check referencing
|
||||||
contnode = nodes.emphasis('foo', 'foo')
|
|
||||||
refnode = addnodes.pending_xref('')
|
|
||||||
refnode['reftarget'] = 'module1.func'
|
|
||||||
refnode['reftype'] = 'func'
|
|
||||||
refnode['refdomain'] = 'py'
|
|
||||||
|
|
||||||
rn = missing_reference(app, app.env, refnode, contnode)
|
def fake_node(domain, type, target, content, **attrs):
|
||||||
|
contnode = nodes.emphasis(content, content)
|
||||||
|
node = addnodes.pending_xref('')
|
||||||
|
node['reftarget'] = target
|
||||||
|
node['reftype'] = type
|
||||||
|
node['refdomain'] = domain
|
||||||
|
node.attributes.update(attrs)
|
||||||
|
node += contnode
|
||||||
|
return node, contnode
|
||||||
|
|
||||||
|
def reference_check(*args, **kwds):
|
||||||
|
node, contnode = fake_node(*args, **kwds)
|
||||||
|
return missing_reference(app, app.env, node, contnode)
|
||||||
|
|
||||||
|
# check resolution when a target is found
|
||||||
|
rn = reference_check('py', 'func', 'module1.func', 'foo')
|
||||||
assert isinstance(rn, nodes.reference)
|
assert isinstance(rn, nodes.reference)
|
||||||
assert rn['refuri'] == 'http://docs.python.org/sub/foo.html#module1.func'
|
assert rn['refuri'] == 'http://docs.python.org/sub/foo.html#module1.func'
|
||||||
assert rn['reftitle'] == '(in foo v2.0)'
|
assert rn['reftitle'] == '(in foo v2.0)'
|
||||||
assert rn[0].astext() == 'module1.func'
|
assert rn[0].astext() == 'foo'
|
||||||
|
|
||||||
# create unresolvable nodes and check None return value
|
# create unresolvable nodes and check None return value
|
||||||
refnode['reftype'] = 'foo'
|
assert reference_check('py', 'foo', 'module1.func', 'foo') is None
|
||||||
assert missing_reference(app, app.env, refnode, contnode) is None
|
assert reference_check('py', 'func', 'foo', 'foo') is None
|
||||||
|
assert reference_check('py', 'func', 'foo', 'foo') is None
|
||||||
refnode['reftype'] = 'function'
|
|
||||||
refnode['reftarget'] = 'foo.func'
|
|
||||||
assert missing_reference(app, app.env, refnode, contnode) is None
|
|
||||||
|
|
||||||
# check handling of prefixes
|
# check handling of prefixes
|
||||||
|
|
||||||
# prefix given, target found: prefix is stripped
|
# prefix given, target found: prefix is stripped
|
||||||
refnode['reftype'] = 'mod'
|
rn = reference_check('py', 'mod', 'py3k:module2', 'py3k:module2')
|
||||||
refnode['reftarget'] = 'py3k:module2'
|
|
||||||
rn = missing_reference(app, app.env, refnode, contnode)
|
|
||||||
assert rn[0].astext() == 'module2'
|
assert rn[0].astext() == 'module2'
|
||||||
|
|
||||||
|
# prefix given, but not in title: nothing stripped
|
||||||
|
rn = reference_check('py', 'mod', 'py3k:module2', 'module2')
|
||||||
|
assert rn[0].astext() == 'module2'
|
||||||
|
|
||||||
|
# prefix given, but explicit: nothing stripped
|
||||||
|
rn = reference_check('py', 'mod', 'py3k:module2', 'py3k:module2',
|
||||||
|
refexplicit=True)
|
||||||
|
assert rn[0].astext() == 'py3k:module2'
|
||||||
|
|
||||||
# prefix given, target not found and nonexplicit title: prefix is stripped
|
# prefix given, target not found and nonexplicit title: prefix is stripped
|
||||||
refnode['reftarget'] = 'py3k:unknown'
|
node, contnode = fake_node('py', 'mod', 'py3k:unknown', 'py3k:unknown',
|
||||||
refnode['refexplicit'] = False
|
refexplicit=False)
|
||||||
contnode[0] = nodes.Text('py3k:unknown')
|
rn = missing_reference(app, app.env, node, contnode)
|
||||||
rn = missing_reference(app, app.env, refnode, contnode)
|
|
||||||
assert rn is None
|
assert rn is None
|
||||||
assert contnode[0].astext() == 'unknown'
|
assert contnode[0].astext() == 'unknown'
|
||||||
|
|
||||||
# prefix given, target not found and explicit title: nothing is changed
|
# prefix given, target not found and explicit title: nothing is changed
|
||||||
refnode['reftarget'] = 'py3k:unknown'
|
node, contnode = fake_node('py', 'mod', 'py3k:unknown', 'py3k:unknown',
|
||||||
refnode['refexplicit'] = True
|
refexplicit=True)
|
||||||
contnode[0] = nodes.Text('py3k:unknown')
|
rn = missing_reference(app, app.env, node, contnode)
|
||||||
rn = missing_reference(app, app.env, refnode, contnode)
|
|
||||||
assert rn is None
|
assert rn is None
|
||||||
assert contnode[0].astext() == 'py3k:unknown'
|
assert contnode[0].astext() == 'py3k:unknown'
|
||||||
|
|||||||
Reference in New Issue
Block a user