Fix #2931: code-block directive with same :caption: causes warning of duplicate target

This commit is contained in:
Takeshi KOMIYA 2016-09-17 18:13:17 +09:00
parent 98886d3e07
commit cfddf17d35
4 changed files with 12 additions and 11 deletions

View File

@ -48,6 +48,9 @@ Incompatible changes
Use `Sphinx.set_translator()` API instead.
* Drop python 2.6 and 3.3 support
* Drop epub3 builder's ``epub3_page_progression_direction`` option (use ``epub3_writing_mode``).
* #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.
Features added
--------------

View File

@ -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:
@ -340,7 +339,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:

View File

@ -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 <name *test* rb>` and :ref:`Python <name **test** py>`.

View File

@ -56,7 +56,7 @@ def test_code_block_caption_html(app, status, warning):
caption = (u'<div class="code-block-caption">'
u'<span class="caption-number">Listing 1 </span>'
u'<span class="caption-text">caption <em>test</em> rb'
u'</span><a class="headerlink" href="#caption-test-rb" '
u'</span><a class="headerlink" href="#id1" '
u'title="Permalink to this code">\xb6</a></div>')
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{caption \\sphinxstyleemphasis{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
@ -244,7 +244,7 @@ def test_literalinclude_caption_html(app, status, warning):
caption = (u'<div class="code-block-caption">'
u'<span class="caption-number">Listing 2 </span>'
u'<span class="caption-text">caption <strong>test</strong> py'
u'</span><a class="headerlink" href="#caption-test-py" '
u'</span><a class="headerlink" href="#id2" '
u'title="Permalink to this code">\xb6</a></div>')
assert caption in html
@ -254,9 +254,9 @@ def test_literalinclude_caption_latex(app, status, warning):
app.builder.build('index')
latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstylestrong{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