Skip to content

Commit

Permalink
Enable :widths: option in table directives.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhcole committed Jul 22, 2023
1 parent 350c633 commit 7cf70b4
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 12 deletions.
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

0 comments on commit 7cf70b4

Please sign in to comment.