Fix #1603 :numref: doesn't work correctly when label contain underscore

If label contains underscore, the underscores are replaced with hyphens on normalization.
:numref: confuses the normalization with explicit notation.
This fix uses `target` variable insted of labelid to check the role is explicit or not.
This commit is contained in:
tk0miya 2014-10-27 11:02:54 +09:00
parent b5430045ae
commit 88103c112a
4 changed files with 12 additions and 12 deletions

View File

@ -628,15 +628,15 @@ class StandardDomain(Domain):
return contnode
try:
target = env.get_doctree(docname).ids[labelid]
figtype = get_figtype(target)
figure_id = target['ids'][0]
target_node = env.get_doctree(docname).ids[labelid]
figtype = get_figtype(target_node)
figure_id = target_node['ids'][0]
fignumber = env.toc_fignumbers[docname][figtype][figure_id]
except (KeyError, IndexError):
return None
title = contnode.astext()
if labelid == title:
if target == title:
prefix = env.config.numfig_format.get(figtype, '')
title = prefix.replace('%s', '#')
newtitle = prefix % '.'.join(map(str, fignumber))

View File

@ -17,7 +17,7 @@ test-tocdepth
should be Fig.2
.. _table1:
.. _table-1:
.. csv-table:: should be Table 1
:header-rows: 0
@ -29,7 +29,7 @@ test-tocdepth
hello,world
.. _code1:
.. _code_1:
.. code-block:: python
:caption: should be List 1
@ -44,7 +44,7 @@ test-tocdepth
* Fig.1 is :numref:`fig1`
* Fig.2.2 is :numref:`Figure# <fig22>`
* Table.1 is :numref:`table1`
* Table.1 is :numref:`table-1`
* Table.2.2 is :numref:`Table:# <table22>`
* List.1 is :numref:`code1`
* List.1 is :numref:`code_1`
* List.2.2 is :numref:`Code-# <code22>`

View File

@ -476,9 +476,9 @@ def test_numfig_disabled(app, status, warning):
"span[@class='caption-number']", None, True),
(".//li/code/span", '^fig1$', True),
(".//li/code/span", '^Figure#$', True),
(".//li/code/span", '^table1$', True),
(".//li/code/span", '^table-1$', True),
(".//li/code/span", '^Table:#$', True),
(".//li/code/span", '^code1$', True),
(".//li/code/span", '^code_1$', True),
(".//li/code/span", '^Code-#$', True),
],
'foo.html': [

View File

@ -103,9 +103,9 @@ def test_numref(app, status, warning):
print(warning.getvalue())
assert '\\ref{index:fig1}' in result
assert '\\ref{baz:fig22}' in result
assert '\\ref{index:table1}' in result
assert '\\ref{index:table-1}' in result
assert '\\ref{baz:table22}' in result
assert '\\ref{index:code1}' in result
assert '\\ref{index:code-1}' in result
assert '\\ref{baz:code22}' in result