Skip to main content

rst-table-span

reStructuredText provides four syntaxes for tables:

  • Grid tables

  • Simple tables

  • List tables

  • CSV tables

However, only grid and simple tables support cells spanning multiple columns, and only grid tables support cells spanning multiple rows.

The rst-table-span package adds the :colspan:`C`, :rowspan:`R`, and :cellspan:`CxR` roles which add support for column and row span to all existing RST table types.

This project was inspired by the flat-table directive from the LinuxDoc project.

Example

To produce a table like this:

Header row, column 1 (header rows optional)

Header 2

Header 3

Header 4

body row 1, column 1

column 2

column 3

column 4

body row 2

Cells may span columns.

body row 3

Cells may span rows.

Corner

body row 4

You would normally need to write this:

+------------------------+------------+----------+----------+
| Header row, column 1   | Header 2   | Header 3 | Header 4 |
| (header rows optional) |            |          |          |
+========================+============+==========+==========+
| body row 1, column 1   | column 2   | column 3 | column 4 |
+------------------------+------------+----------+----------+
| body row 2             | Cells may span columns.          |
+------------------------+------------+---------------------+
| body row 3             | Cells may  | Corner              |
+------------------------+ span rows. |                     |
| body row 4             |            |                     |
+------------------------+------------+---------------------+

But with rst-table-span you can instead write it using a csv-table:

.. csv-table::
   :header-rows: 1

   "Header row, column 1 (header rows optional)", Header 2, Header 3, Header 4
   "body row 1, column 1", column 2, column 3, column 4
   body row 2, :colspan:`3` Cells may span columns.
   body row 3, :rowspan:`2` Cells may span rows., :cellspan:`2x2` Corner
   body row 4

Or a list-table:

.. list-table::
   :header-rows: 1

   * - Header row, column 1 (header rows optional)
     - Header 2
     - Header 3
     - Header 4
   * - body row 1, column 1
     - column 2
     - column 3
     - column 4
   * - body row 2
     - :colspan:`3` Cells may span columns.
     -
     -
   * - body row 3
     - :rowspan:`2` Cells may span rows.
     - :cellspan:`2x2` Corner
     -
   * - body row 4
     -
     -
     -

Installation and Usage

Install the package using pip:

pip install rst-table-span

or add the rst-table-span package to your project or environment dependency list (eg. pyproject.toml, requirements.txt, or similar).

Sphinx

Also add the rst_table_span module to your list of extensions in your conf.py settings:

extensions = [
    "rst_table_span",
]

Docutils

Docutils doesn’t provide a declarative extension mechanism, as far as I know. If you invoke docutils programatically using its Publisher API, then a global function is provided to register the roles. Call it before setting up the publisher:

import sys
import docutils.__main__
import rst_table_span

rst_table_span.register_docutils_roles()
sys.exit(docutils.__main__.main())

For convenience, this package installs the above script as the rst-table-span-docutils executable. It behaves the same way as the standard docutils executable. It can then be used used like this:

rst-table-span-docutils demo.rst --output demo.html

License

This library is released under the MIT license (see the LICENSE file in the source code).

Metadata

Release files for rst-table-span 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rst-table-span 1.0.1
File Size Uploaded Provenance Actions
rst_table_span-1.0.1.tar.gz 4.7 kB Without provenance Details for rst_table_span-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rst-table-span 1.0.1
File Interpreter ABI Platform Actions
rst_table_span-1.0.1-py2.py3-none-any.whl Python 2, Python 3 none any Details for rst_table_span-1.0.1-py2.py3-none-any.whl

Total release size: 9.6 kB

Release files / rst_table_span-1.0.1.tar.gz

Download URL rst_table_span-1.0.1.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8d561f4c548f7603c8a276079a07e5301c3ec31ce39c0224d0b64b18b8b9d2ea
BLAKE2b-256 checksum
How to use checksums
23917a0e6c7d074b96ec311ee1835a2684fa765307a63293e729b7e4d59aac19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.1

Release files / rst_table_span-1.0.1-py2.py3-none-any.whl

Download URL rst_table_span-1.0.1-py2.py3-none-any.whl
Size 4.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
28e89f3f6666be0a4011e76f4421025f61788264de16f3609d50293224cd142a
BLAKE2b-256 checksum
How to use checksums
3389bdb06dcb5091b4cdf55502c6d2eceab214c095e86148cf2ea1c9a973e52e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.1

Security for rst-table-span 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page