executablebooks / MyST-NB

Parse and execute ipynb files in Sphinx
https://myst-nb.readthedocs.io
BSD 3-Clause "New" or "Revised" License
200 stars 80 forks source link

Tables from code-output not properly rendered #570

Open raphaelquast opened 7 months ago

raphaelquast commented 7 months ago

Describe the bug

context I have a nice markdown table like this:

| a | b | c |
|---|---|---|
| 1 | 2 | 3 |

and I'd like to render it from a code-cell using something like this:

from IPython.display import display, Markdown
display(Markdown(
"""
| a | b | c |
|---|---|---|
| 1 | 2 | 3 |
"""
))

... and in my conf.py i have the following:

myst_render_markdown_format = "myst"

expectation I expected something like this:

image

bug But instead I get this:

image

Reproduce the bug

the description should be enough to reproduce

List your environment

myst-nb 1.0.0 myst-parser 2.0.0

welcome[bot] commented 7 months ago

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

mathisdrn commented 4 months ago

I was also trying to render a dataframe into a proper markdown table and I was able to reproduce bug. This is inconvenient as mystnb should help to format table with data instead of having to write markdown.

raphaelquast commented 4 months ago

@mathisdrn fyi: I found that HTML tables seem to do the job just fine (and pandas supports html-table output as well... )!

import pandas as pd
from IPython.display import display, Markdown
df = pd.DataFrame(dict(a=[1,2,3], b=[4,5,6]))

display(HTML(df.to_html()))