-
Notifications
You must be signed in to change notification settings - Fork 196
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
Markdown table alignment ignored #412
Comments
Heya, so basically the intention in the markdown parser, is to set a style on each cell: you can see if you put this table into https://markdown-it.github.io, you'll get e.g. <table>
<thead>
<tr>
<th style="text-align:left">a</th>
<th style="text-align:center">b</th>
<th style="text-align:right">c</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">1</td>
<td style="text-align:center">2</td>
<td style="text-align:right">3</td>
</tr>
</tbody>
</table> However, with docutils/sphinx there is no way to propagate a style into the HTML, so currently it is setting these as classes e.g. the same output in sphinx is <table class="colwidths-auto table">
<thead>
<tr class="row-odd">
<th class="text-align:left head"><p>a</p></th>
<th class="text-align:center head"><p>b</p></th>
<th class="text-align:right head"><p>c</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even">
<td class="text-align:left"><p>1</p></td>
<td class="text-align:center"><p>2</p></td>
<td class="text-align:right"><p>3</p></td>
</tr>
</tbody>
</table> There are actually two things not ideal with this table (a) we don't need the paragraph tags (I checked with RST and that also outputs If you want to fix this with the current myst-parser then, the way would be to add some custom CSS to your project: .text-align\:left, text-align\:left > p {
text-align: left
}
.text-align\:center, text-align\:center > p {
text-align: center
}
.text-align\:center, text-align\:right > p {
text-align: right
} A minimal fix here would be to at least document this workaround, probably improve the naming of the CSS classes, and maybe reach out to some of the main themes to include it in their CSS cc @choldgraf (sphinx-book-theme), @pradyunsg (furo) what is your preference for the class names |
Good point about documenting the CSS classes that are output. @jedbrown what Sphinx theme are you using? |
Thanks. This workaround seems adequate. I currently have sites on PyData and RTD themes, though the RTD site should migrate to a newer/mobile-friendly theme (likely PyData or Book). (I notice that Book tables are almost confusingly minimalist.) |
I vote for |
This was surfaced in Furo recently as well (pradyunsg/furo#279). From that conversation, @pradyunsg suggested that we re-use the CSS classes that Sphinx uses in other situations where it left/right aligns things:
EDIT: looks like @pradyunsg beat me to it :-) |
^>^ |
Another way to think about it is to piggy-back on what other common frameworks use. Right now Boostrap uses v4 Bootstrap: https://getbootstrap.com/docs/4.0/utilities/text/ |
A related issue (I think) is that when I use Following the table directive example I found here (https://myst-parser.readthedocs.io/en/latest/syntax/optional.html?highlight=center#code-fences-using-colons)
but with the sphinx-book-theme it generates this: <table class="colwidths-auto table">
<thead>
<tr class="row-odd"><th class="head"><p>loooooooong</p></th>
<th class="head"><p>small</p></th>
<th class="head"><p>small</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>small</p></td>
<td><p>loooooooooooong</p></td>
<td><p>loooooooooooong</p></td>
</tr>
</tbody>
</table> |
This is because of pydata/pydata-sphinx-theme#524 |
Describe the problem
One should be able to create tables with specified alignment, as in
Using MyST, it seems to be at the discretion of the theme. For example, RTD looks like this
while the PyData theme looks like
Link to your repository or website
No response
Steps to reproduce
Paste the above markdown table into a document parsed by MyST.
The version of Python you're using
3.9.6
Your operating system
Arch Linux
Versions of your packages
MyST-Parser 0.15.1
Additional context
No response
The text was updated successfully, but these errors were encountered: