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.
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 thesearch
plugin. MkDocs enables it by default if there is noplugins
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().
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().
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
Hashes for mkdocs-table-reader-plugin-0.4.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c12508c678015aea6e5948aa0e3fe1ad6031dc50d5502e2c539d2eeb57a6e17 |
|
MD5 | e21d9b1e3a90060c0490ff81188b8063 |
|
BLAKE2b-256 | e8a01b22060699f8e210caac221e81ee25cca7788c0647412799a1985347f602 |
Hashes for mkdocs_table_reader_plugin-0.4.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b7406e0d5b46164ec3411c3e133d8a9fbcd9542de9fd6a36a629d1aa3a71b55 |
|
MD5 | 2c908d680013954b298433ee41b7187f |
|
BLAKE2b-256 | 124ca7343a2b34dfabf7b3d107974c485d0e87d3e4f50f0be656cb957cf9862e |