baynezy / Html2Markdown

A library for converting HTML to markdown syntax in C#
Apache License 2.0
271 stars 51 forks source link

Having an extra <ul> tag throws an error "System.InvalidOperationException: Sequence contains no elements" #395

Closed shettyanusha closed 3 months ago

shettyanusha commented 3 months ago

Report issue

If there is an extra <ul> in the html string, the package throws the below error System.InvalidOperationException: Sequence contains no elements at System.Linq.ThrowHelper.ThrowNoElementsException() at System.Linq.Enumerable.Aggregate[TSource](IEnumerable1 source, Func3 func) at Html2Markdown.Replacement.HtmlParser.ReplaceList(String html) at Html2Markdown.Replacement.HtmlParser.ReplaceLists(String html) at Html2Markdown.Replacement.CustomReplacer.Replace(String html) at Html2Markdown.Converter.<>c.b__5_0(String current, IReplacer element) at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable1 source, TAccumulate seed, Func3 func) at Html2Markdown.Converter.Convert(String html)

The String used to test this - <ul><ul><li>first list val</li></ul></ul>

Expected behavior

The extra <ul> tag should be ignored.

Actual Behaviour

Error

Steps to reproduce the problem

var description = "<ul><ul><li>first list val</li></ul></ul>"; var converter = new Converter(); markdown = converter.Convert(description);

baynezy commented 3 months ago

@shettyanusha thanks for raising the bug. Are you using the latest version of the package? If I try and use your reproduction case I get an empty string. That is obviously still a bug but not this error.

baynezy commented 3 months ago

@shettyanusha - I am in the midst of releasing this to Nuget. It wil be in version 6.2.1.4.

Kind regards.

ashetty-planview commented 3 months ago

Thank you so much @baynezy. I'm on .NETStandard 2.1 and it seems like version 6 is not compatible with it. The Html2Markdown version is 5.1.0