From 1217a49c8968a3a0135ac0e6c26ddc0b7ed60a7c Mon Sep 17 00:00:00 2001 From: Mike Fiedler Date: Sun, 3 Jul 2022 14:59:15 +0000 Subject: [PATCH] fix: enable `colspan` and `rowspan` attributes Previously exlcuded directives made for incorrect rendering of rst table cells spanning more than a single column or row. Fixes #182 Signed-off-by: Mike Fiedler --- readme_renderer/clean.py | 2 +- tests/fixtures/test_rst_tables.html | 62 +++++++++++++++++++++++++++++ tests/fixtures/test_rst_tables.rst | 28 +++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/test_rst_tables.html create mode 100644 tests/fixtures/test_rst_tables.rst diff --git a/readme_renderer/clean.py b/readme_renderer/clean.py index 332dd5b..be430cd 100644 --- a/readme_renderer/clean.py +++ b/readme_renderer/clean.py @@ -46,7 +46,7 @@ "img": ["src", "width", "height", "alt", "align", "class"], "span": ["class"], "th": ["align"], - "td": ["align"], + "td": ["align", "colspan", "rowspan"], "div": ["align", "class"], "h1": ["align"], "h2": ["align"], diff --git a/tests/fixtures/test_rst_tables.html b/tests/fixtures/test_rst_tables.html new file mode 100644 index 0000000..2e2a984 --- /dev/null +++ b/tests/fixtures/test_rst_tables.html @@ -0,0 +1,62 @@ + ++++++ + + + + + + + + + + + + + + + + + + + + + + + +
Header row, column 1 +(header rows optional)Header 2Header 3Header 4
body row 1, column 1column 2column 3column 4
body row 2Cells may span columns.
body row 3Cells may +span rows.
    +
  • Table cells
  • +
  • contain
  • +
  • body elements.
  • +
+
body row 4
+ ++++ + + + + + + + + + + + + + + + + + + +
title1title2
col1col2
mutirowcell1
cell2
singlerowcell3
diff --git a/tests/fixtures/test_rst_tables.rst b/tests/fixtures/test_rst_tables.rst new file mode 100644 index 0000000..52ceaa2 --- /dev/null +++ b/tests/fixtures/test_rst_tables.rst @@ -0,0 +1,28 @@ +.. Example from https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#tables + ++------------------------+------------+----------+----------+ +| Header row, column 1 | Header 2 | Header 3 | Header 4 | +| (header rows optional) | | | | ++========================+============+==========+==========+ +| body row 1, column 1 | column 2 | column 3 | column 4 | ++------------------------+------------+----------+----------+ +| body row 2 | Cells may span columns. | ++------------------------+------------+---------------------+ +| body row 3 | Cells may | - Table cells | ++------------------------+ span rows. | - contain | +| body row 4 | | - body elements. | ++------------------------+------------+---------------------+ + +.. Example from #182 + ++---------------+---------------+ +| title1 | title2 | ++===============+===============+ +| col1 | col2 | ++---------------+---------------+ +| mutirow | cell1 | +| +---------------+ +| | cell2 | ++---------------+---------------+ +| singlerow | cell3 | ++---------------+---------------+