Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with empty lists #448

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading