Skip to content

Commit

Permalink
Merge pull request #448 from baynezy/feature/issue-109-empty-list-bug
Browse files Browse the repository at this point in the history
Fix bug with empty lists
  • Loading branch information
baynezy authored Aug 7, 2024
2 parents c16a697 + df55116 commit 99f691b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Html2Markdown/Replacement/HtmlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ private static string ReplaceList(string html)
}
markdownList.Add($"{listPrefix}{finalList}");
});

if (markdownList.Count == 0) return string.Empty;

//If a new line is already ending the markdown item, then we don't need to add another one
return Environment.NewLine + Environment.NewLine + markdownList.Aggregate((current, item) => current.EndsWith(Environment.NewLine) ? current + item : current + Environment.NewLine + item) + Environment.NewLine + Environment.NewLine;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
emptyString
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
emptyString
9 changes: 9 additions & 0 deletions test/Html2Markdown.Test/MarkdownSchemeConverterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,15 @@ public Task Convert_WhenThereAreMultipleUnorderedLists_ThenReplaceWithMarkdownLi

return CheckConversion(html);
}

// See issue https://github.com/baynezy/Html2Markdown/issues/109
[Test]
public Task Convert_WhenThereIsAnEmptyList_ThenRemoveTheList()
{
const string html = "<ul><li></li></ul>";

return CheckConversion(html);
}

#endregion

Expand Down

0 comments on commit 99f691b

Please sign in to comment.