timvink / mkdocs-table-reader-plugin

MkDocs plugin that enables a markdown tag like {{ read_csv('table.csv') }} to directly insert various table formats into a page
https://timvink.github.io/mkdocs-table-reader-plugin/
MIT License
111 stars 18 forks source link

Allow paths relative to page #36

Closed kdm9 closed 1 year ago

kdm9 commented 1 year ago

Hello, and thanks for a neat plugin.

The attached patch allows paths to be specified relative to a page's source. For example:

$ tree
.
└── a
    └── b
        └── c
            ├── index.md
            └── table.csv
$ cat a/b/c/index.md 
# test

{{ read_tsv("table.csv") }}

Specifically, we check if the file is in the configured data path, and iff not found there, check relative to the page's source directory.

timvink commented 1 year ago

Hi @kdm9 ,

I like the idea!

I think we should put the functionality behind an option flag (because explicit > implicit), but we can put it to True by default. Maybe search_page_directory_fallback

We also need to update docs/options.md. And of course add some unit tests (at 11k downloads/month I want to be sure changes don't break things).

Would you like to continue working on this?

kdm9 commented 1 year ago

@timvink great, thanks. I'll remove the prints (oops 😳) and implement the option and update the docs, but it would be great if I could leave the tests to you (I'm unfamiliar with the test suite, and having you write them might uncover issues I would miss)

timvink commented 1 year ago

Thanks @kdm9 ! Will tweak it a bit further and write unit tests & include it in next release.

timvink commented 1 year ago

Just released v2.

Refactored your code & rewrote the docs for more clarity. It's a great change that makes a lot of sense. Thanks again for pushing this!