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( + "
| Test | 8 570 | Test | ||
| 1 449 | 1 187 | |||