Skip to main content

Span table cols and rows in MkDocs

Project description

mdx_spanner

This package enables rowspan and colspan in markdown tables when using MkDocs.

Syntax

Basics (spanning indicators)

You can activate colspan by putting only ~~ in a cell. This will merge the cell with the cell in the previous column.

You can activate rowspan by putting __ in a cell. This will merge the cell with the cell in the previous row. If the cell in previous row is empty it will continue to merge until it finds a non-empty cell.

Sample:

| Header 1 | Header 2 | Header 3 |
| ---------| -------- | -------- |
| Value 1  |    ~~    | Value 2  |
|          |    ~~    | Value 3  |
|_        _|    ~~    | Value 5  |
| Value 6  | Value 7  | Value 8  |

This should result in the following table:

+----------+----------+----------+
| Header 1 | Header 2 | Header 3 |
+----------+----------+----------+
| Value 1             | Value 2  |
|                     +----------+
|                     | Value 3  |
|                     +----------+
|                     | Value 5  |
+----------+----------+----------+
| Value 6  | Value 7  | Value 8  |
+----------+----------+----------+

Advanced (alignment markers)

You can change the alignment of a single spanned cell by adding markers to the spanning indicators.

To change the horizontal alignment (when multiple columns are merged) put colons before and/or after the ~~ to indicate the alignment:

Sample Result
:~~ Left aligned
:~~: Centered
~~: Right aligned

To change the vertical alignment (when multiple rows are merged) put one of the following chars (`^`,`=`,`_`) between the `__` to indicate the alignment:
Sample Result
_^_ Top aligned
_=_ Centered
___ Bottom aligned

Sample:

| Header 1   | Header 2 | Header 3 |
| ---------- | -------- | -------- |
| Value 1    |   :~~:   | Value 2  |
|            |    ~~    | Value 3  |
|_     =    _|    ~~    | Value 5  |
| Value 6    | Value 7  | Value 8  |

This should result in the following table:

+----------+----------+----------+
| Header 1 | Header 2 | Header 3 |
+----------+----------+----------+
|                     | Value 2  |
|                     +----------+
|       Value 1       | Value 3  |
|                     +----------+
|                     | Value 5  |
+----------+----------+----------+
| Value 6  | Value 7  | Value 8  |
+----------+----------+----------+

Install

$ pip install mdx_spanner

Usage

After installing the extension you can add it in the mkdocs.yml file:

site_name: ...
nav:
  ...
theme:
  ...
markdown_extensions:
  - mdx_spanner

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mdx_spanner-0.0.5.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

mdx_spanner-0.0.5-py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page