mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
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:
parent
b5430045ae
commit
88103c112a
@ -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))
|
||||
|
@ -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>`
|
||||
|
@ -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': [
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user