mkdocs-table-reader-plugin icon indicating copy to clipboard operation
mkdocs-table-reader-plugin copied to clipboard

Add superfence notation

Open timvink opened this issue 2 years ago • 3 comments

(inspired by this discussion)

Instead of {{ read_csv('table.csv') }} we could take inspiration from https://github.com/coddingtonbear/obsidian-csv-table and create a custom superfences notation like so:

```table-reader
filepath: table.csv
```

We could add the following extra options:

  • reader (str) one of the pandas functions, like read_csv
  • keyword_arguments, a dictionary, with named arguments, for example encoding: 'utf-8'
  • filter (list of strings), where each is successively passed to .query()
  • sortBy (list of strings), passed to pandas's .sort_values()
  • maxRows (int), passed to pandas's .head()
  • columnVariables (list of strings), passed to pandas's .rename()`

You can already do all this by just using a mkdocs hook to preprocess tables.

So if you read this & have a use-case for this, let me know!

timvink avatar Mar 06 '23 09:03 timvink

Hey Tim! Original poster of the discussion here. I might be biased, but I really like the Obsidian notation - the fact that it reads easily, feels void of actual code (which I really prefer in Markdown documents) is a big bonus I think. And the actions/options you listed above should be fine - I would try to match what has been done in the Obsidian plug-in as there is no need to re-invent the wheel, and their users have had a long time to post issues. Thanks for following up on the discussion and with your work on the plugin - I'm looking forward to testing it out!

In terms of a use-case, as I mentioned in the original post, I'm personally working on an open hardware project where we have a collection of parts in a file and want to showcase subsets of parts needed to make each build. :-)

roaldarbol avatar Mar 06 '23 10:03 roaldarbol

I really like the Obsidian notation

I thought it would be easier to understand if I would follow the pandas arguments where possible. But it's not that much clearer anyway. Being able to copy markdown from obsidian and have it work in Mkdocs with only minimal changes is more vaiuable.

I'm looking forward to working on this one, but it's low-prio so probably going to take 1-2 months before I have some free time for hobby coding again :D

timvink avatar Mar 10 '23 20:03 timvink

No worries, this would be awesome, but not time critical. ;-) Looking forward to your implementation!

roaldarbol avatar Mar 11 '23 18:03 roaldarbol

Was there any progress on this, just hit this issue and looking for a solution to use Marco and table-reader together

samhodgkinson avatar Aug 02 '24 09:08 samhodgkinson

No, however I did solve compatibility between macros and this plugin. See #57. v3 soon to be released.

Update: v3 released: https://pypi.org/project/mkdocs-table-reader-plugin/

timvink avatar Aug 15 '24 12:08 timvink

Thanks for the update on this, much appreciated. @timvink

samhodgkinson avatar Aug 17 '24 08:08 samhodgkinson

I've reconsidered.

I don't want to support an additional format. The reason is compatibility with other plugins, and compatibility with the existing options.

Instead I think there an opportunity for a mkdocs-obsidian-csv-table-plugin. It can re-implement all the options available for https://github.com/coddingtonbear/obsidian-csv-table. That way you would be able to copy paste your obsidian markdown and use it in mkdocs.

I've already solved some tricky problems in this plugin that can be copied:

  • using custom superfences to find and parse the references (https://github.com/timvink/mkdocs-table-reader-plugin/pull/53)
  • Storing the current page and making that available to the reader function, so you can find the absolute path from the relative path on a markdown page. See the source code of this plugin.

So if anyone is up for it, go for it!

timvink avatar Aug 27 '24 14:08 timvink