Skip to content

Commit

Permalink
Fix a bug when li is empty #151
Browse files Browse the repository at this point in the history
  • Loading branch information
onizet committed Sep 6, 2024
1 parent 112e412 commit e642278
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Html2OpenXml/Expressions/Numbering/ListExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public override IEnumerable<OpenXmlElement> Interpret(ParsingContext context)
{
var expression = new BlockElementExpression(liNode);
var childElements = expression.Interpret(context);
if (!childElements.Any()) continue;
Paragraph p = (Paragraph) childElements.First();

p.ParagraphProperties ??= new();
Expand Down
10 changes: 10 additions & 0 deletions test/HtmlToOpenXml.Tests/NumberingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ public void EmptyList_ShouldBeIgnored()
}
}

[Test(Description = "Empty list item should not be registred")]
public void EmptyLiElement_ShouldBeIgnored()
{
var elements = converter.Parse(@"<ul>
<li>not empty</li>
<li></li>
</ul>");
Assert.That(elements, Has.Count.EqualTo(1));
}

[Test(Description = "Increment instanceId based on existing lists")]
public void WithExistingNumbering_ReturnsUniqueInstanceId()
{
Expand Down

0 comments on commit e642278

Please sign in to comment.