You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,8 +40,8 @@ In your markdown files you can now use:
40
40
41
41
Where the path is relative to the location of your project's `mkdocs.yml` file, _or_ your project's `docs/` directory, _or_ the location of your markdown source file (all 3 possible locations will be searched, in that order).
42
42
43
-
- There are [readers](https://timvink.github.io/mkdocs-table-reader-plugin/readers/) for `.csv`, `.fwf`, `.json`, `.xls`, `.xlsx`, `.yaml`, `.feather` and `.tsv` files. There is also the `read_raw()` reader that will allow you to insert tables (or other content) already in markdown format.
44
-
- `table-reader`is compatible with [`mkdocs-macros-plugin`](https://mkdocs-macros-plugin.readthedocs.io/en/latest/), which means you can [dynamically insert tables using jinja2 syntax](https://timvink.github.io/mkdocs-table-reader-plugin/howto/use_jinja2/).
43
+
- There are [readers](https://timvink.github.io/mkdocs-table-reader-plugin/readers/) available for many common table formats, like `.csv`, `.fwf`, `.json`, `.xls`, `.xlsx`, `.yaml`, `.feather` and `.tsv`. There is also the `read_raw()` reader that will allow you to insert tables (or other content) already in markdown format.
44
+
- `table-reader`is compatible with [`mkdocs-macros-plugin`](https://mkdocs-macros-plugin.readthedocs.io/en/latest/). This enables further automation like filtering tables or inserting directories of tables. See the documentation on [compatibility with macros plugin](howto/use_jinja2.md) for more examples.
Copy file name to clipboardExpand all lines: docs/howto/alternatives.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ Downsides:
39
39
40
40
## Execute python during build
41
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/).
42
+
You could also choose to insert the markdown for tables dynamically, using packages like [markdown-exec](https://pypi.org/project/markdown-exec/).
Any keyword arguments you give to <code>\{\{ read_csv('path_to_your_table.csv') \}\}</code> will be matched and passed the corresponding [pandas.read_csv()](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html) and/or
15
+
{% raw %}
16
+
Any keyword arguments you give to `{{ read_csv('path_to_your_table.csv') }}` will be matched and passed the corresponding [pandas.read_csv()](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html) and/or
Pandas's `.to_markdown()` uses the [tabulate](https://pypi.org/project/tabulate/) package and any keyword arguments that are passed to it. Tabulate in turn offers many customization options, see [library usage](https://github.com/astanin/python-tabulate#library-usage).
19
21
@@ -23,21 +25,33 @@ Text columns will be aligned to the left [by default](https://github.com/astanin
@@ -47,21 +61,33 @@ If you use [mkdocs-material](https://squidfunk.github.io/mkdocs-material), you c
47
61
48
62
You can use [tabulate](https://pypi.org/project/tabulate/)'s [number formatting](https://github.com/astanin/python-tabulate#number-formatting). Example:
Copy file name to clipboardExpand all lines: docs/howto/preprocess_tables.md
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
# Preprocess input tables
2
2
3
+
{% raw %}
4
+
3
5
`mkdocs>=1.4` supports [hooks](https://www.mkdocs.org/user-guide/configuration/#hooks), which enable you to run python scripts on `mkdocs serve` or `mkdocs build`.
4
6
5
7
Here are some example of workflows that use hooks and the `table-reader` plugin:
@@ -26,7 +28,7 @@ Here are some example of workflows that use hooks and the `table-reader` plugin:
@@ -74,7 +76,7 @@ Here are some example of workflows that use hooks and the `table-reader` plugin:
74
76
75
77
<code>
76
78
My table:
77
-
\{\{ read_csv("docs/assets/nyc_data.csv") \}\}
79
+
{{ read_csv("docs/assets/nyc_data.csv") }}
78
80
</code>
79
81
80
82
=== "mkdocs.yml"
@@ -101,3 +103,5 @@ Here are some example of workflows that use hooks and the `table-reader` plugin:
101
103
```
102
104
103
105
Note that during development when you use `mkdocs serve` and autoreload, you might not want to run this hook every time you make a change. You could use an environment variable inside your hook, for example something like `if os.environ['disable_hook'] == 1: return None`.
Copy file name to clipboardExpand all lines: docs/howto/use_jinja2.md
+22-25Lines changed: 22 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,6 @@
1
-
# Use jinja2 for automation
1
+
# Compatibility with mkdocs-macros-plugin to enable further automation
2
+
3
+
{% raw %}
2
4
3
5
`table-reader` supports [`mkdocs-macros-plugin`](https://mkdocs-macros-plugin.readthedocs.io/en/latest/), which enables you to use jinja2 syntax inside markdown files (among other things).
4
6
@@ -10,26 +12,19 @@ plugins:
10
12
- table-reader
11
13
```
12
14
13
-
Now you can do cool things like:
14
-
15
-
## Dynamically load a list of tables
15
+
Everything will work as before, _except_ indentation will not be retrained. This means components that rely on indentation (like [Admonitions](https://squidfunk.github.io/mkdocs-material/reference/admonitions/) and [Content tabs](https://squidfunk.github.io/mkdocs-material/reference/content-tabs/#usage)) will break.
16
16
17
-
```markdown
18
-
# index.md
17
+
The solution is to use the custom _filter_ `add_indendation` (a filter added to `macros` by `table-reader` plugin, see the [readers](../readers.md)). For example:
19
18
20
-
{% set table_names = ["basic_table.csv","basic_table2.csv"] %}
If you inserted content has multiple lines, then indentation will be not be retained beyond the first line. This means things like [content tabs](https://squidfunk.github.io/mkdocs-material/reference/content-tabs/#usage) will not work as expected.
25
+
The upside is you now have much more control. A couple of example use cases:
31
26
32
-
To fix that, you can use the custom _filter_`add_indendation` (a filter add to `macros` by `table-reader` plugin). For example:
27
+
## Dynamically load a specified list of tables into tabs
33
28
34
29
=== "index.md"
35
30
@@ -39,7 +34,7 @@ To fix that, you can use the custom _filter_ `add_indendation` (a filter add to
@@ -64,11 +59,6 @@ To fix that, you can use the custom _filter_ `add_indendation` (a filter add to
64
59
alternate_style: true
65
60
```
66
61
67
-
!!! note "Note the space in { {"
68
-
69
-
To avoid the tables being inserted into the code example, we replaced `{{` with `{ {`.
70
-
If you copy this example, make sure to fix.
71
-
72
62
73
63
## Recursively insert an entire directory of tables
74
64
@@ -100,12 +90,19 @@ Now you could do something like:
100
90
101
91
{% for table_name in listdir('docs/assets/my_tables") %}
102
92
103
-
{{ read_csv(table_name) }}
93
+
{{ read_csv(table_name) }}
104
94
105
95
{% endfor %}
106
96
```
107
97
108
-
!!! note "Note the space in { {"
98
+
## Filter a table before inserting it
99
+
100
+
When you enable the `macros` plugin in your `mkdocs.yml`, `table-reader` will add additional _macros_ and _filters_ (see the [readers overview](../readers.md)).
101
+
102
+
You can use the `pd_<reader>` variants to read a file to a pandas dataframe. Then you can use the pandas methods like [`.query()`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.query.html). For example:
Copy file name to clipboardExpand all lines: docs/options.md
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,7 @@ hide:
4
4
---
5
5
6
6
# Options
7
+
{% raw %}
7
8
8
9
You can customize the plugin by setting options in `mkdocs.yml`. For example:
9
10
@@ -24,7 +25,7 @@ Default is `.`. Set a default path to the searched directories in order to short
24
25
25
26
Given a file path, `table-reader` will search for that file relative to your your project's `mkdocs.yml` and relative to your `docs/` folder. If you use a folder for all your table files you can shorten the path specification by setting the `data_path`.
26
27
27
-
For example, if your table is located in `docs/assets/tables/basic_table.csv`, you can set `data_path` to `docs/assets/tables/`. Then you will be able to use <code>\{\{ read_csv("basic_table.csv") \}\}</code> instead of <code>\{\{ read_csv("docs/assets/tables/basic_table.csv") \}\}</code> inside any markdown page.
28
+
For example, if your table is located in `docs/assets/tables/basic_table.csv`, you can set `data_path` to `docs/assets/tables/`. Then you will be able to use `{{ read_csv("basic_table.csv") }}` instead of `{{ read_csv("docs/assets/tables/basic_table.csv") }}` inside any markdown page.
28
29
29
30
!!! info
30
31
@@ -38,7 +39,7 @@ Default: `False`. When enabled, if a filepath is not found, the plugin will rais
38
39
39
40
## `select_readers`
40
41
41
-
Default: Selects all available readers. Specify a list of readers to improve documentation build times for very large sites.
42
+
Default: Selects all available readers. Specify a list of readers to improve documentation build times for very large sites. This option is ignored when you use this plugin with `mkdocs-macros-plugin` ([read more](howto/use_jinja2.md))
42
43
43
44
## `enabled`
44
45
@@ -57,4 +58,6 @@ Which enables you to disable the plugin locally using:
0 commit comments