mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #2931: code-block directive with same :caption: causes warning of duplicate target
This commit is contained in:
parent
98886d3e07
commit
cfddf17d35
3
CHANGES
3
CHANGES
@ -48,6 +48,9 @@ Incompatible changes
|
|||||||
Use `Sphinx.set_translator()` API instead.
|
Use `Sphinx.set_translator()` API instead.
|
||||||
* Drop python 2.6 and 3.3 support
|
* Drop python 2.6 and 3.3 support
|
||||||
* Drop epub3 builder's ``epub3_page_progression_direction`` option (use ``epub3_writing_mode``).
|
* 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
|
Features added
|
||||||
--------------
|
--------------
|
||||||
|
@ -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:
|
||||||
@ -340,7 +339,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:
|
||||||
|
@ -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>`.
|
||||||
|
|
||||||
|
@ -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{caption \\sphinxstyleemphasis{test} rb}'
|
caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstyleemphasis{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
|
||||||
@ -244,7 +244,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
|
||||||
|
|
||||||
@ -254,9 +254,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{caption \\sphinxstylestrong{test} py}'
|
caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstylestrong{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
|
||||||
|
Loading…
Reference in New Issue
Block a user