Support for colspan and rowspan in RST tables for docutils and Sphinx
Project description
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).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rst_table_span-1.0.1.tar.gz.
File metadata
- Download URL: rst_table_span-1.0.1.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d561f4c548f7603c8a276079a07e5301c3ec31ce39c0224d0b64b18b8b9d2ea
|
|
| MD5 |
6c05eb5bbbd9c0098efd2590dda61508
|
|
| BLAKE2b-256 |
23917a0e6c7d074b96ec311ee1835a2684fa765307a63293e729b7e4d59aac19
|
File details
Details for the file rst_table_span-1.0.1-py2.py3-none-any.whl.
File metadata
- Download URL: rst_table_span-1.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28e89f3f6666be0a4011e76f4421025f61788264de16f3609d50293224cd142a
|
|
| MD5 |
a40bf1ced9875c01f4e1cbac5e42d239
|
|
| BLAKE2b-256 |
3389bdb06dcb5091b4cdf55502c6d2eceab214c095e86148cf2ea1c9a973e52e
|