Closed mizraelson closed 1 year ago
Can you be more specific? Is your table in .csv format for example?
The normal way of escaping characters (prefixing with \
) works fine for me. For example, here's a CSV file:
"a","b"
50,"b\|a"
Which renders as
Yes, but is it possible to do that without changing the original table? Like, let's say its a table which has |
symbol in it. And it's a standard automatically-generated table,I cant alter its' format. Is there a way to kinda check for this pipe symbol and escape it inside the plagin before passing it to df.to_markdown()?
There are many options in both pd.read_csv and df.to_markdown. Have you found any that work for you?
You can use all those arguments in this plugin. See https://timvink.github.io/mkdocs-table-reader-plugin/customization/
I haven't found any that would solve it. The idea is that I have a file with a tab-delimited table which has |
symbols in it (e.g. this is a single cell - "13|20|33|295|302||35.0;25|31|51|292|298||30.0;22|28|51|295|301||30.0"). I want to include this table in mkdocs. Right now I get columns separated by |
instead of a single cell with a string.
I don't think this is an issue with this plugin. If you're not able to load the table into python using pandas
, then there's something wrong with your table and you need to fix the input.
You can even write a little python function to do that for you, and trigger it to run on build (when you do mkdocs build
or mkdocs serve
) using this plugin: https://github.com/aklajnert/mkdocs-simple-hooks
Hope that helps!
I ran into this problem too and had to change my code to escape all |'s in a string. Would have been really nice if this library did it.
Ok I'll look into making this easier to do.
If you have an example table for me that would be great (so I can write a unit test with it)
It's really not important! It was just a few seconds work to code it on my side. But if you need a file this is what is generated for one of my projects. I use the pipe symbol to show the optional parameters
So this actually is a bug. pandas
uses tabulate
during the .to_markdown()
, which uses the pipe table markdown format. So then mkdocs will add extra columns
I couldn't find any functionality in https://github.com/astanin/python-tabulate to deal with this. I will likely open an issue to see if they want to support it, or otherwise hack it into this plugin. Downside is obviously that searching & replacing characters in columns + all values will costs some performance, but in documentation at least we can expect reasonably small tables.
More details: https://github.com/astanin/python-tabulate/issues/241
I'm going to assume most people insert relatively small tables into their documentation, so looping over all cells and doing a regex to replace all possible pipe characters is a performance hit that could be acceptable. I could offer an option to disable it, but then I would have to run a bunch of benchmark and explain to users in the docs how much it effects performance. For now, not going to overengineer it and choosing for a fix that 'just works'.
Fix will be part of table-reader v2 (#39), which is work-in-progress
thanks @timvink for implementing this.
Is there a way to escape
|
before converting to markdawn? I have a table with|
symbols in cells. And I end up with these cells being splitted into columns.