From 82c153ffd2965fd56f1e51fd4b960014c5e4621b Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 17 Sep 2016 18:28:55 +0900 Subject: [PATCH] Fix #2931: code-block directive with same :caption: causes warning of duplicate target --- CHANGES | 3 +++ sphinx/directives/code.py | 2 -- tests/roots/test-directive-code/caption.rst | 2 +- tests/test_directive_code.py | 16 ++++++++-------- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGES b/CHANGES index b0fb61c83..f90cd2c48 100644 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,9 @@ Bugs fixed * #2873: code-block overflow in latex (due to commas) * #1060, #2056: sphinx.ext.intersphinx: broken links are generated if relative paths are used in `intersphinx_mapping` +* #2931: code-block directive with same :caption: causes warning of duplicate + target. Now `code-block` and `literalinclude` does not define hyperlink + target using its caption automatially. Release 1.4.6 (released Aug 20, 2016) ===================================== diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py index 8edfd61d7..35439ae39 100644 --- a/sphinx/directives/code.py +++ b/sphinx/directives/code.py @@ -133,7 +133,6 @@ class CodeBlock(Directive): caption = self.options.get('caption') if caption: - self.options.setdefault('name', nodes.fully_normalize_name(caption)) try: literal = container_wrapper(self, literal, caption) except ValueError as exc: @@ -344,7 +343,6 @@ class LiteralInclude(Directive): if caption is not None: if not caption: caption = self.arguments[0] - self.options.setdefault('name', nodes.fully_normalize_name(caption)) try: retnode = container_wrapper(self, retnode, caption) except ValueError as exc: diff --git a/tests/roots/test-directive-code/caption.rst b/tests/roots/test-directive-code/caption.rst index e8389b994..77c5c3811 100644 --- a/tests/roots/test-directive-code/caption.rst +++ b/tests/roots/test-directive-code/caption.rst @@ -4,7 +4,7 @@ Caption References ---------- -See :numref:`caption *test* rb` and :numref:`caption **test** py`. +See :numref:`name *test* rb` and :numref:`name **test** py`. See :ref:`Ruby ` and :ref:`Python `. diff --git a/tests/test_directive_code.py b/tests/test_directive_code.py index 5871f0321..8209e8f61 100644 --- a/tests/test_directive_code.py +++ b/tests/test_directive_code.py @@ -56,7 +56,7 @@ def test_code_block_caption_html(app, status, warning): caption = (u'
' u'Listing 1 ' u'caption test rb' - u'\xb6
') assert caption in html @@ -66,9 +66,9 @@ def test_code_block_caption_latex(app, status, warning): app.builder.build_all() latex = (app.outdir / 'Python.tex').text(encoding='utf-8') caption = '\\sphinxSetupCaptionForVerbatim{literal-block}{caption \\emph{test} rb}' - label = '\\def\\sphinxLiteralBlockLabel{\\label{caption:caption-test-rb}}' - link = '\hyperref[caption:caption-test-rb]' \ - '{Listing \\ref{caption:caption-test-rb}}' + label = '\\def\\sphinxLiteralBlockLabel{\\label{caption:id1}}' + link = '\hyperref[caption:name-test-rb]' \ + '{Listing \\ref{caption:name-test-rb}}' assert caption in latex assert label in latex assert link in latex @@ -243,7 +243,7 @@ def test_literalinclude_caption_html(app, status, warning): caption = (u'
' u'Listing 2 ' u'caption test py' - u'\xb6
') assert caption in html @@ -253,9 +253,9 @@ def test_literalinclude_caption_latex(app, status, warning): app.builder.build('index') latex = (app.outdir / 'Python.tex').text(encoding='utf-8') caption = '\\sphinxSetupCaptionForVerbatim{literal-block}{caption \\textbf{test} py}' - label = '\\def\\sphinxLiteralBlockLabel{\\label{caption:caption-test-py}}' - link = '\hyperref[caption:caption-test-py]' \ - '{Listing \\ref{caption:caption-test-py}}' + label = '\\def\\sphinxLiteralBlockLabel{\\label{caption:id2}}' + link = '\hyperref[caption:name-test-py]' \ + '{Listing \\ref{caption:name-test-py}}' assert caption in latex assert label in latex assert link in latex