Skip to content

Commit 3c45b7e

Browse files
authored
🐛 FIX: floor table column widths to integers (#568)
1 parent 602470e commit 3c45b7e

10 files changed

Lines changed: 42 additions & 20 deletions

File tree

myst_parser/mdit_to_docutils/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ def render_table(self, token: SyntaxTreeNode) -> None:
912912

913913
# column settings element
914914
maxcols = len(header_row.children)
915-
colwidths = [round(100 / maxcols, 2)] * maxcols
915+
colwidths = [100 // maxcols] * maxcols
916916
tgroup = nodes.tgroup(cols=len(colwidths))
917917
table += tgroup
918918
for colwidth in colwidths:

tests/test_renderers/fixtures/sphinx_directives.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ table (`sphinx.directives.patches.RSTTable`):
241241
<emphasis>
242242
title
243243
<tgroup cols="2">
244-
<colspec colwidth="50.0">
245-
<colspec colwidth="50.0">
244+
<colspec colwidth="50">
245+
<colspec colwidth="50">
246246
<thead>
247247
<row>
248248
<entry>

tests/test_renderers/fixtures/tables.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ a|b
77
<document source="<src>/index.md">
88
<table classes="colwidths-auto">
99
<tgroup cols="2">
10-
<colspec colwidth="50.0">
11-
<colspec colwidth="50.0">
10+
<colspec colwidth="50">
11+
<colspec colwidth="50">
1212
<thead>
1313
<row>
1414
<entry>
@@ -35,8 +35,8 @@ Header only:
3535
<document source="<src>/index.md">
3636
<table classes="colwidths-auto">
3737
<tgroup cols="2">
38-
<colspec colwidth="50.0">
39-
<colspec colwidth="50.0">
38+
<colspec colwidth="50">
39+
<colspec colwidth="50">
4040
<thead>
4141
<row>
4242
<entry>
@@ -56,9 +56,9 @@ a | b | c
5656
<document source="<src>/index.md">
5757
<table classes="colwidths-auto">
5858
<tgroup cols="3">
59-
<colspec colwidth="33.33">
60-
<colspec colwidth="33.33">
61-
<colspec colwidth="33.33">
59+
<colspec colwidth="33">
60+
<colspec colwidth="33">
61+
<colspec colwidth="33">
6262
<thead>
6363
<row>
6464
<entry classes="text-left">
@@ -92,8 +92,8 @@ Nested syntax:
9292
<document source="<src>/index.md">
9393
<table classes="colwidths-auto">
9494
<tgroup cols="2">
95-
<colspec colwidth="50.0">
96-
<colspec colwidth="50.0">
95+
<colspec colwidth="50">
96+
<colspec colwidth="50">
9797
<thead>
9898
<row>
9999
<entry>
@@ -125,8 +125,8 @@ a|b
125125
<document source="<src>/index.md">
126126
<table classes="colwidths-auto">
127127
<tgroup cols="2">
128-
<colspec colwidth="50.0">
129-
<colspec colwidth="50.0">
128+
<colspec colwidth="50">
129+
<colspec colwidth="50">
130130
<thead>
131131
<row>
132132
<entry>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
extensions = ["myst_parser"]
2+
exclude_patterns = ["_build"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| foo | bar |
2+
| --- | --- |
3+
| baz | bim |

tests/test_sphinx/test_sphinx_builds.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,3 +547,20 @@ def test_fieldlist_extension(
547547
regress_html=True,
548548
regress_ext=f".sphinx{sphinx.version_info[0]}.html",
549549
)
550+
551+
552+
@pytest.mark.sphinx(
553+
buildername="texinfo",
554+
srcdir=os.path.join(SOURCE_DIR, "texi_table"),
555+
freshenv=True,
556+
)
557+
def test_texinfo_table(
558+
app,
559+
status,
560+
warning,
561+
):
562+
"""Test that tables can be built with the Texinfo builder."""
563+
app.build()
564+
assert "build succeeded" in status.getvalue() # Build succeeded
565+
warnings = warning.getvalue().strip()
566+
assert warnings == ""

tests/test_sphinx/test_sphinx_builds/test_basic.resolved.sphinx4.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
a=1{`}
7676
<table classes="colwidths-auto">
7777
<tgroup cols="2">
78-
<colspec colwidth="50.0">
79-
<colspec colwidth="50.0">
78+
<colspec colwidth="50">
79+
<colspec colwidth="50">
8080
<thead>
8181
<row>
8282
<entry>

tests/test_sphinx/test_sphinx_builds/test_basic.sphinx4.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@
7676
a=1{`}
7777
<table classes="colwidths-auto">
7878
<tgroup cols="2">
79-
<colspec colwidth="50.0">
80-
<colspec colwidth="50.0">
79+
<colspec colwidth="50">
80+
<colspec colwidth="50">
8181
<thead>
8282
<row>
8383
<entry>

tests/test_sphinx/test_sphinx_builds/test_gettext_html.resolved.sphinx4.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
gras
4444
<table classes="colwidths-auto">
4545
<tgroup cols="1">
46-
<colspec colwidth="100.0">
46+
<colspec colwidth="100">
4747
<thead>
4848
<row>
4949
<entry>

tests/test_sphinx/test_sphinx_builds/test_gettext_html.sphinx4.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
gras
4444
<table classes="colwidths-auto">
4545
<tgroup cols="1">
46-
<colspec colwidth="100.0">
46+
<colspec colwidth="100">
4747
<thead>
4848
<row>
4949
<entry>

0 commit comments

Comments
 (0)