From 056ab4d9a1d9878418c6e246482c2af1d8c85722 Mon Sep 17 00:00:00 2001 From: Jean Abou Samra Date: Sun, 15 May 2022 00:03:46 +0200 Subject: [PATCH 1/2] Round column widths to integers Don't use floats, since some Sphinx builders expect the widths to be integers, like the Texinfo builder and the text builder. Closes #540 --- myst_parser/mdit_to_docutils/base.py | 2 +- .../fixtures/sphinx_directives.md | 4 ++-- tests/test_renderers/fixtures/tables.md | 22 +++++++++---------- .../test_sphinx/sourcedirs/texi_table/conf.py | 2 ++ .../sourcedirs/texi_table/index.md | 3 +++ tests/test_sphinx/test_sphinx_builds.py | 16 ++++++++++++++ .../test_basic.resolved.sphinx4.xml | 4 ++-- .../test_sphinx_builds/test_basic.sphinx4.xml | 4 ++-- .../test_gettext_html.resolved.sphinx4.xml | 2 +- .../test_gettext_html.sphinx4.xml | 2 +- 10 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 tests/test_sphinx/sourcedirs/texi_table/conf.py create mode 100644 tests/test_sphinx/sourcedirs/texi_table/index.md diff --git a/myst_parser/mdit_to_docutils/base.py b/myst_parser/mdit_to_docutils/base.py index 099b5ad1..252cc353 100644 --- a/myst_parser/mdit_to_docutils/base.py +++ b/myst_parser/mdit_to_docutils/base.py @@ -912,7 +912,7 @@ def render_table(self, token: SyntaxTreeNode) -> None: # column settings element maxcols = len(header_row.children) - colwidths = [round(100 / maxcols, 2)] * maxcols + colwidths = [100 // maxcols] * maxcols tgroup = nodes.tgroup(cols=len(colwidths)) table += tgroup for colwidth in colwidths: diff --git a/tests/test_renderers/fixtures/sphinx_directives.md b/tests/test_renderers/fixtures/sphinx_directives.md index 16a5fa74..2084558e 100644 --- a/tests/test_renderers/fixtures/sphinx_directives.md +++ b/tests/test_renderers/fixtures/sphinx_directives.md @@ -241,8 +241,8 @@ table (`sphinx.directives.patches.RSTTable`): title - - + + diff --git a/tests/test_renderers/fixtures/tables.md b/tests/test_renderers/fixtures/tables.md index f24a86cc..b478b926 100644 --- a/tests/test_renderers/fixtures/tables.md +++ b/tests/test_renderers/fixtures/tables.md @@ -7,8 +7,8 @@ a|b - - + + @@ -35,8 +35,8 @@ Header only:
- - + + @@ -56,9 +56,9 @@ a | b | c
- - - + + + @@ -92,8 +92,8 @@ Nested syntax:
- - + + @@ -125,8 +125,8 @@ a|b
- - + + diff --git a/tests/test_sphinx/sourcedirs/texi_table/conf.py b/tests/test_sphinx/sourcedirs/texi_table/conf.py new file mode 100644 index 00000000..e1c5009b --- /dev/null +++ b/tests/test_sphinx/sourcedirs/texi_table/conf.py @@ -0,0 +1,2 @@ +extensions = ["myst_parser"] +exclude_patterns = ["_build"] diff --git a/tests/test_sphinx/sourcedirs/texi_table/index.md b/tests/test_sphinx/sourcedirs/texi_table/index.md new file mode 100644 index 00000000..9face4b5 --- /dev/null +++ b/tests/test_sphinx/sourcedirs/texi_table/index.md @@ -0,0 +1,3 @@ +| foo | bar | +| --- | --- | +| baz | bim | diff --git a/tests/test_sphinx/test_sphinx_builds.py b/tests/test_sphinx/test_sphinx_builds.py index e8615a64..7040e035 100644 --- a/tests/test_sphinx/test_sphinx_builds.py +++ b/tests/test_sphinx/test_sphinx_builds.py @@ -547,3 +547,19 @@ def test_fieldlist_extension( regress_html=True, regress_ext=f".sphinx{sphinx.version_info[0]}.html", ) + +@pytest.mark.sphinx( + buildername="texinfo", + srcdir=os.path.join(SOURCE_DIR, "texi_table"), + freshenv=True, +) +def test_texinfo_table( + app, + status, + warning, +): + """Test that tables can be built with the Texinfo builder.""" + app.build() + assert "build succeeded" in status.getvalue() # Build succeeded + warnings = warning.getvalue().strip() + assert warnings == "" diff --git a/tests/test_sphinx/test_sphinx_builds/test_basic.resolved.sphinx4.xml b/tests/test_sphinx/test_sphinx_builds/test_basic.resolved.sphinx4.xml index ed086997..8a12765e 100644 --- a/tests/test_sphinx/test_sphinx_builds/test_basic.resolved.sphinx4.xml +++ b/tests/test_sphinx/test_sphinx_builds/test_basic.resolved.sphinx4.xml @@ -75,8 +75,8 @@ a=1{`}
- - + + diff --git a/tests/test_sphinx/test_sphinx_builds/test_basic.sphinx4.xml b/tests/test_sphinx/test_sphinx_builds/test_basic.sphinx4.xml index c793d318..34b0e3c3 100644 --- a/tests/test_sphinx/test_sphinx_builds/test_basic.sphinx4.xml +++ b/tests/test_sphinx/test_sphinx_builds/test_basic.sphinx4.xml @@ -76,8 +76,8 @@ a=1{`}
- - + + diff --git a/tests/test_sphinx/test_sphinx_builds/test_gettext_html.resolved.sphinx4.xml b/tests/test_sphinx/test_sphinx_builds/test_gettext_html.resolved.sphinx4.xml index 1b1c195b..231ca337 100644 --- a/tests/test_sphinx/test_sphinx_builds/test_gettext_html.resolved.sphinx4.xml +++ b/tests/test_sphinx/test_sphinx_builds/test_gettext_html.resolved.sphinx4.xml @@ -43,7 +43,7 @@ gras
- + diff --git a/tests/test_sphinx/test_sphinx_builds/test_gettext_html.sphinx4.xml b/tests/test_sphinx/test_sphinx_builds/test_gettext_html.sphinx4.xml index 0d8dbc79..dfc5f414 100644 --- a/tests/test_sphinx/test_sphinx_builds/test_gettext_html.sphinx4.xml +++ b/tests/test_sphinx/test_sphinx_builds/test_gettext_html.sphinx4.xml @@ -43,7 +43,7 @@ gras
- + From b575490a7f24ef38055530795b9e0202acdf2350 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 14 May 2022 22:08:09 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_sphinx/test_sphinx_builds.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_sphinx/test_sphinx_builds.py b/tests/test_sphinx/test_sphinx_builds.py index 7040e035..ca34c733 100644 --- a/tests/test_sphinx/test_sphinx_builds.py +++ b/tests/test_sphinx/test_sphinx_builds.py @@ -548,6 +548,7 @@ def test_fieldlist_extension( regress_ext=f".sphinx{sphinx.version_info[0]}.html", ) + @pytest.mark.sphinx( buildername="texinfo", srcdir=os.path.join(SOURCE_DIR, "texi_table"),