onizet / html2openxml

Html2OpenXml is a small .Net library that convert simple or advanced HTML to plain OpenXml components. This program has started in 2009, initially to convert user's comments from SharePoint to Word.
MIT License
297 stars 106 forks source link

Sequence contains no elements on an empty header tag #141

Closed jovannitjuandi closed 2 weeks ago

jovannitjuandi commented 3 months ago

Describe the bug When HTML has an empty h3 tag, the following line in processHeading function, that gets the first item in the element throws an exception image

Expected behavior would it be possible to create a heading line with no text in it instead? or a space? or skip it entirely? I was just hoping it wouldn't fail the entire export when it's just that one heading tag that's has a problem?

Repro image

I can patch it now by running a regex query to remove all empty HTML tags although it would be better if the empty headings can still be there so different sections of the output word document can still be collapsed even without a text as section titles Repro.docx

BTW, Thank you so much for continuously supporting this library, it has made exporting web content to word so much easier

onizet commented 3 months ago

Hello, I'm sorry about this bug but the good news is that I have also discovered and fixed it in the v3 of this library. I'm actively working on it. Stay tuned and thank you for your kind words!