Skip to main content

MkDocs plugin to directly insert tables from files into markdown.

Project description

Actions Status PyPI - Python Version PyPI PyPI - Downloads codecov GitHub contributors PyPI - License

mkdocs-table-reader-plugin

MkDocs plugin that adds a {{ read_csv('table.csv') }} markdown tag to directly insert CSV files as a table into a page. See it in action at timvink.github.io/mkdocs-table-reader-plugin/.

This helps to enable building reproducible reports. For more complex use cases, consider pheasant or nbconvert.

Setup

Install the plugin using pip3:

pip3 install mkdocs-table-reader-plugin

Next, add the following lines to your mkdocs.yml:

plugins:
  - search
  - table-reader

If you have no plugins entry in your config file yet, you'll likely also want to add the search plugin. MkDocs enables it by default if there is no plugins entry set.

Usage

In your markdown documents you can now use:

{{ read_csv('path_to_table.csv') }}

Where the path is relative to the location of your project's mkdocs.yml file.

Under the hood this is basically:

import pandas as pd
df = pd.read_csv('path_to_table.csv')
df.to_markdown(index=False, tablefmt='pipe')

Which means you can pass all parameters of pandas.read_csv().

You can see an example usage in this repo (see mkdocs.yml and docs/) and the result at timvink.github.io/mkdocs-table-reader-plugin/.

Available readers

The table reader functions implemented from pandas:

Reading xlsx files

You might get a XLRDError('Excel xlsx file; not supported',) error when trying to read modern excel files. That's because xlrd does not support .xlsx files (stackoverflow post). Instead, install openpyxl and use:

{{ read_excel('tables/excel_table.xlsx', engine='openpyxl') }}

Options

You can customize the plugin by setting options in mkdocs.yml. For example:

plugins:
  - table-reader:
      data_path: "docs"

data_path

Default is ., which means you can specify the path to your table files relative to the location of your project's mkdocs.yml file. If you use a folder for all your table files you can shorten the path specification by setting data_path.

For example, if you set data_path to docs/ in the project below, you will be able to use {{ read_csv("basic_table.csv") }} instead of {{ read_csv("docs/basic_table.csv") }} inside index.md.

.
├── docs
│   ├── basic_table.csv
│   └── index.md
└── mkdocs.yml

Contributing

Contributions are very welcome! Please read CONTRIBUTING.md before putting in any work.

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-reader-plugin-0.4.4.tar.gz (5.6 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_reader_plugin-0.4.4-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs-table-reader-plugin-0.4.4.tar.gz.

File metadata

  • Download URL: mkdocs-table-reader-plugin-0.4.4.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for mkdocs-table-reader-plugin-0.4.4.tar.gz
Algorithm Hash digest
SHA256 2d8752c99048d960a397d4d05ca9da9fda789054e5a4ac4987d502d7d518a667
MD5 02ba2e35aafe567c92d520363b217458
BLAKE2b-256 dd7eacd66490e66873e49a21f1982301b953d6f53847d2ba067358009dc53a70

See more details on using hashes here.

File details

Details for the file mkdocs_table_reader_plugin-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: mkdocs_table_reader_plugin-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for mkdocs_table_reader_plugin-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a63b4e7718b05c735c6923e1d2fb566f07b9d29c31211ccec6a27e7676b95605
MD5 1bfc3e3c2afc2f9497dafe6e2c17510e
BLAKE2b-256 7e9f51c1485e636677bbe985e1c4b4c7e4d3e2c9aac0a234f13207dec9326d86

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