Skip to main content

A MkDocs plugin listing all figures to create a table of figures page

Project description

mkdocs-table-of-figures

This is a plugin that creates a figcaption with elements alt attribute or title and lists all figures in files into a table of figures to be integrated in Markdown pages for MkDocs.

Setup

Installing using pip:

pip install mkdocs-table-of-figures

Config

You need to activate the plugin in mkdocs.yml:

plugins:
  - table-of-figures:
      title_label: "Table of figures of the documentation" # Optional --> Default : Table of Figures
      figure_label: "Figure N°" # Optional --> Default : Figure
      description_label: "Description of the figures" # Optional --> Default : Description

      temp_dir: "folder_name" # Optional --> Default : temp_figures
      file: "file_name" # Optional --> Default : figures.md

      on_mermaid: true # Optional --> Default : false
      on_codeblock: true # Optional --> Default : false
      on_table: true # Optional --> Default : false

As you can see, every option is optional, but if you want to generate a table of figures in another language than English, you will need to set up label options.

  • title_label - This is the title (heading 1) given to the page that will contain the table of figures.
  • figure_label - This is the name given to every figure right before the auto-incremented number.
  • description_label - This is the label given to the column containing the description of each figure (alt text).
  • temp_dir - The temporary directory used to store the table of figures Markdown file before rendering to HTML. Only set this option if you already have a temp_figures folder in the root directory (same as mkdocs.yml), which you should not normally have.
  • file - The name of the Markdown file containing the table of figures. Only set this option if you already have a figures.md file in the docs directory.
  • on_mermaid - To enable mermaid diagrams support, need to use of md_in_html Markdown extension
  • on_codeblock - To enable code blocks support, need to use of md_in_html Markdown extension
  • on_table - To enable tables support, need to use of md_in_html Markdown extension

Usage

The plugin will only look for Markdown image composed of alt text. If you don't set any alt text for the Markdown image it will be ignored.

There is two way of correctly rendering image stored within the docs:

  • Using url from base: this mean that you give the full path from the docs directory starting with / like this /path/to/image/from/docs/image.png
  • With the help of md_in_html: there is a Markdown extension that you can set in mkdocs.yml that allow the plugin to place Markdown in HTML which allow this plugin to let MkDocs set relative link in src attribute properly during HTML rendering

Concerning external images nothing change.

You can set the md_in_html option like so :

markdown_extensions:
  - md_in_html

Using the command mkdocs build or mkdocs serve will trigger the plugin if it has been set correctly in the config file.

Support

This plugin currently supports markdown images, mermaid diagrams, code blocks and table.

To make a mermaid diagram, code block or table detectable by this plugin, you need to give it a title at the line just below it like this:

    ``` php
    <?php
      $var = 42;
    ?>
    ```
    The title of the code block go here
    ``` mermaid
    sequenceDiagram
        participant Alice
        participant Bob
        Alice->>John: Hello John, how are you?
        loop Healthcheck
            John->>John: Fight against hypochondria
        end
        Note right of John: Rational thoughts <br/>prevail!
        John-->>Alice: Great!
        John->>Bob: How about you?
        Bob-->>John: Jolly good!
    ```
    The title of the mermaid diagram go here
    | Table   | Right | Center  | Left  |
    | ------- | ----: | :-----: | :---- |
    | A table |  With | Content | in it |
    The title of the table go here

It will not work if there is a line between the element and the title.

I highly recommend using mkdocs-material to use mermaid diagrams. For more info about mermaid diagrams, I invite you to check mkdocs-material and mermaid's official documentation.

I also recommend to add this stylesheet to prevent mermaid size from being reduced or code blocks from having code centered by mkdocs-material.

figure.figure-mermaid {
    margin: 0 1em;
    width: 100%;
}

figure.figure-codeblock code {
    text-align: initial;
}

You can place the stylesheet in your mkdocs.yml at extra-css option

extra_css:
  - fix-mermaid-figure.css

License

This project is under MIT license. See the license file for more details.

See Also

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

mkdocs-table-of-figures-0.2.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mkdocs_table_of_figures-0.2.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs-table-of-figures-0.2.0.tar.gz.

File metadata

  • Download URL: mkdocs-table-of-figures-0.2.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for mkdocs-table-of-figures-0.2.0.tar.gz
Algorithm Hash digest
SHA256 79e7bd45b8d8b46a80197ca092fafec3df2edb4f82f7dd2eb7fde66287f6c296
MD5 dd8ef95757e86f2c1e5945931b39e1dd
BLAKE2b-256 2e24fd71b93a0cb5f4a2b31546199a362e49f2809974dec4948b86551961373b

See more details on using hashes here.

File details

Details for the file mkdocs_table_of_figures-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mkdocs_table_of_figures-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 03d0a61a312a937733fefdebedf247ca2b5e8ea503323c1e215256e8d75922ac
MD5 b13b8c9dcc4d0efd30ed4b087240d225
BLAKE2b-256 ea77b82dfe7b3dcdf130aec1fd8017ae5477f2f7870180cbb4a34bd7bc536557

See more details on using hashes here.

Supported by

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