diff --git a/Source/HtmlRenderer/Core/Dom/CssLayoutEngineTable.cs b/Source/HtmlRenderer/Core/Dom/CssLayoutEngineTable.cs index 382602c60..cc683aec7 100644 --- a/Source/HtmlRenderer/Core/Dom/CssLayoutEngineTable.cs +++ b/Source/HtmlRenderer/Core/Dom/CssLayoutEngineTable.cs @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; +using System.Linq; using TheArtOfDev.HtmlRenderer.Adapters; using TheArtOfDev.HtmlRenderer.Adapters.Entities; using TheArtOfDev.HtmlRenderer.Core.Entities; @@ -293,8 +294,9 @@ private double CalculateCountAndWidth() } else { + // A cell takes as many columns as its colspan, HTML 4.9.12.1 foreach (CssBox b in _allRows) - _columnCount = Math.Max(_columnCount, b.Boxes.Count); + _columnCount = Math.Max(_columnCount, b.Boxes.Sum(cell => Math.Max(GetColSpan(cell), 1))); } //Initialize column widths array with NaNs diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Tables/ColspanIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Tables/ColspanIntegrationTests.cs new file mode 100644 index 000000000..2943fc2a1 --- /dev/null +++ b/Source/Test/HtmlRenderer.IntegrationTest/Tables/ColspanIntegrationTests.cs @@ -0,0 +1,24 @@ +using HtmlRenderer.IntegrationTest.TestSupport; + +namespace HtmlRenderer.IntegrationTest.Tables; + +[TestClass] +public sealed class ColspanIntegrationTests +{ + private const double Delta = 1.0; + + [TestMethod] + [Spec("html", "tables.html#forming-a-table")] + public void RowsWithDifferentCellCounts_ShareTheColumnsTheirColspansAddUpTo() + { + var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap( + "" + + "
Test8 570Test
1 4491 187
")); + var a = LayoutHarness.FindById(root, "a")!; + var b = LayoutHarness.FindById(root, "b")!; + var c = LayoutHarness.FindById(root, "c")!; + + Assert.IsGreaterThan(a.ActualBottom, c.Location.Y); + Assert.AreEqual(b.Location.X, c.Location.X, Delta); + } +} diff --git a/Source/Test/HtmlRenderer.Test/Html/TablesTests.cs b/Source/Test/HtmlRenderer.Test/Html/TablesTests.cs index ed1b37b55..ad3cce4e5 100644 --- a/Source/Test/HtmlRenderer.Test/Html/TablesTests.cs +++ b/Source/Test/HtmlRenderer.Test/Html/TablesTests.cs @@ -133,7 +133,6 @@ public void Colspan_AboveAThousand_IsClampedToAThousand() } [TestMethod] - [Ignore("Gap, see Spec/html.yml")] [Spec("html", "tables.html#forming-a-table")] public void Colspan_AddsColumns() { @@ -143,7 +142,6 @@ public void Colspan_AddsColumns() } [TestMethod] - [Ignore("Gap, see Spec/html.yml")] [Spec("html", "tables.html#forming-a-table")] public void CellSpanningPastTheOtherRows_IsLaidOut() { diff --git a/Spec/html.yml b/Spec/html.yml index 8fc571108..931ac775a 100644 --- a/Spec/html.yml +++ b/Spec/html.yml @@ -892,8 +892,6 @@ sections: title: 4.9.12.1 Forming a table status: partial gaps: - - The column count is the highest number of cells in a row, colspan doesn't add columns, so a cell past it gets no width - - A cell spanning past that column count breaks the layout of the whole table - Cells past the columns declared by col and colgroup aren't laid out - A colspan of 0 or below breaks the layout of the whole table instead of counting as 1 - colspan isn't clamped to 1000