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

This commit is contained in:
Takeshi KOMIYA 2016-09-17 18:28:55 +09:00
parent 669b5f1736
commit 82c153ffd2
4 changed files with 12 additions and 11 deletions

View File

@ -19,6 +19,9 @@ Bugs fixed
* #2873: code-block overflow in latex (due to commas) * #2873: code-block overflow in latex (due to commas)
* #1060, #2056: sphinx.ext.intersphinx: broken links are generated if relative * #1060, #2056: sphinx.ext.intersphinx: broken links are generated if relative
paths are used in `intersphinx_mapping` 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) Release 1.4.6 (released Aug 20, 2016)
===================================== =====================================

View File

@ -133,7 +133,6 @@ class CodeBlock(Directive):
caption = self.options.get('caption') caption = self.options.get('caption')
if caption: if caption:
self.options.setdefault('name', nodes.fully_normalize_name(caption))
try: try:
literal = container_wrapper(self, literal, caption) literal = container_wrapper(self, literal, caption)
except ValueError as exc: except ValueError as exc:
@ -344,7 +343,6 @@ class LiteralInclude(Directive):
if caption is not None: if caption is not None:
if not caption: if not caption:
caption = self.arguments[0] caption = self.arguments[0]
self.options.setdefault('name', nodes.fully_normalize_name(caption))
try: try:
retnode = container_wrapper(self, retnode, caption) retnode = container_wrapper(self, retnode, caption)
except ValueError as exc: except ValueError as exc:

View File

@ -4,7 +4,7 @@ Caption
References 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>`. 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">' caption = (u'<div class="code-block-caption">'
u'<span class="caption-number">Listing 1 </span>' u'<span class="caption-number">Listing 1 </span>'
u'<span class="caption-text">caption <em>test</em> rb' 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>') u'title="Permalink to this code">\xb6</a></div>')
assert caption in html assert caption in html
@ -66,9 +66,9 @@ def test_code_block_caption_latex(app, status, warning):
app.builder.build_all() app.builder.build_all()
latex = (app.outdir / 'Python.tex').text(encoding='utf-8') latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
caption = '\\sphinxSetupCaptionForVerbatim{literal-block}{caption \\emph{test} rb}' caption = '\\sphinxSetupCaptionForVerbatim{literal-block}{caption \\emph{test} rb}'
label = '\\def\\sphinxLiteralBlockLabel{\\label{caption:caption-test-rb}}' label = '\\def\\sphinxLiteralBlockLabel{\\label{caption:id1}}'
link = '\hyperref[caption:caption-test-rb]' \ link = '\hyperref[caption:name-test-rb]' \
'{Listing \\ref{caption:caption-test-rb}}' '{Listing \\ref{caption:name-test-rb}}'
assert caption in latex assert caption in latex
assert label in latex assert label in latex
assert link in latex assert link in latex
@ -243,7 +243,7 @@ def test_literalinclude_caption_html(app, status, warning):
caption = (u'<div class="code-block-caption">' caption = (u'<div class="code-block-caption">'
u'<span class="caption-number">Listing 2 </span>' u'<span class="caption-number">Listing 2 </span>'
u'<span class="caption-text">caption <strong>test</strong> py' 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>') u'title="Permalink to this code">\xb6</a></div>')
assert caption in html assert caption in html
@ -253,9 +253,9 @@ def test_literalinclude_caption_latex(app, status, warning):
app.builder.build('index') app.builder.build('index')
latex = (app.outdir / 'Python.tex').text(encoding='utf-8') latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
caption = '\\sphinxSetupCaptionForVerbatim{literal-block}{caption \\textbf{test} py}' caption = '\\sphinxSetupCaptionForVerbatim{literal-block}{caption \\textbf{test} py}'
label = '\\def\\sphinxLiteralBlockLabel{\\label{caption:caption-test-py}}' label = '\\def\\sphinxLiteralBlockLabel{\\label{caption:id2}}'
link = '\hyperref[caption:caption-test-py]' \ link = '\hyperref[caption:name-test-py]' \
'{Listing \\ref{caption:caption-test-py}}' '{Listing \\ref{caption:name-test-py}}'
assert caption in latex assert caption in latex
assert label in latex assert label in latex
assert link in latex assert link in latex