New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gfm output of pandas dataframes rendered incorrectly on GitHub #2152
Comments
Style scoped seems to not be widely supported: https://caniuse.com/style-scoped |
I believe also the GFM does not allow the use of So IMO this is not valid HTML for Github preview to HTML I don't think Quarto can do something about this as this is about how Github is rendering Markdown to HTML. |
The <style scoped> tags were produced by Quarto, not Github. See "Output md raw:" in the first comment. I agree that it is not valid HTML for Github preview but that HTML is part of the Markdown file that Quarto created from a qmd file (contents also in the first comment). |
I see. thank @kalenkovich for pointing that out more clearly for me. What I meant really is that quarto does not add this For example, explicitly output markdown will output a compatible GFM document I think ---
title: "Untitled"
format: gfm
keep-md: true
---
```{python}
#| output: asis
from IPython.display import Markdown
import pandas as pd
iris = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')
print(iris.head().to_markdown())
```
Which renders to Untitled
================
``` python
from IPython.display import Markdown
import pandas as pd
iris = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')
print(iris.head().to_markdown())
```
| | sepal_length | sepal_width | petal_length | petal_width | species |
|----:|-------------:|------------:|-------------:|------------:|:--------|
| 0 | 5.1 | 3.5 | 1.4 | 0.2 | setosa |
| 1 | 4.9 | 3 | 1.4 | 0.2 | setosa |
| 2 | 4.7 | 3.2 | 1.3 | 0.2 | setosa |
| 3 | 4.6 | 3.1 | 1.5 | 0.2 | setosa |
| 4 | 5 | 3.6 | 1.4 | 0.2 | setosa | Rendered as HTML below Untitledfrom IPython.display import Markdown
import pandas as pd
iris = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')
print(iris.head().to_markdown())
Probably there is something we can do to try output Markdown for Pandas table when in |
@cderv A more careful orchestration of quarto formats and downstream table printing is definitely needed. (Ideally we'd define an API for these things that clients can implement) |
Here is a relevant nbconvert issue and another one with two workarounds. The workarounds are:
|
Flagging this to 1.3 because we can't ask pandas to fix this until we have support for signaling downstream libraries about quarto, and that will be a 1.2 feature. |
You can tell IPython how to represent a DataFrame -> HTML (or markdown). (see these IPython docs) For example , this changes the default DataFrame html representation in IPython (and the jupyter notebook) to use DataFrame.to_html, with custom options: import pandas as pd
from IPython import get_ipython
# special ipython function to get the html formatter
html_formatter = get_ipython().display_formatter.formatters['text/html']
html_formatter.for_type(
pd.DataFrame,
lambda df: df.to_html(max_rows = pd.get_option("display.max_rows"), show_dimensions = True)
) Here's a qmd example:
Which outputs this HTML table <table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>x</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>1</td>
</tr>
</tbody>
</table>
<p>1 rows × 1 columns</p> |
@machow This is a really good move to know about, thank you. I think the existence of this path is enough for us to close this issue. I'll note that there's a new feature coming in quarto 1.3 where we process HTML tables in every format and turn them into markdown by default. This gets markdown-readable tables, but
This will produce HTML table in gfm output. |
We could at least make an example maybe 🤔 Existing examples are in https://github.com/quarto-dev/quarto-examples/ |
Yes, this does need to be documented better. We've overhauled our table treatment for 1.3, and the documentation will be there. |
Bug description
gfm output that has pandas dataframes printed out, renders incorrectly on Github, possibly because of GitHub not respecting <style scoped> tags.
Input qmd:
Output md raw:
Output md rendered:
I am on Mac OS Big Sur and using VS Code 1.70.2.
Checklist
The text was updated successfully, but these errors were encountered: