Use rawsource in autosectionlabel

Fixes #4027.
This commit is contained in:
Kit La Touche 2017-09-05 21:56:11 -06:00 committed by Takeshi KOMIYA
parent 87a9a86de9
commit f21b9d5892
5 changed files with 19 additions and 2 deletions

View File

@ -23,6 +23,8 @@ Bugs fixed
* #4223: doctest: failing tests reported in wrong file, at wrong line * #4223: doctest: failing tests reported in wrong file, at wrong line
* i18n: message catalogs are not compiled if specific filenames are given for * i18n: message catalogs are not compiled if specific filenames are given for
``sphinx-build`` as arguments (refs: #4560) ``sphinx-build`` as arguments (refs: #4560)
* #4027: sphinx.ext.autosectionlabel now expects labels to be the same as they
are in the raw source; no smart quotes, nothig fancy.
Testing Testing
-------- --------

View File

@ -30,9 +30,10 @@ def register_sections_as_label(app, document):
labelid = node['ids'][0] labelid = node['ids'][0]
docname = app.env.docname docname = app.env.docname
if app.config.autosectionlabel_prefix_document: if app.config.autosectionlabel_prefix_document:
name = nodes.fully_normalize_name(docname + ':' + node[0].astext()) name = nodes.fully_normalize_name(
docname + ':' + node[0].rawsource)
else: else:
name = nodes.fully_normalize_name(node[0].astext()) name = nodes.fully_normalize_name(node[0].rawsource)
sectname = clean_astext(node[0]) sectname = clean_astext(node[0])
if name in labels: if name in labels:

View File

@ -15,6 +15,9 @@ For Windows users
For UNIX users For UNIX users
-------------- --------------
This one's got an apostrophe
----------------------------
References References
========== ==========
@ -23,3 +26,4 @@ References
* :ref:`index:Installation` * :ref:`index:Installation`
* :ref:`index:For Windows users` * :ref:`index:For Windows users`
* :ref:`index:For UNIX users` * :ref:`index:For UNIX users`
* :ref:`index:This one's got an apostrophe`

View File

@ -15,6 +15,9 @@ For Windows users
For UNIX users For UNIX users
-------------- --------------
This one's got an apostrophe
----------------------------
References References
========== ==========
@ -23,3 +26,4 @@ References
* :ref:`Installation` * :ref:`Installation`
* :ref:`For Windows users` * :ref:`For Windows users`
* :ref:`For UNIX users` * :ref:`For UNIX users`
* :ref:`This one's got an apostrophe`

View File

@ -35,6 +35,12 @@ def test_autosectionlabel_html(app, status, warning):
'<span class="std std-ref">For UNIX users</span></a></li>') '<span class="std std-ref">For UNIX users</span></a></li>')
assert re.search(html, content, re.S) assert re.search(html, content, re.S)
html = ('<li><a class="reference internal" '
'href="#this-one-s-got-an-apostrophe">'
'<span class="std std-ref">This ones got an apostrophe'
'</span></a></li>')
assert re.search(html, content, re.S)
# Re-use test definition from above, just change the test root directory # Re-use test definition from above, just change the test root directory
@pytest.mark.sphinx('html', testroot='ext-autosectionlabel-prefix-document') @pytest.mark.sphinx('html', testroot='ext-autosectionlabel-prefix-document')