Skip to content

Commit

Permalink
Fix table Cell borders are wrongly applied on the run #156
Browse files Browse the repository at this point in the history
  • Loading branch information
onizet committed Aug 23, 2024
1 parent 577148c commit 2302820
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ protected override void ComposeStyles(ParsingContext context)
};

cellProperties.TableCellBorders = borders;
// we apply the borders on the cell level, not the run
runProperties.Border = null;
}
}
}
23 changes: 21 additions & 2 deletions test/HtmlToOpenXml.Tests/TableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,6 @@ public void DoubleRowSpanSameLine_ShouldSucceed()
Assert.That(elements, Has.All.TypeOf<Table>());
Assert.That(elements[0].GetFirstChild<TableGrid>()?.Elements<GridColumn>().Count(), Is.EqualTo(4));

Assert.That(elements, Has.Count.EqualTo(1));
Assert.That(elements, Has.All.TypeOf<Table>());
var rows = elements[0].Elements<TableRow>();
Assert.That(rows.Count(), Is.EqualTo(2));
Assert.That(rows.Select(r => r.Elements<TableCell>().Count()),
Expand All @@ -608,5 +606,26 @@ public void DoubleRowSpanSameLine_ShouldSucceed()
Assert.That(rows.ElementAt(1).GetFirstChild<TableCell>()?.TableCellProperties?.VerticalMerge?.Val?.Value, Is.EqualTo(MergedCellValues.Continue));
Assert.That(rows.ElementAt(1).GetLastChild<TableCell>()?.TableCellProperties?.VerticalMerge?.Val?.Value, Is.EqualTo(MergedCellValues.Continue));
}

[Test(Description = "Cell borders should not be applied on inner runs #156")]
public void CellBorders_ShouldNotPropagate_OnRuns()
{
var elements = converter.Parse(@"<table>
<tr>
<td style='width: 120px; border: 1px solid #ababab'>Placeholder</td>
</tr>
</table>");

Assert.That(elements, Has.Count.EqualTo(1));
Assert.That(elements, Has.All.TypeOf<Table>());
var cells = elements[0].GetFirstChild<TableRow>()?.Elements<TableCell>();
Assert.That(cells?.Count(), Is.EqualTo(1));
Assert.That(cells.First().TableCellProperties?.TableCellBorders, Is.Not.Null);
var paragraphs = cells.First().Elements<Paragraph>();
Assert.That(paragraphs.Count(), Is.EqualTo(1));
var runs = paragraphs.First().Elements<Run>();
Assert.That(runs.Count(), Is.EqualTo(1));
Assert.That(runs.First().RunProperties?.Border, Is.Null);
}
}
}

0 comments on commit 2302820

Please sign in to comment.