Skip to main content

MkDocs Caption

Package PyPI - Version PyPI - Python Version
Meta Hatch project linting - Ruff code style - Black types - Mypy License - MIT

Enhance your MkDocs documentation with easy figure, table captioning and numbering.

Features

  • Table and Figure captioning and numbering
  • Automatic link text generation for references
  • Highly configurable
  • Extensible to support captions for all Element types

Table of Contents

Installation

pip install mkdocs-caption

Quick Usage

In mkdocs.yml:

...
plugins:
- caption

Inside the Markdown the follwoining will now be converted into a figure/table with caption and numbering.

![figure caption](img.jpg)

Table: table caption

| heading 1| heading 2 | 
| - | - | 
| content 1 | content 2 |
| content 3 | content 4 | 
<p>
  <figure id=_figure-1>
    <img src="img.jpg" />
    <figcaption>Figure 1. figure caption</figcaption>
  </figure>
</p>
<p>
<table id="_table_1">
  <thead>
    <tr>
      <th>heading 1</th>
      <th>heading 2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>content 1</td>
      <td>content 2</td>
    </tr>
    <tr>
      <td>content 3</td>
      <td>content 4</td>
    </tr>
  </tbody>
  <caption>Table 1: table caption</caption>
</table>

Images

The plugin uses the title attribute as the source for the caption. The fallback is the alt attribute. If neither is present the image will not be captioned. The caption is prefixed with the image number. The image number is incremented for every image that is captioned.

Markdown this offers three ways to add a caption to an image.

![figure caption](img.jpg)

![](img.jpg "figure caption")

![](img.jpg){title="figure caption"}

Each captioned image is also assosiated with an id, which by default is constructed from the image number (_figure-x). It is also possible to overwrite the default id by adding an attribute id to an image. The id can be used to link to the image. The plugin also adds a link text (figure x) to all references without a link text. Please note that this feature does not support cross page references.

take a look at [](#_figure-1).
take a look at <a href="#_figure-1">figure 1</a>.

Tables

The plugin allows easy captioning of tables in markdown. Since Markdown does not support captions for tables the plugin uses a custom syntax here. A predefined prefix is used to identify a table caption (Table:). The caption must be placed right before the table (even if the caption should be at the bottom of the table). The caption is prefixed with the table number. The table number is incremented for every image that is captioned.

Table: table caption

| heading 1| heading 2 |
| - | - |
| content 1 | content 2 |
...

Each captioned table is also assosiated with an id, which by default is constructed from the table number (_table-x). It is also possible to overwrite the default id by adding an attribute id to the table (see below). The id can be used to link to the table. The plugin also adds a link text (table x) to all references without a link text. Please note that this feature does not support cross page references.

take a look at [](#_table-1).
take a look at <a href="#_table-1">table 1</a>.

The caption can also be extendet by attributes that are automatically added to the table element. The attributes are specified similar to image attributes be curly brackets. There are two attributes that have special meaning: id and cols. The id attribute is used to overwrite the default id of the table. The cols attribute can be used to controll the column width of the table.

Table: table caption {id="my-table" cols="1,3"}

| heading 1| heading 2 |
| - | - |
| content 1 | content 2 |
...
heading 1 heading 2
content 1 content 2
content 3 content 4
Table 1: table caption

Note that the sum of the specified column widths is treated as 100%.

Custom captions

In addition to tables and figures the plugin also supports custom captions. Custom captions must be manually defined in the mkdocs.yml file. Similar to table captions the are placed right before the target element (e.g. an enumeration). The plugin will wrap the target element in a figure with the specified caption and options.

In mkdocs.yml:

...
plugins:
- caption:
    additional_identifier: [`List`]

In Markdown:

List: list caption

1. item 1
2. item 2
<figure id="_list-1">
  <ul>
    <li>item 1</li>
    <li>item 2</li>
  </ul>
  <figcaption>List 1: list caption</figcaption
</figure>

The same configuration options as for the table also apply for the custom captions. Note that each identifier has its own counter.

Configuration

The plugin can be configured in the mkdocs.yml file. The following options are available:

plugins:
  - caption:
    additional_identifier: [] # list of additional identifiers (e.g. [`List`, `Example`])
    table:
      enable: true
      start_index: 1
      increment_index: 1
      position: bottom  # (top, bottom)
      identifier: '_table-{index}'
      reference_text: 'table {index}'
      caption_prefix: 'Table {index}:'
    figure:
      enable: true
      start_index: 1
      increment_index: 1
      position: bottom
      identifier: '_figure-{index}'
      reference_text: 'figure {index}'
      caption_prefix: 'figure {index}:'
    custom:
      enable: true
      start_index: 1
      increment_index: 1
      position: bottom
      identifier: '_{identifier}-{index}'
      reference_text: '{identifier} {index}'
      caption_prefix: '{identifier} {index}:'

The {index} placeholders is replaced with the current index. The {identifier} placeholder is replaced with the identifier of the current element and is only relevant for the custom option.

It is also possible to overwrite the default configuration for a specific page. This can be done by adding a caption section to the page header.

---
caption:
  table:
    start_index: 4
---
# Page Title
...

License

mkdocs-caption is distributed under the terms of the MIT license.

Release files for mkdocs-caption 0.0.3

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

Source distribution (sdist)

Source distribution for mkdocs-caption 0.0.3
File Size Uploaded
mkdocs_caption-0.0.3.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mkdocs-caption 0.0.3
File Interpreter ABI Platform
mkdocs_caption-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 20.6 kB

Release files / mkdocs_caption-0.0.3.tar.gz

Download URL mkdocs_caption-0.0.3.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8151d48c7cf8d64c550aec36c5a3157bbad8c9849ea4716945ed3f2e3d42d057
BLAKE2b-256 checksum
How to use checksums
81b0a7bc4683b2955da08bcb0edb719b6679102b8bd4a0dafbe4e64528a88083
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.24.1

Release files / mkdocs_caption-0.0.3-py3-none-any.whl

Download URL mkdocs_caption-0.0.3-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b8d62aaa8d03670dc8931aada37e463b1ae7c34fb3384c14eaa59669be7b447a
BLAKE2b-256 checksum
How to use checksums
a5072de7ec485bef10d4f77326a3d9ec7353d7760ac6d2ad22603f9a4b5cbc29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.24.1

Release history Release notifications | RSS feed

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

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