Skip to content

Add support to flat-table to remove a potential empty paragraph and fix the flat-table iterator#43

Open
tim-nordell-nimbelink wants to merge 2 commits into
return42:masterfrom
tim-nordell-nimbelink:fix/misc-flat-table
Open

Add support to flat-table to remove a potential empty paragraph and fix the flat-table iterator#43
tim-nordell-nimbelink wants to merge 2 commits into
return42:masterfrom
tim-nordell-nimbelink:fix/misc-flat-table

Conversation

@tim-nordell-nimbelink
Copy link
Copy Markdown

Using the flat-table extension we noticed that we end up with an extra empty paragraph when we have this kind of situation:

.. flat-table::

   * - :cspan:`1` :rspan:`1`
   
       .. directive::
  
          directive-content

There are two commits in this series:

  • The first commit fixes an iterator bug in the original code where it was iterating over a list that was being modified
  • The second commit adds the detection of an empty paragraph as the first node and removes the entire node if this occurs

…vals

Iterating through a list while you're modifying it results an indeterminate
iteration. Instead, copy the original list for the iterator.

An example which doesn't work in Python 3.14 is having this in your flat-table:

   .. flat-table::

      * - :rspan:`1`:cspan:`1`

versus the following which works in Python 3.14:

   .. flat-table::

      * - :rspan:`1` :cspan:`1`

The difference is the latter ends up with a node inserted between the rspan
and cspan.

Signed-off-by: Tim Nordell <tnordell@airgain.com>
This permits a flat-table to have a leading paragraph like this:

    .. flat-table::

       * - :rspan:`1`

           My content here

without injecting an extraneous paragraph on the first line.  This syntax
is useful for certain situations where the content comes from a nested
directive like:

    .. flat-table::

       * - :rspan:`1`

           .. directive::

              My directive content here

Otherwise the flat-table instance ends up injecting an extra empty paragraph in
this situation. The other place that ends up with extra space in the LaTeX
output is the following situation:

    .. flat-table::

       * - :rspan:`1`
           My text here

This is also solved by trimming leading whitespace on the following sibling of
the element removed.

Examples of trimming in the upstream docutils repository can be seen in [1].

[1] https://github.com/docutils/docutils/blob/c8e6032183c603d1b95fed922952437b24f97f1b/docutils/docutils/transforms/references.py#L734-L745

Signed-off-by: Tim Nordell <tnordell@airgain.com>
@tim-nordell-nimbelink
Copy link
Copy Markdown
Author

Sorry for the churn this morning, but I had discovered one other place in our documents that using the flat-table directive caused extra whitespace in the PDF output, and just needed to tweak it slightly. Notably, the directive case causes extra whites-space in the HTML output whereas the other case mentioned in the commit only causes extra whitespace in the LaTeX/PDF output but not in the HTML output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant