|
From: <mi...@us...> - 2025-04-14 08:54:19
|
Revision: 10085
http://sourceforge.net/p/docutils/code/10085
Author: milde
Date: 2025-04-14 08:54:01 +0000 (Mon, 14 Apr 2025)
Log Message:
-----------
Test "clickable" image in a figure and fix LaTeX writer.
Add a "target" option to a "figure" directive in the standard.rst
functional test file to test handling and validation of an `<image>` wrapped
in a `<reference>` in a `<figure>`.
Fix the LaTeX writer's handling of images nested in a `<reference>`:
* Default to center-aligned images in a figure also if it is "clickable".
* Fix newlines in output of visit_image() and visit_reference().
* Add test cases to the LaTeX writer test.
Modified Paths:
--------------
trunk/docutils/docutils/writers/latex2e/__init__.py
trunk/docutils/test/functional/expected/latex_memoir.tex
trunk/docutils/test/functional/expected/standalone_rst_docutils_xml.xml
trunk/docutils/test/functional/expected/standalone_rst_html4css1.html
trunk/docutils/test/functional/expected/standalone_rst_html5.html
trunk/docutils/test/functional/expected/standalone_rst_latex.tex
trunk/docutils/test/functional/expected/standalone_rst_pseudoxml.txt
trunk/docutils/test/functional/expected/standalone_rst_xetex.tex
trunk/docutils/test/functional/input/data/standard.rst
trunk/docutils/test/test_writers/test_latex2e.py
Modified: trunk/docutils/docutils/writers/latex2e/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/latex2e/__init__.py 2025-04-14 08:53:31 UTC (rev 10084)
+++ trunk/docutils/docutils/writers/latex2e/__init__.py 2025-04-14 08:54:01 UTC (rev 10085)
@@ -2463,7 +2463,9 @@
# alignment defaults:
if 'align' not in attrs:
# Set default align of image in a figure to 'center'
- if isinstance(node.parent, nodes.figure):
+ if (isinstance(node.parent, nodes.figure)
+ or isinstance(node.parent, nodes.reference)
+ and isinstance(node.parent.parent, nodes.figure)):
attrs['align'] = 'center'
self.set_align_from_classes(node)
# pre- and postfix (prefix inserted in reverse order)
@@ -2470,6 +2472,8 @@
pre = []
post = []
include_graphics_options = []
+ if isinstance(node.parent, nodes.reference):
+ pre.append(self.out.pop()) # move \href behind alignment code
align_codes = {
# inline images: by default latex aligns the bottom.
'bottom': ('', ''),
@@ -2877,6 +2881,8 @@
ord('%'): '\\%',
ord('\\'): '\\\\',
}
+ if not (self.is_inline(node) or isinstance(node.parent, nodes.figure)):
+ self.out.append('\n')
# external reference (URL)
if 'refuri' in node:
href = str(node['refuri']).translate(special_chars)
@@ -2897,8 +2903,6 @@
href = self.document.nameids[node['refname']]
else:
raise AssertionError('Unknown reference.')
- if not self.is_inline(node):
- self.out.append('\n')
if self.reference_label:
self.out.append('\\%s{%s}' %
(self.reference_label, href.replace('#', '')))
@@ -2907,7 +2911,7 @@
def depart_reference(self, node) -> None:
self.out.append('}')
- if not self.is_inline(node):
+ if not (self.is_inline(node) or isinstance(node.parent, nodes.figure)):
self.out.append('\n')
def visit_revision(self, node) -> None:
Modified: trunk/docutils/test/functional/expected/latex_memoir.tex
===================================================================
--- trunk/docutils/test/functional/expected/latex_memoir.tex 2025-04-14 08:53:31 UTC (rev 10084)
+++ trunk/docutils/test/functional/expected/latex_memoir.tex 2025-04-14 08:54:01 UTC (rev 10085)
@@ -870,7 +870,7 @@
\begin{DUclass}{figclass1}
\begin{DUclass}{figclass2}
\begin{figure}
-\noindent\makebox[\linewidth][c]{\includegraphics[width=258bp]{../../../docs/user/rst/images/title.png}}
+\noindent\makebox[\linewidth][c]{\href{https://docutils.sourceforge.io/rst.html}{\includegraphics[width=258bp]{../../../docs/user/rst/images/title.png}}}
\caption{Plaintext markup syntax and parser system.}
\begin{DUlegend}
\setlength{\DUtablewidth}{\linewidth}%
Modified: trunk/docutils/test/functional/expected/standalone_rst_docutils_xml.xml
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_docutils_xml.xml 2025-04-14 08:53:31 UTC (rev 10084)
+++ trunk/docutils/test/functional/expected/standalone_rst_docutils_xml.xml 2025-04-14 08:54:01 UTC (rev 10085)
@@ -848,7 +848,7 @@
media, figures might float to a different position if this helps the page
layout.</paragraph>
<figure classes="figclass1 figclass2">
- <image alt="reStructuredText, the markup syntax" classes="class1 class2" uri="../../../docs/user/rst/images/title.png" width="258"></image>
+ <reference refuri="https://docutils.sourceforge.io/rst.html"><image alt="reStructuredText, the markup syntax" classes="class1 class2" uri="../../../docs/user/rst/images/title.png" width="258"></image></reference>
<caption>Plaintext markup syntax and parser system.</caption>
<legend>
<table>
Modified: trunk/docutils/test/functional/expected/standalone_rst_html4css1.html
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_html4css1.html 2025-04-14 08:53:31 UTC (rev 10084)
+++ trunk/docutils/test/functional/expected/standalone_rst_html4css1.html 2025-04-14 08:54:01 UTC (rev 10085)
@@ -617,7 +617,9 @@
media, figures might float to a different position if this helps the page
layout.</p>
<div class="figclass1 figclass2 figure">
+<a class="reference external image-reference" href="https://docutils.sourceforge.io/rst.html">
<img alt="reStructuredText, the markup syntax" class="class1 class2" src="../../../docs/user/rst/images/title.png" style="width: 258px;" />
+</a>
<p class="caption">Plaintext markup syntax and parser system.</p>
<div class="legend">
<table border="1" class="docutils">
Modified: trunk/docutils/test/functional/expected/standalone_rst_html5.html
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_html5.html 2025-04-14 08:53:31 UTC (rev 10084)
+++ trunk/docutils/test/functional/expected/standalone_rst_html5.html 2025-04-14 08:54:01 UTC (rev 10085)
@@ -614,7 +614,9 @@
media, figures might float to a different position if this helps the page
layout.</p>
<figure class="figclass1 figclass2">
+<a class="reference external image-reference" href="https://docutils.sourceforge.io/rst.html">
<img alt="reStructuredText, the markup syntax" class="class1 class2" src="../../../docs/user/rst/images/title.png" width="258" />
+</a>
<figcaption>
<p>Plaintext markup syntax and parser system.</p>
<div class="legend">
Modified: trunk/docutils/test/functional/expected/standalone_rst_latex.tex
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_latex.tex 2025-04-14 08:53:31 UTC (rev 10084)
+++ trunk/docutils/test/functional/expected/standalone_rst_latex.tex 2025-04-14 08:54:01 UTC (rev 10085)
@@ -864,7 +864,7 @@
\begin{DUclass}{figclass1}
\begin{DUclass}{figclass2}
\begin{figure}
-\noindent\makebox[\linewidth][c]{\includegraphics[width=258bp]{../../../docs/user/rst/images/title.png}}
+\noindent\makebox[\linewidth][c]{\href{https://docutils.sourceforge.io/rst.html}{\includegraphics[width=258bp]{../../../docs/user/rst/images/title.png}}}
\caption{Plaintext markup syntax and parser system.}
\begin{DUlegend}
\setlength{\DUtablewidth}{\linewidth}%
Modified: trunk/docutils/test/functional/expected/standalone_rst_pseudoxml.txt
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_pseudoxml.txt 2025-04-14 08:53:31 UTC (rev 10084)
+++ trunk/docutils/test/functional/expected/standalone_rst_pseudoxml.txt 2025-04-14 08:54:01 UTC (rev 10085)
@@ -1338,7 +1338,8 @@
media, figures might float to a different position if this helps the page
layout.
<figure classes="figclass1 figclass2">
- <image alt="reStructuredText, the markup syntax" classes="class1 class2" uri="../../../docs/user/rst/images/title.png" width="258">
+ <reference refuri="https://docutils.sourceforge.io/rst.html">
+ <image alt="reStructuredText, the markup syntax" classes="class1 class2" uri="../../../docs/user/rst/images/title.png" width="258">
<caption>
Plaintext markup syntax and parser system.
<legend>
@@ -2425,15 +2426,15 @@
<system_message level="1" line="476" source="functional/input/data/standard.rst" type="INFO">
<paragraph>
Hyperlink target "image-target-3" is not referenced.
- <system_message level="1" line="643" source="functional/input/data/standard.rst" type="INFO">
+ <system_message level="1" line="644" source="functional/input/data/standard.rst" type="INFO">
<paragraph>
Hyperlink target "target1" is not referenced.
- <system_message level="1" line="644" source="functional/input/data/standard.rst" type="INFO">
+ <system_message level="1" line="645" source="functional/input/data/standard.rst" type="INFO">
<paragraph>
Hyperlink target "target2" is not referenced.
- <system_message level="1" line="689" source="functional/input/data/standard.rst" type="INFO">
+ <system_message level="1" line="690" source="functional/input/data/standard.rst" type="INFO">
<paragraph>
Hyperlink target "docutils" is not referenced.
- <system_message level="1" line="855" source="functional/input/data/standard.rst" type="INFO">
+ <system_message level="1" line="856" source="functional/input/data/standard.rst" type="INFO">
<paragraph>
Hyperlink target "hyperlink targets" is not referenced.
Modified: trunk/docutils/test/functional/expected/standalone_rst_xetex.tex
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_xetex.tex 2025-04-14 08:53:31 UTC (rev 10084)
+++ trunk/docutils/test/functional/expected/standalone_rst_xetex.tex 2025-04-14 08:54:01 UTC (rev 10085)
@@ -889,7 +889,7 @@
\begin{DUclass}{figclass1}
\begin{DUclass}{figclass2}
\begin{figure}
-\noindent\makebox[\linewidth][c]{\includegraphics[width=258bp]{../../../docs/user/rst/images/title.png}}
+\noindent\makebox[\linewidth][c]{\href{https://docutils.sourceforge.io/rst.html}{\includegraphics[width=258bp]{../../../docs/user/rst/images/title.png}}}
\caption{Plaintext markup syntax and parser system.}
\begin{DUlegend}
\setlength{\DUtablewidth}{\linewidth}%
Modified: trunk/docutils/test/functional/input/data/standard.rst
===================================================================
--- trunk/docutils/test/functional/input/data/standard.rst 2025-04-14 08:53:31 UTC (rev 10084)
+++ trunk/docutils/test/functional/input/data/standard.rst 2025-04-14 08:54:01 UTC (rev 10085)
@@ -526,6 +526,7 @@
:figclass: figclass1 figclass2
:class: class1 class2
:alt: reStructuredText, the markup syntax
+ :target: https://docutils.sourceforge.io/rst.html
:width: 258
Plaintext markup syntax and parser system.
Modified: trunk/docutils/test/test_writers/test_latex2e.py
===================================================================
--- trunk/docutils/test/test_writers/test_latex2e.py 2025-04-14 08:53:31 UTC (rev 10084)
+++ trunk/docutils/test/test_writers/test_latex2e.py 2025-04-14 08:54:01 UTC (rev 10085)
@@ -129,9 +129,29 @@
Foo (some raw text)
same paragraph.
"""],
+# images and figures
+["""
+.. image:: larch-mini.jpg
+ :target: larch.jpg
+ :align: center
+""",
+r"""
+\noindent\makebox[\linewidth][c]{\href{larch.jpg}{\includegraphics{larch-mini.jpg}}}
+"""],
+["""\
+.. figure:: larch-mini.jpg
+ :target: larch.jpg
+
+ The larch
+""",
+r"""
+\begin{figure}
+\noindent\makebox[\linewidth][c]{\href{larch.jpg}{\includegraphics{larch-mini.jpg}}}
+\caption{The larch}
+\end{figure}
+"""],
])
-
samples['latex_sectnum'] = ({'sectnum_xform': False}, [
["""\
.. sectnum::
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|