diff --git a/sphinx/ext/autosectionlabel.py b/sphinx/ext/autosectionlabel.py index a5e22dfd5..6a3ff1422 100644 --- a/sphinx/ext/autosectionlabel.py +++ b/sphinx/ext/autosectionlabel.py @@ -29,11 +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].rawsource) + name = nodes.fully_normalize_name(docname + ':' + ref_name) else: - name = nodes.fully_normalize_name(node[0].rawsource) + name = nodes.fully_normalize_name(ref_name) sectname = clean_astext(node[0]) if name in labels: diff --git a/tests/test_ext_autosectionlabel.py b/tests/test_ext_autosectionlabel.py index b2b3685d8..fafeaf1ed 100644 --- a/tests/test_ext_autosectionlabel.py +++ b/tests/test_ext_autosectionlabel.py @@ -9,6 +9,7 @@ :license: BSD, see LICENSE for details. """ +import os import re import pytest @@ -35,6 +36,16 @@ def test_autosectionlabel_html(app, status, warning): 'For UNIX users') assert re.search(html, content, re.S) + +@pytest.mark.skipif( + os.environ.get('DOCUTILS', None) not in ('0.13.1', '0.14'), + reason='Requires docutils >= 0.13.1', +) +@pytest.mark.sphinx('html', testroot='ext-autosectionlabel') +def test_autosectionlabel_html_apostrophe(app, status, warning): + app.builder.build_all() + + content = (app.outdir / 'index.html').text() html = ('
  • ' 'This one’s got an apostrophe' @@ -46,3 +57,13 @@ def test_autosectionlabel_html(app, status, warning): @pytest.mark.sphinx('html', testroot='ext-autosectionlabel-prefix-document') def test_autosectionlabel_prefix_document_html(app, status, warning): return test_autosectionlabel_html(app, status, warning) + + +# Re-use test definition from above, just change the test root directory +@pytest.mark.skipif( + os.environ.get('DOCUTILS', None) not in ('0.13.1', '0.14'), + reason='Requires docutils >= 0.13.1', +) +@pytest.mark.sphinx('html', testroot='ext-autosectionlabel-prefix-document') +def test_autosectionlabel_prefix_document_html_apostrophe(app, status, warning): + return test_autosectionlabel_html_apostrophe(app, status, warning)