From 7ca11ce1b659d85707f5fdc4558f514893bddd38 Mon Sep 17 00:00:00 2001 From: milde Date: Wed, 22 Mar 2017 14:29:01 +0000 Subject: [PATCH] Improve and test "compound" handling in LaTeX. Test samples added to standard.txt allow inspection of the outcome of compound handling for all output formats. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@8052 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/docs/dev/todo.txt | 12 ++- docutils/docutils/writers/latex2e/__init__.py | 25 +++-- .../expected/standalone_rst_docutils_xml.xml | 93 ++++++++++++++---- .../expected/standalone_rst_html4css1.html | 86 +++++++++++++---- .../functional/expected/standalone_rst_html5.html | 79 ++++++++++++---- .../functional/expected/standalone_rst_latex.tex | 105 +++++++++++++++------ .../expected/standalone_rst_pseudoxml.txt | 105 +++++++++++++++++---- .../functional/expected/standalone_rst_xetex.tex | 105 +++++++++++++++------ docutils/test/functional/input/data/standard.txt | 73 +++++++++++--- 9 files changed, 536 insertions(+), 147 deletions(-) diff --git a/docutils/docs/dev/todo.txt b/docutils/docs/dev/todo.txt index d4d3787a7..2e51d4851 100644 --- a/docutils/docs/dev/todo.txt +++ b/docutils/docs/dev/todo.txt @@ -2349,6 +2349,14 @@ Bug fixes * File names of included graphics (see also `grffile` package). +* Paragraph following field-list or table in compound is indented. + + This is a problem with the current DUfieldlist definition and with + the use of "longtable" for tables. + See `LaTeX constructs and packages instead of re-implementations`_ for + alternatives. + + Generate clean and configurable LaTeX source ---------------------------------------------- @@ -2498,7 +2506,8 @@ Default layout Overriding: - * continue if the `compound paragraph`_ directive is used, or + * continue if the `compound paragraph`_ directive is used (as currently), + or * force a new paragraph with an empty comment. * Sidebar handling (environment with `framed`, `marginnote`, `wrapfig`, @@ -2552,7 +2561,6 @@ Tables * Add more classes or options, e.g. for - + column width set by latex, + horizontal alignment and rules. + long table vs. tabular (see next item). diff --git a/docutils/docutils/writers/latex2e/__init__.py b/docutils/docutils/writers/latex2e/__init__.py index 160757b13..5690384b8 100644 --- a/docutils/docutils/writers/latex2e/__init__.py +++ b/docutils/docutils/writers/latex2e/__init__.py @@ -1595,7 +1595,8 @@ class LaTeXTranslator(nodes.NodeVisitor): def duclass_open(self, node): """Open a group and insert declarations for class values.""" - self.out.append('\n') + if not isinstance(node.parent, nodes.compound): + self.out.append('\n') for cls in node['classes']: if cls.startswith('language-'): language = self.babel.language_name(cls[9:]) @@ -1808,18 +1809,20 @@ class LaTeXTranslator(nodes.NodeVisitor): pass def visit_comment(self, node): + if not isinstance(node.parent, nodes.compound): + self.out.append('\n') # Precede every line with a comment sign, wrap in newlines - self.out.append('\n%% %s\n' % node.astext().replace('\n', '\n% ')) + self.out.append('%% %s\n' % node.astext().replace('\n', '\n% ')) raise nodes.SkipNode def depart_comment(self, node): pass def visit_compound(self, node): + if isinstance(node.parent, nodes.compound): + self.out.append('\n') + node['classes'].insert(0, 'compound') self.duclass_open(node) - # TODO: remove/comment blank lines in content - # so that included lists, equations, figures, ... - # become part of the compound paragraph. def depart_compound(self, node): self.duclass_close(node) @@ -1859,7 +1862,7 @@ class LaTeXTranslator(nodes.NodeVisitor): pass def depart_definition(self, node): - self.out.append('\n') + self.out.append('\n') # TODO: just pass? def visit_definition_list(self, node): self.duclass_open(node) @@ -2382,8 +2385,10 @@ class LaTeXTranslator(nodes.NodeVisitor): include_graphics_options.append('width=%s' % self.to_latex_length(attrs['width'])) if not (self.is_inline(node) or - isinstance(node.parent, nodes.figure)): + isinstance(node.parent, (nodes.figure, nodes.compound))): pre.append('\n') + if not (self.is_inline(node) or + isinstance(node.parent, nodes.figure)): post.append('\n') pre.reverse() self.out.extend(pre) @@ -2653,12 +2658,12 @@ class LaTeXTranslator(nodes.NodeVisitor): def visit_paragraph(self, node): # insert blank line, unless - # * the paragraph is first in a list item, + # * the paragraph is first in a list item or compound, # * follows a non-paragraph node in a compound, # * is in a table with auto-width columns index = node.parent.index(node) - if (index == 0 and (isinstance(node.parent, nodes.list_item) or - isinstance(node.parent, nodes.description))): + if index == 0 and isinstance(node.parent, + (nodes.list_item, nodes.description, nodes.compound)): pass elif (index > 0 and isinstance(node.parent, nodes.compound) and not isinstance(node.parent[index - 1], nodes.paragraph) and diff --git a/docutils/test/functional/expected/standalone_rst_docutils_xml.xml b/docutils/test/functional/expected/standalone_rst_docutils_xml.xml index 4cff8805c..9c26d2335 100644 --- a/docutils/test/functional/expected/standalone_rst_docutils_xml.xml +++ b/docutils/test/functional/expected/standalone_rst_docutils_xml.xml @@ -1170,23 +1170,29 @@ Python-specific usage examples; begun with ">>>"
<generated classes="sectnum">2.14.7   </generated>Compound Paragraph + The compound directive is used to create a "compound paragraph", which + is a single logical paragraph containing multiple physical body + elements. For example: + + The 'rm' command is very dangerous. If you are logged + in as root and enter + cd / +rm -rf * + you will erase the entire contents of your file system. + + Test the handling and display of compound paragraphs: - Compound 1, paragraph 1. - Compound 1, paragraph 2. + Compound 2, paragraph 1, + compound 2, paragraph 2, - Compound 1, list item one. + list item 1, - Compound 1, list item two. + list item 2, - - Another compound statement: - - Compound 2, a literal block: - Compound 2, literal. - Compound 2, this is a test. + compound 2, paragraph 3. Compound 3, only consisting of one paragraph. @@ -1194,7 +1200,7 @@ Python-specific usage examples; begun with ">>>" Compound 4. This one starts with a literal block. - Compound 4, a paragraph. + Compound 4, paragraph following the literal block. Now something really perverted -- a nested compound block. This is just to test that it works at all; the results don't have to be @@ -1202,13 +1208,14 @@ This one starts with a literal block. Compound 5, block 1 (a paragraph). - Compound 6, block 2 in compound 5. + Compound 6 is block 2 in compound 5. Compound 6, another paragraph. Compound 5, block 3 (a paragraph). - Compound 7, with a table inside: + Compound 7, tests the inclusion of various block-level + elements in one logical paragraph. First a table, @@ -1237,8 +1244,62 @@ This one starts with a literal block.
- Compound 7, a paragraph after the table. - Compound 7, another paragraph. + followed by a paragraph. This physical paragraph is + actually a continuation of the paragraph before the table. It is followed + by + + a quote and + + + + an enumerated list, + + + a paragraph, + + + + + + + option list, + + + + a paragraph, + + + a field + + list, + + + + a paragraph, + + + a definition + + list, + + + + a paragraph, an image: + + a paragraph, + + a line + block, + + a paragraph followed by a comment, + this is a comment + a paragraph, a + + with content + + and the final paragraph of the compound 7.
@@ -1684,7 +1745,7 @@ Comments may contain non-ASCII characters: ä ö ü æ ø å Hyperlink target "docutils" is not referenced. - + Hyperlink target "hyperlink targets" is not referenced.
diff --git a/docutils/test/functional/expected/standalone_rst_html4css1.html b/docutils/test/functional/expected/standalone_rst_html4css1.html index aa5c71277..53e7a9de5 100644 --- a/docutils/test/functional/expected/standalone_rst_html4css1.html +++ b/docutils/test/functional/expected/standalone_rst_html4css1.html @@ -854,21 +854,27 @@ allowed (e.g. inside a directive).

2.14.7   Compound Paragraph

-
-

Compound 1, paragraph 1.

-

Compound 1, paragraph 2.

-
    -
  • Compound 1, list item one.
  • -
  • Compound 1, list item two.
  • -
-
-

Another compound statement:

+

The compound directive is used to create a "compound paragraph", which +is a single logical paragraph containing multiple physical body +elements. For example:

-

Compound 2, a literal block:

+

The 'rm' command is very dangerous. If you are logged +in as root and enter

-Compound 2, literal.
+cd /
+rm -rf *
 
-

Compound 2, this is a test.

+

you will erase the entire contents of your file system.

+
+

Test the handling and display of compound paragraphs:

+
+

Compound 2, paragraph 1,

+

compound 2, paragraph 2,

+
    +
  • list item 1,
  • +
  • list item 2,
  • +
+

compound 2, paragraph 3.

Compound 3, only consisting of one paragraph.

@@ -878,7 +884,7 @@ Compound 2, literal. Compound 4. This one starts with a literal block. -

Compound 4, a paragraph.

+

Compound 4, paragraph following the literal block.

Now something really perverted -- a nested compound block. This is just to test that it works at all; the results don't have to be @@ -886,13 +892,14 @@ meaningful.

Compound 5, block 1 (a paragraph).

-

Compound 6, block 2 in compound 5.

+

Compound 6 is block 2 in compound 5.

Compound 6, another paragraph.

Compound 5, block 3 (a paragraph).

-

Compound 7, with a table inside:

+

Compound 7, tests the inclusion of various block-level +elements in one logical paragraph. First a table,

@@ -916,8 +923,53 @@ paragraph.
-

Compound 7, a paragraph after the table.

-

Compound 7, another paragraph.

+

followed by a paragraph. This physical paragraph is +actually a continuation of the paragraph before the table. It is followed +by

+
+a quote and
+
    +
  1. an enumerated list,
  2. +
+

a paragraph,

+ +++ + + + +
+--anoption list,
+

a paragraph,

+ +++ + + + +
a field:list,
+

a paragraph,

+
+
a definition
+
list,
+
+

a paragraph, an image:

+../../../docs/user/rst/images/biohazard.png +

a paragraph,

+
+
a line
+
block,
+
+

a paragraph followed by a comment,

+ +

a paragraph, a

+
+

Note

+

with content

+
+

and the final paragraph of the compound 7.

diff --git a/docutils/test/functional/expected/standalone_rst_html5.html b/docutils/test/functional/expected/standalone_rst_html5.html index fc15a8c31..ee9e71679 100644 --- a/docutils/test/functional/expected/standalone_rst_html5.html +++ b/docutils/test/functional/expected/standalone_rst_html5.html @@ -835,19 +835,25 @@ allowed (e.g. inside a directive).

2.14.7 Compound Paragraph

+

The compound directive is used to create a "compound paragraph", which +is a single logical paragraph containing multiple physical body +elements. For example:

+
+

The 'rm' command is very dangerous. If you are logged +in as root and enter

+
cd /
+rm -rf *
+

you will erase the entire contents of your file system.

+
+

Test the handling and display of compound paragraphs:

-

Compound 1, paragraph 1.

-

Compound 1, paragraph 2.

-
    -
  • Compound 1, list item one.

  • -
  • Compound 1, list item two.

  • +

    Compound 2, paragraph 1,

    +

    compound 2, paragraph 2,

    +
      +
    • list item 1,

    • +
    • list item 2,

    -
-

Another compound statement:

-
-

Compound 2, a literal block:

-
Compound 2, literal.
-

Compound 2, this is a test.

+

compound 2, paragraph 3.

Compound 3, only consisting of one paragraph.

@@ -855,7 +861,7 @@ allowed (e.g. inside a directive).

Compound 4.
 This one starts with a literal block.
-

Compound 4, a paragraph.

+

Compound 4, paragraph following the literal block.

Now something really perverted -- a nested compound block. This is just to test that it works at all; the results don't have to be @@ -863,13 +869,14 @@ meaningful.

Compound 5, block 1 (a paragraph).

-

Compound 6, block 2 in compound 5.

+

Compound 6 is block 2 in compound 5.

Compound 6, another paragraph.

Compound 5, block 3 (a paragraph).

-

Compound 7, with a table inside:

+

Compound 7, tests the inclusion of various block-level +elements in one logical paragraph. First a table,

@@ -893,8 +900,48 @@ paragraph.

-

Compound 7, a paragraph after the table.

-

Compound 7, another paragraph.

+

followed by a paragraph. This physical paragraph is +actually a continuation of the paragraph before the table. It is followed +by

+
+

a quote and

+
+
    +
  1. an enumerated list,

  2. +
+

a paragraph,

+
+
--an
+

option list,

+
+
+

a paragraph,

+
+
a field
+

list,

+
+
+

a paragraph,

+
+
a definition
+

list,

+
+
+

a paragraph, an image:

+../../../docs/user/rst/images/biohazard.png +

a paragraph,

+
+
a line
+
block,
+
+

a paragraph followed by a comment,

+ +

a paragraph, a

+
+

Note

+

with content

+
+

and the final paragraph of the compound 7.

diff --git a/docutils/test/functional/expected/standalone_rst_latex.tex b/docutils/test/functional/expected/standalone_rst_latex.tex index dc7feb914..73b4a5623 100644 --- a/docutils/test/functional/expected/standalone_rst_latex.tex +++ b/docutils/test/functional/expected/standalone_rst_latex.tex @@ -1269,59 +1269,71 @@ I recommend you try \href{http://www.python.org/}{Python, \emph{the} best langua \label{compound-paragraph}% } -\begin{DUclass}{some-class} +The \emph{compound} directive is used to create a “compound paragraph”, which +is a single logical paragraph containing multiple physical body +elements. For example: + +\begin{DUclass}{compound} +The ‘rm’ command is very dangerous. If you are logged +in as root and enter +\begin{quote} +\begin{alltt} +cd / +rm -rf * +\end{alltt} +\end{quote} +you will erase the entire contents of your file system. +\end{DUclass} -Compound 1, paragraph 1. +Test the handling and display of compound paragraphs: -Compound 1, paragraph 2. +\begin{DUclass}{compound} +\begin{DUclass}{some-class} +Compound 2, paragraph 1, +compound 2, paragraph 2, \begin{itemize} -\item Compound 1, list item one. +\item list item 1, -\item Compound 1, list item two. +\item list item 2, \end{itemize} +compound 2, paragraph 3. +\end{DUclass} \end{DUclass} -Another compound statement: - - -Compound 2, a literal block: - -\begin{quote} -\begin{alltt} -Compound 2, literal. -\end{alltt} -\end{quote} -Compound 2, this is a test. - - +\begin{DUclass}{compound} Compound 3, only consisting of one paragraph. +\end{DUclass} - +\begin{DUclass}{compound} \begin{quote} \begin{alltt} Compound 4. This one starts with a literal block. \end{alltt} \end{quote} -Compound 4, a paragraph. +Compound 4, paragraph following the literal block. +\end{DUclass} Now something \emph{really} perverted – a nested compound block. This is just to test that it works at all; the results don’t have to be meaningful. - +\begin{DUclass}{compound} Compound 5, block 1 (a paragraph). - -Compound 6, block 2 in compound 5. +\begin{DUclass}{compound} +Compound 6 is block 2 in compound 5. Compound 6, another paragraph. +\end{DUclass} Compound 5, block 3 (a paragraph). +\end{DUclass} - -Compound 7, with a table inside: +\begin{DUclass}{compound} +Compound 7, tests the inclusion of various block-level +elements in one logical paragraph. First a table, \setlength{\DUtablewidth}{\linewidth} \begin{longtable*}[c]{|p{0.249\DUtablewidth}|p{0.249\DUtablewidth}|p{0.249\DUtablewidth}|} @@ -1346,9 +1358,48 @@ Paragraph 3. \\ \hline \end{longtable*} -Compound 7, a paragraph after the table. +followed by a paragraph. This physical paragraph is +actually a continuation of the paragraph before the table. It is followed +by +\begin{quote} +a quote and +\end{quote} +\begin{enumerate} +\item an enumerated list, +\end{enumerate} +a paragraph, +\begin{DUoptionlist} +\item[-{}-an] option list, +\end{DUoptionlist} +a paragraph, +\begin{DUfieldlist} +\item[{a field:}] +list, +\end{DUfieldlist} +a paragraph, +\begin{description} +\item[{a definition}] \leavevmode +list, + +\end{description} +a paragraph, an image: +\includegraphics{../../../docs/user/rst/images/biohazard.png} +a paragraph, +\begin{DUlineblock}{0em} +\item[] a line +\item[] block, +\end{DUlineblock} +a paragraph followed by a comment, +% this is a comment +a paragraph, a -Compound 7, another paragraph. +\DUadmonition[note]{ +\DUtitle[note]{Note} + +with content +} +and the final paragraph of the compound 7. +\end{DUclass} \subsubsection{2.14.8~~~Parsed Literal Blocks% diff --git a/docutils/test/functional/expected/standalone_rst_pseudoxml.txt b/docutils/test/functional/expected/standalone_rst_pseudoxml.txt index 219892d3b..5e06805ab 100644 --- a/docutils/test/functional/expected/standalone_rst_pseudoxml.txt +++ b/docutils/test/functional/expected/standalone_rst_pseudoxml.txt @@ -1663,27 +1663,38 @@ 2.14.7    Compound Paragraph + + The + + compound + directive is used to create a "compound paragraph", which + is a single logical paragraph containing multiple physical body + elements. For example: + + + The 'rm' command is very dangerous. If you are logged + in as root and enter + + cd / + rm -rf * + + you will erase the entire contents of your file system. + + Test the handling and display of compound paragraphs: - Compound 1, paragraph 1. + Compound 2, paragraph 1, - Compound 1, paragraph 2. + compound 2, paragraph 2, - Compound 1, list item one. + list item 1, - Compound 1, list item two. - - Another compound statement: - + list item 2, - Compound 2, a literal block: - - Compound 2, literal. - - Compound 2, this is a test. + compound 2, paragraph 3. Compound 3, only consisting of one paragraph. @@ -1692,7 +1703,7 @@ Compound 4. This one starts with a literal block. - Compound 4, a paragraph. + Compound 4, paragraph following the literal block. Now something @@ -1705,14 +1716,15 @@ Compound 5, block 1 (a paragraph). - Compound 6, block 2 in compound 5. + Compound 6 is block 2 in compound 5. Compound 6, another paragraph. Compound 5, block 3 (a paragraph). - Compound 7, with a table inside: + Compound 7, tests the inclusion of various block-level + elements in one logical paragraph. First a table, @@ -1741,9 +1753,66 @@ Paragraph 3. - Compound 7, a paragraph after the table. + followed by a paragraph. This physical paragraph is + actually a continuation of the paragraph before the table. It is followed + by + + + a quote and + + + + an enumerated list, + + a paragraph, + + + +