Merge pull request #4591 from tk0miya/autosectionlabel-smart-quotes-fix

Fix #4027: use rawsource in autosectionlabel extension
This commit is contained in:
Takeshi KOMIYA 2018-02-11 14:21:42 +09:00 committed by GitHub
commit 4a96f85119
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 2 deletions

View File

@ -23,6 +23,8 @@ Bugs fixed
* #4223: doctest: failing tests reported in wrong file, at wrong line
* i18n: message catalogs are not compiled if specific filenames are given for
``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
--------

View File

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

View File

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

View File

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