mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Added Tests for latex(pdf) links to captioned or named literal blocks
As conf.py has now numfig = True, needed to modify accordingly test for links in html output. This topic branch fixes #2405, #2414, and also makes for latex(pdf) functional hyperlinks to named references, but only for literal blocks (code-block or literalinclude). modified: tests/roots/test-directive-code/caption.rst modified: tests/roots/test-directive-code/conf.py new file: tests/roots/test-directive-code/namedblocks.rst modified: tests/test_directive_code.py
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
Dedent
|
||||
======
|
||||
Caption
|
||||
=======
|
||||
|
||||
References
|
||||
----------
|
||||
|
||||
See :numref:`caption *test* rb` and :numref:`caption **test** py`.
|
||||
|
||||
See :ref:`Ruby <name *test* rb>` and :ref:`Python <name **test** py>`.
|
||||
|
||||
|
||||
Code blocks
|
||||
-----------
|
||||
@@ -19,3 +27,26 @@ Literal Include
|
||||
:language: python
|
||||
:caption: caption **test** py
|
||||
:lines: 10-11
|
||||
|
||||
|
||||
Named Code blocks
|
||||
-----------------
|
||||
|
||||
.. code-block:: ruby
|
||||
:name: name *test* rb
|
||||
:caption: caption *test* rbnamed
|
||||
|
||||
def ruby?
|
||||
false
|
||||
end
|
||||
|
||||
|
||||
Named Literal Include
|
||||
---------------------
|
||||
|
||||
.. literalinclude:: literal.inc
|
||||
:language: python
|
||||
:name: name **test** py
|
||||
:caption: caption **test** pynamed
|
||||
:lines: 10-11
|
||||
|
||||
|
||||
@@ -2,3 +2,5 @@
|
||||
|
||||
master_doc = 'index'
|
||||
exclude_patterns = ['_build']
|
||||
numfig = True
|
||||
|
||||
|
||||
28
tests/roots/test-directive-code/namedblocks.rst
Normal file
28
tests/roots/test-directive-code/namedblocks.rst
Normal file
@@ -0,0 +1,28 @@
|
||||
Named Blocks
|
||||
============
|
||||
|
||||
References to named blocks
|
||||
--------------------------
|
||||
|
||||
See :ref:`the ruby code <some ruby code>` and
|
||||
also :ref:`the python code <some python code>`.
|
||||
|
||||
|
||||
Named Code block
|
||||
----------------
|
||||
|
||||
.. code-block:: ruby
|
||||
:name: some ruby code
|
||||
|
||||
def ruby?
|
||||
false
|
||||
end
|
||||
|
||||
|
||||
Named Literal Include
|
||||
---------------------
|
||||
|
||||
.. literalinclude:: literal.inc
|
||||
:language: python
|
||||
:name: some python code
|
||||
|
||||
@@ -54,6 +54,7 @@ def test_code_block_caption_html(app, status, warning):
|
||||
app.builder.build(['caption'])
|
||||
html = (app.outdir / 'caption.html').text(encoding='utf-8')
|
||||
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'title="Permalink to this code">\xb6</a></div>')
|
||||
@@ -65,7 +66,28 @@ 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}}'
|
||||
assert caption in latex
|
||||
assert label in latex
|
||||
assert link in latex
|
||||
|
||||
|
||||
@with_app('latex', testroot='directive-code')
|
||||
def test_code_block_namedlink_latex(app, status, warning):
|
||||
app.builder.build_all()
|
||||
latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
|
||||
label1 = '\def\SphinxLiteralBlockLabel{\label{caption:name-test-rb}}'
|
||||
link1 = '\\hyperref[caption:name\\string-test\\string-rb]'\
|
||||
'{\\crossref{\\DUrole{std,std-ref}{Ruby}}'
|
||||
label2 = '\def\SphinxLiteralBlockLabel{\label{namedblocks:some-ruby-code}}'
|
||||
link2 = '\\hyperref[namedblocks:some\\string-ruby\\string-code]'\
|
||||
'{\\crossref{\\DUrole{std,std-ref}{the ruby code}}}'
|
||||
assert label1 in latex
|
||||
assert link1 in latex
|
||||
assert label2 in latex
|
||||
assert link2 in latex
|
||||
|
||||
|
||||
@with_app('xml', testroot='directive-code')
|
||||
@@ -219,6 +241,7 @@ def test_literalinclude_caption_html(app, status, warning):
|
||||
app.builder.build('index')
|
||||
html = (app.outdir / 'caption.html').text(encoding='utf-8')
|
||||
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'title="Permalink to this code">\xb6</a></div>')
|
||||
@@ -230,7 +253,28 @@ 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}}'
|
||||
assert caption in latex
|
||||
assert label in latex
|
||||
assert link in latex
|
||||
|
||||
|
||||
@with_app('latex', testroot='directive-code')
|
||||
def test_literalinclude_namedlink_latex(app, status, warning):
|
||||
app.builder.build('index')
|
||||
latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
|
||||
label1 = '\def\SphinxLiteralBlockLabel{\label{caption:name-test-py}}'
|
||||
link1 = '\\hyperref[caption:name\\string-test\\string-py]'\
|
||||
'{\\crossref{\\DUrole{std,std-ref}{Python}}'
|
||||
label2 = '\def\SphinxLiteralBlockLabel{\label{namedblocks:some-python-code}}'
|
||||
link2 = '\\hyperref[namedblocks:some\\string-python\\string-code]'\
|
||||
'{\\crossref{\\DUrole{std,std-ref}{the python code}}}'
|
||||
assert label1 in latex
|
||||
assert link1 in latex
|
||||
assert label2 in latex
|
||||
assert link2 in latex
|
||||
|
||||
|
||||
@with_app('xml', testroot='directive-code')
|
||||
|
||||
Reference in New Issue
Block a user