diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-03-02 18:37:20 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-03-02 18:37:20 +0900 |
commit | ac9e9c0745f0001b3db30611a9a5c298634c3e08 (patch) | |
tree | 7a976fe0ad7f38c1ac182a61580982193e9d58cb | |
parent | 245b464fac15a0fa2a2ce5ba9e23f032c311b68a (diff) | |
parent | be971c6d385b42524e0660f788abf6399877bc30 (diff) | |
download | sphinx-git-ac9e9c0745f0001b3db30611a9a5c298634c3e08.tar.gz |
Merge branch '1.8' into 2.0
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | sphinx/ext/doctest.py | 30 | ||||
-rw-r--r-- | sphinx/ext/graphviz.py | 4 | ||||
-rw-r--r-- | sphinx/writers/latex.py | 12 | ||||
-rw-r--r-- | tests/roots/test-images/index.rst | 7 | ||||
-rw-r--r-- | tests/test_build_latex.py | 14 |
6 files changed, 54 insertions, 17 deletions
@@ -287,8 +287,12 @@ Bugs fixed * LaTeX: Remove extraneous space after author names on PDF title page (refs: #6004) * #6026: LaTeX: A cross reference to definition list does not work * #6046: LaTeX: ``TypeError`` is raised when invalid latex_elements given +* #6067: LaTeX: images having a target are concatenated to next line +* #6067: LaTeX: images having a target are not aligned even if specified * #6019: imgconverter: Including multipage PDF fails * #6047: autodoc: ``autofunction`` emits a warning for method objects +* #6028: graphviz: Ensure the graphviz filenames are reproducible +* #6068: doctest: ``skipif`` option may remove the code block from documentation Testing -------- diff --git a/sphinx/ext/doctest.py b/sphinx/ext/doctest.py index 23f3063cd..a47d05b55 100644 --- a/sphinx/ext/doctest.py +++ b/sphinx/ext/doctest.py @@ -83,16 +83,6 @@ class TestDirective(SphinxDirective): def run(self): # type: () -> List[nodes.Node] - if 'skipif' in self.options: - condition = self.options['skipif'] - context = {} # type: Dict[str, Any] - if self.config.doctest_global_setup: - exec(self.config.doctest_global_setup, context) - should_skip = eval(condition, context) - if self.config.doctest_global_cleanup: - exec(self.config.doctest_global_cleanup, context) - if should_skip: - return [] # use ordinary docutils nodes for test code: they get special attributes # so that our builder recognizes them, and the other builders are happy. code = '\n'.join(self.content) @@ -160,6 +150,8 @@ class TestDirective(SphinxDirective): self.state.document.reporter.warning( __("'%s' is not a valid pyversion option") % spec, line=self.lineno) + if 'skipif' in self.options: + node['skipif'] = self.options['skipif'] return [node] @@ -404,6 +396,20 @@ Doctest summary return node.line - 1 return None + def skipped(self, node): + # type: (nodes.Element) -> bool + if 'skipif' not in node: + return False + else: + condition = node['skipif'] + context = {} # type: Dict[str, Any] + if self.config.doctest_global_setup: + exec(self.config.doctest_global_setup, context) + should_skip = eval(condition, context) + if self.config.doctest_global_cleanup: + exec(self.config.doctest_global_cleanup, context) + return should_skip + def test_doc(self, docname, doctree): # type: (str, nodes.Node) -> None groups = {} # type: Dict[str, TestGroup] @@ -429,8 +435,10 @@ Doctest summary # type: (nodes.Node) -> bool return isinstance(node, (nodes.literal_block, nodes.comment)) \ and 'testnodetype' in node - for node in doctree.traverse(condition): # type: nodes.Element + if self.skipped(node): + continue + source = node['test'] if 'test' in node else node.astext() filename = self.get_filename_for_node(node, docname) line_number = self.get_line_number(node) diff --git a/sphinx/ext/graphviz.py b/sphinx/ext/graphviz.py index 9827d8531..c602869cd 100644 --- a/sphinx/ext/graphviz.py +++ b/sphinx/ext/graphviz.py @@ -196,9 +196,7 @@ class GraphvizSimple(SphinxDirective): node = graphviz() node['code'] = '%s %s {\n%s\n}\n' % \ (self.name, self.arguments[0], '\n'.join(self.content)) - node['options'] = { - 'docname': path.splitext(self.state.document.current_source)[0], - } + node['options'] = {'docname': self.env.docname} if 'graphviz_dot' in self.options: node['options']['graphviz_dot'] = self.options['graphviz_dot'] if 'alt' in self.options: diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 9ee51f8aa..c5be44b18 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1533,7 +1533,11 @@ class LaTeXTranslator(SphinxTranslator): # in reverse order post = [] # type: List[str] include_graphics_options = [] - is_inline = self.is_inline(node) + has_hyperlink = isinstance(node.parent, nodes.reference) + if has_hyperlink: + is_inline = self.is_inline(node.parent) + else: + is_inline = self.is_inline(node) if 'width' in attrs: if 'scale' in attrs: w = self.latex_image_length(attrs['width'], attrs['scale']) @@ -1575,7 +1579,7 @@ class LaTeXTranslator(SphinxTranslator): if self.in_parsed_literal: pre.append('{\\sphinxunactivateextrasandspace ') post.append('}') - if not is_inline: + if not is_inline and not has_hyperlink: pre.append('\n\\noindent') post.append('\n') pre.reverse() @@ -1863,6 +1867,8 @@ class LaTeXTranslator(SphinxTranslator): for id in node.get('ids'): anchor = not self.in_caption self.body += self.hypertarget(id, anchor=anchor) + if not self.is_inline(node): + self.body.append('\n') uri = node.get('refuri', '') if not uri and node.get('refid'): uri = '%' + self.curfilestack[-1] + '#' + node['refid'] @@ -1916,6 +1922,8 @@ class LaTeXTranslator(SphinxTranslator): def depart_reference(self, node): # type: (nodes.Element) -> None self.body.append(self.context.pop()) + if not self.is_inline(node): + self.body.append('\n') def visit_number_reference(self, node): # type: (nodes.Element) -> None diff --git a/tests/roots/test-images/index.rst b/tests/roots/test-images/index.rst index d1478fab1..67b742b27 100644 --- a/tests/roots/test-images/index.rst +++ b/tests/roots/test-images/index.rst @@ -15,6 +15,13 @@ test-image .. image:: testimäge.png +.. image:: rimg.png + :target: https://www.sphinx-doc.org/ + +.. image:: rimg.png + :align: center + :target: https://www.python.org/ + .. a remote image .. image:: https://www.python.org/static/img/python-logo.png diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 0cafdadd7..7772c9faa 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -1220,16 +1220,28 @@ def test_latex_raw_directive(app, status, warning): @pytest.mark.sphinx('latex', testroot='images') -def test_latex_remote_images(app, status, warning): +def test_latex_images(app, status, warning): app.builder.build_all() result = (app.outdir / 'python.tex').text(encoding='utf8') + + # images are copied assert '\\sphinxincludegraphics{{python-logo}.png}' in result assert (app.outdir / 'python-logo.png').exists() + + # not found images assert '\\sphinxincludegraphics{{NOT_EXIST}.PNG}' not in result assert ('WARNING: Could not fetch remote image: ' 'http://example.com/NOT_EXIST.PNG [404]' in warning.getvalue()) + # an image having target + assert ('\\sphinxhref{https://www.sphinx-doc.org/}' + '{\\sphinxincludegraphics{{rimg}.png}}\n\n' in result) + + # a centerized image having target + assert ('\\sphinxhref{https://www.python.org/}{{\\hspace*{\\fill}' + '\\sphinxincludegraphics{{rimg}.png}\\hspace*{\\fill}}}\n\n' in result) + @pytest.mark.sphinx('latex', testroot='latex-index') def test_latex_index(app, status, warning): |