-
Notifications
You must be signed in to change notification settings - Fork 128
Closed
Description
Describe the bug
When trying to parse html that contains an empty list element:
<ul>
<li>not empty</li>
<li></li>
</ul>an System.InvalidOperationException is thrown.
Stacktrace:
Unhandled exception. System.InvalidOperationException: Sequence contains no elements
at System.Linq.ThrowHelper.ThrowNoElementsException()
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at HtmlToOpenXml.Expressions.ListExpression.<Interpret>d__4.MoveNext()
at HtmlToOpenXml.Expressions.BlockElementExpression.ComposeChildren(ParsingContext context, IEnumerable`1 childNodes, ParagraphProperties paragraphProperties, Action`1 preAction, Action`1 postAction)
at HtmlToOpenXml.Expressions.BlockElementExpression.Interpret(ParsingContext context, IEnumerable`1 childNodes)
at HtmlToOpenXml.Expressions.PhrasingElementExpression.Interpret(ParsingContext context)
at HtmlToOpenXml.Expressions.BlockElementExpression.Interpret(ParsingContext context)
at HtmlToOpenXml.Expressions.BodyExpression.Interpret(ParsingContext context)
at HtmlToOpenXml.HtmlConverter.<Parse>d__8.MoveNext()
at HtmlToOpenXml.HtmlConverter.Parse(String html)
at Program.<Main>$(String[] args) in C:\git\MyApp\MyApp\Program.cs:line 10
Expected behavior
An exception should not be thrown when the html contains an empty list element.
Repro
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml;
using HtmlToOpenXml;
using var stream = new MemoryStream();
using var document = WordprocessingDocument.Create(stream, WordprocessingDocumentType.Document);
var converter = new HtmlConverter(document.AddMainDocumentPart());
converter.Parse("""
<ul>
<li>not empty</li>
<li></li>
</ul>
""");Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels