Skip to content

Commit 7267d81

Browse files
authored
Document alternatives, closes #50
1 parent aa376e3 commit 7267d81

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

docs/howto/alternatives.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Consider alternatives
2+
3+
This plugin is built to be able to quickly insert table files anywhere in a markdown file.
4+
5+
You could also consider alternative approaches that might fit your use-case better.
6+
7+
## Write tables to markdown files
8+
9+
You could write a script (maybe triggered by a [mkdocs hook](https://www.mkdocs.org/user-guide/configuration/#hooks)) that writes the tables you need into markdown files. It could look something like this:
10+
11+
```python
12+
# write markdown tables
13+
import pandas as pd
14+
15+
md = pd.read_csv("your_file.csv").to_markdown()
16+
with open("docs/assets/tables/my_file.md", "w") as f:
17+
f.write(md)
18+
```
19+
20+
You can then use the [snippets extension](https://facelessuser.github.io/pymdown-extensions/extensions/snippets/) to insert the tables into your markdown pages:
21+
22+
```md
23+
# some_page.md
24+
25+
My table:
26+
27+
;--8<-- "assets/tables/my_file.md"
28+
```
29+
30+
Upsides:
31+
32+
- Easy, fast, low on dependencies
33+
- You can see changes of your tables in version control
34+
35+
Downsides:
36+
37+
- You need to generate/update the markdown files on every build
38+
- if you move the page you have to update the path (if you used a relative path for the snippet)
39+
40+
## Execute python during build
41+
42+
You could also choose to insert the markdown for tables dynamically, using packages like [markdown-exec]() or [mkdocs-macros-plugin](https://mkdocs-macros-plugin.readthedocs.io/).
43+
44+
For example:
45+
46+
````
47+
```python exec="true"
48+
import pandas as pd
49+
50+
file_path = "path/to/file/from/project/root"
51+
print(pd.read_csv(file_path).to_markdown(index=False, disable_numparse=True))
52+
```
53+
````
54+

docs/options.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ plugins:
1616
allow_missing_files: False
1717
```
1818
19-
## Options
20-
2119
## `base_path`
2220

2321
The base path where `mkdocs-table-reader-plugin` will search for input files. The path to your table files should be relative to the `base_path`. Allowed values:

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ nav:
1212
- howto/preprocess_tables.md
1313
- howto/project_structure.md
1414
- howto/docker.md
15+
- howto/alternatives.md
1516
- options.md
1617

1718
theme:

0 commit comments

Comments
 (0)