Skip to content
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

Enable :widths: option in table directives. #795

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion myst_parser/mdit_to_docutils/base.py
Expand Up @@ -1349,7 +1349,6 @@ def render_table(self, token: SyntaxTreeNode) -> None:

# top-level element
table = nodes.table()
table["classes"] += ["colwidths-auto"]
self.copy_attributes(token, table, ("class", "id"))
self.add_line_and_source_path(table, token)
self.current_node.append(table)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_renderers/fixtures/docutil_link_resolution.md
Expand Up @@ -169,7 +169,7 @@ c | d
[explicit](#table)
.
<document source="<src>/index.md">
<table classes="colwidths-auto" ids="table" names="table">
<table ids="table" names="table">
<title>
caption
<tgroup cols="2">
Expand Down
111 changes: 111 additions & 0 deletions tests/test_renderers/fixtures/sphinx_directives.md
Expand Up @@ -230,6 +230,43 @@ table (`sphinx.directives.patches.RSTTable`):
```{table} *title*
:name: name

| a | b |
|---|---|
| 1 | 2 |
```
.
<document source="<src>/index.md">
<table ids="name" names="name">
<title>
<emphasis>
title
<tgroup cols="2">
<colspec colwidth="50">
<colspec colwidth="50">
<thead>
<row>
<entry>
<paragraph>
a
<entry>
<paragraph>
b
<tbody>
<row>
<entry>
<paragraph>
1
<entry>
<paragraph>
2
.

table widths auto (`sphinx.directives.patches.RSTTable`):
.
```{table} *title*
:name: name
:widths: auto

| a | b |
|---|---|
| 1 | 2 |
Expand Down Expand Up @@ -261,6 +298,80 @@ table (`sphinx.directives.patches.RSTTable`):
2
.

table widths grid (`sphinx.directives.patches.RSTTable`):
.
```{table} *title*
:name: name
:widths: grid

| a | b |
|---|---|
| 1 | 2 |
```
.
<document source="<src>/index.md">
<table classes="colwidths-given" ids="name" names="name">
<title>
<emphasis>
title
<tgroup cols="2">
<colspec colwidth="50">
<colspec colwidth="50">
<thead>
<row>
<entry>
<paragraph>
a
<entry>
<paragraph>
b
<tbody>
<row>
<entry>
<paragraph>
1
<entry>
<paragraph>
2
.

table widths given (`sphinx.directives.patches.RSTTable`):
.
```{table} *title*
:name: name
:widths: 1 2

| a | b |
|---|---|
| 1 | 2 |
```
.
<document source="<src>/index.md">
<table classes="colwidths-given" ids="name" names="name">
<title>
<emphasis>
title
<tgroup cols="2">
<colspec colwidth="1">
<colspec colwidth="2">
<thead>
<row>
<entry>
<paragraph>
a
<entry>
<paragraph>
b
<tbody>
<row>
<entry>
<paragraph>
1
<entry>
<paragraph>
2
.

csv-table (`sphinx.directives.patches.CSVTable`):
.
```{csv-table}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_renderers/fixtures/sphinx_link_resolution.md
Expand Up @@ -155,7 +155,7 @@ c | d
[explicit](#table)
.
<document source="<src>/index.md">
<table classes="colwidths-auto" ids="table" names="table">
<table ids="table" names="table">
<title>
caption
<tgroup cols="2">
Expand Down
10 changes: 5 additions & 5 deletions tests/test_renderers/fixtures/tables.md
Expand Up @@ -5,7 +5,7 @@ a|b
1|2
.
<document source="<src>/index.md">
<table classes="colwidths-auto">
<table>
<tgroup cols="2">
<colspec colwidth="50">
<colspec colwidth="50">
Expand Down Expand Up @@ -33,7 +33,7 @@ Header only:
| --- | --- |
.
<document source="<src>/index.md">
<table classes="colwidths-auto">
<table>
<tgroup cols="2">
<colspec colwidth="50">
<colspec colwidth="50">
Expand All @@ -54,7 +54,7 @@ a | b | c
1 | 2 | 3
.
<document source="<src>/index.md">
<table classes="colwidths-auto">
<table>
<tgroup cols="3">
<colspec colwidth="33">
<colspec colwidth="33">
Expand Down Expand Up @@ -90,7 +90,7 @@ Nested syntax:
|c | {sub}`x` |
.
<document source="<src>/index.md">
<table classes="colwidths-auto">
<table>
<tgroup cols="2">
<colspec colwidth="50">
<colspec colwidth="50">
Expand Down Expand Up @@ -123,7 +123,7 @@ a|b
[link-a](https://www.google.com/)|[link-b](https://www.python.org/)
.
<document source="<src>/index.md">
<table classes="colwidths-auto">
<table>
<tgroup cols="2">
<colspec colwidth="50">
<colspec colwidth="50">
Expand Down
Expand Up @@ -73,7 +73,7 @@
<paragraph>
<literal>
a=1{`}
<table classes="colwidths-auto">
<table>
<tgroup cols="2">
<colspec colwidth="50">
<colspec colwidth="50">
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sphinx/test_sphinx_builds/test_basic.xml
Expand Up @@ -74,7 +74,7 @@
<paragraph>
<literal>
a=1{`}
<table classes="colwidths-auto">
<table>
<tgroup cols="2">
<colspec colwidth="50">
<colspec colwidth="50">
Expand Down
Expand Up @@ -41,7 +41,7 @@
texte 8 en
<strong>
gras
<table classes="colwidths-auto">
<table>
<tgroup cols="1">
<colspec colwidth="100">
<thead>
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sphinx/test_sphinx_builds/test_gettext_html.xml
Expand Up @@ -41,7 +41,7 @@
texte 8 en
<strong>
gras
<table classes="colwidths-auto">
<table>
<tgroup cols="1">
<colspec colwidth="100">
<thead>
Expand Down