Closed ncarboni closed 4 years ago
Thanks for the feedback, glad to hear you like it! And a different use case than I imaged when I created it, nice!
This plugin uses df.to_markdown()
to create markdown from a table. That's included in pandas>=1.03
, but actually uses tabulate
under the hood.
**kwargs These parameters will be passed to tabulate. docs for pandas.DataFrame.to_markdown
Currently, this is what the call looks like in this plugin:
There are other parameters supported by tabulate
, see python-tabulate. Specifically the section on line-breaks is very relevant: "Note that some output formats (e.g. simple, or plain) do not represent row delimiters, so that the representation of multiline cells in such formats may be ambiguous to the reader" . The default is tablefmt="simple"
so it might be useful to try a different format.
MkDocs uses python-markdown which implements this reference syntax. That one doesn't include tables, which is why python-markdown has a tables extension. That extension in turn uses the PHP Extra Markdown syntax for tables, which is supported by tabulate
via tablefmt="pipe"
, which is included in the list of output formats that support multiline cells!
That was a fun bit of detective work :) With this knowledge, I think "pipe"
should be the default tablefmt
for this plugin. I created a new merge request with the change in #3 that we can test.
tablefmt="pipe"
output setting. Can you test (by installing #3) if this solves your issue before I release a new version?\n
instead of \r\n
). contextThanks for the explanation, it is quite useful to understand the possibilities. I quickly tried yesterday using tablefmt="pipe", but I still did not get any multiline. I will do some other testing today (I will try other tablefmt options and see if something change) and come back with more info. In the meanwhile, thank you very much!
A bit of recap after some tests.
I added tablefmt="pipe" (return df.to_markdown(showindex=False, tablefmt="pipe"
) to read_csv and read_excel, and re-installed the package. However, I do not see any differences in the creation of the table. I tried with other table format from python-tabulate, but they did not seems to work either.
I tried to inserti a \n
in order to signal a <br>
in the cell of the CSV or excel file, but also there I did not obtained a real carriage return but only a new row.
I am maybe doing something wrong from my side? Did you by any chance make it work?
Did some experiments (and found + fixed a different bug in #4).
This csv:
Renders as:
However inserting <br/
> directly works as intended, and might already be the solution for your specific use-case:
It seems that the csv
standard does not support escape characters like \n
(source). Alternatively, specifying the newline differently in the CSV creates a new row but the alignment is proper:
I'm not sure what the proper behaviour should be, and where that should be addressed. Most likely it's in python-markdown
tables extension. But the root cause is not in mkdocs-table-reader-plugin
, so I suggest to close this issue. I might investigate further and open a new issue elsewhere.
FYI, I opened https://github.com/Python-Markdown/markdown/issues/975
Thanks for the testing! If will use
for now and let's see if something will change from python-markdown side. Feel free to close :-)
Long story short, for multiline cells the solution is to use <br/>
. (see also the python-markdown
issue). If you need anything more complex, you can always fall back to raw HTML tables.
I am testing with this plugin and it is already fantastic, but I was wondering if there is a way to take into account carriage return within a cell. I would like a cell to display
But if I tried to load a CSV with a carriage return I obtain this:
fair enough, it is a CSV. Using an excel file (using
{{ read_excel('file'.xlsx) }}
instead I obtain this result:While nicer the result coming from excel do present a new line instead of a carriage return within the same cell. I was wondering if it would be possible to have a real carriage return, something like this (obtained using
<br>
):