MkDocs plugin to directly insert tables from files into markdown.
Project description
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
pluginsentry in your config file yet, you'll likely also want to add thesearchplugin. MkDocs enables it by default if there is nopluginsentry 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:
{{ read_csv() }}passed to pandas.read_csv().{{ read_table() }}passed to pandas.read_table().{{ read_fwf() }}passed to pandas.read_fwf().{{ read_excel() }}passed to pandas.read_excel().
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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d8752c99048d960a397d4d05ca9da9fda789054e5a4ac4987d502d7d518a667
|
|
| MD5 |
02ba2e35aafe567c92d520363b217458
|
|
| BLAKE2b-256 |
dd7eacd66490e66873e49a21f1982301b953d6f53847d2ba067358009dc53a70
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a63b4e7718b05c735c6923e1d2fb566f07b9d29c31211ccec6a27e7676b95605
|
|
| MD5 |
1bfc3e3c2afc2f9497dafe6e2c17510e
|
|
| BLAKE2b-256 |
7e9f51c1485e636677bbe985e1c4b4c7e4d3e2c9aac0a234f13207dec9326d86
|