Merge pull request #3605 from tk0miya/3594_support_block_level_raw_node_in_latex

Fix #3594: LaTeX: single raw directive has been considereed as block …
This commit is contained in:
Jean-François B 2017-04-08 21:52:36 +02:00 committed by GitHub
commit ebc376157c
6 changed files with 77 additions and 0 deletions

View File

@ -41,6 +41,7 @@ Incompatible changes
``xcolor`` packages should be used by extensions of Sphinx latex writer.
(refs #3550)
* ``Builder.env`` is not filled at instantiation
* #3594: LaTeX: single raw directive has been considereed as block level element
Features removed
----------------

View File

@ -1991,8 +1991,12 @@ class LaTeXTranslator(nodes.NodeVisitor):
def visit_raw(self, node):
# type: (nodes.Node) -> None
if not self.is_inline(node):
self.body.append('\n')
if 'latex' in node.get('format', '').split():
self.body.append(node.astext())
if not self.is_inline(node):
self.body.append('\n')
raise nodes.SkipNode
def visit_reference(self, node):

View File

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
master_doc = 'index'

View File

@ -0,0 +1,40 @@
test-directives-raw
===================
HTML
----
standard
^^^^^^^^
.. raw:: html
standalone raw directive (HTML)
with substitution
^^^^^^^^^^^^^^^^^
HTML: abc |HTML_RAW| ghi
.. |HTML_RAW| raw:: html
def
LaTeX
-----
standard
^^^^^^^^
.. raw:: latex
standalone raw directive (LaTeX)
with substitution
^^^^^^^^^^^^^^^^^
LaTeX: abc |LATEX_RAW| ghi
.. |LATEX_RAW| raw:: latex
def

View File

@ -1180,3 +1180,17 @@ def test_html_inventory(app):
'',
'http://example.com/index.html',
'The basic Sphinx documentation for testing')
@pytest.mark.sphinx('html', testroot='directives-raw')
def test_html_raw_directive(app, status, warning):
app.builder.build_all()
result = (app.outdir / 'index.html').text(encoding='utf8')
# standard case
assert 'standalone raw directive (HTML)' in result
assert 'standalone raw directive (LaTeX)' not in result
# with substitution
assert '<p>HTML: abc def ghi</p>' in result
assert '<p>LaTeX: abc ghi</p>' in result

View File

@ -1027,3 +1027,18 @@ def test_latex_table_complex_tables(app, status, warning):
'\\sphinxtablestrut{6}&\\sphinxtablestrut{4}&\ncell3-5\n'
'\\\\\n\\hline\n\\end{tabulary}\n'
in table)
@pytest.mark.sphinx('latex', testroot='directives-raw')
def test_latex_raw_directive(app, status, warning):
app.builder.build_all()
result = (app.outdir / 'Python.tex').text(encoding='utf8')
# standard case
assert 'standalone raw directive (HTML)' not in result
assert ('\\label{\\detokenize{index:id1}}\n'
'standalone raw directive (LaTeX)' in result)
# with substitution
assert 'HTML: abc ghi' in result
assert 'LaTeX: abc def ghi' in result