diff --git a/lib/formatter.js b/lib/formatter.js index ef2e82d..687a3fb 100644 --- a/lib/formatter.js +++ b/lib/formatter.js @@ -125,7 +125,7 @@ function formatUnorderedList(elem, fn, options) { var result = ''; var prefix = options.unorderedListItemPrefix; var nonWhiteSpaceChildren = (elem.children || []).filter(function(child) { - return child.type !== 'text' || !whiteSpaceRegex.test(child.data); + return child.name === 'li' && (child.type !== 'text' || !whiteSpaceRegex.test(child.data)); }); nonWhiteSpaceChildren.forEach(function(elem) { result += formatListItem(prefix, elem, fn, options); @@ -136,7 +136,7 @@ function formatUnorderedList(elem, fn, options) { function formatOrderedList(elem, fn, options) { var result = ''; var nonWhiteSpaceChildren = (elem.children || []).filter(function(child) { - return child.type !== 'text' || !whiteSpaceRegex.test(child.data); + return child.name === 'li' && (child.type !== 'text' || !whiteSpaceRegex.test(child.data)); }); // Return different functions for different OL types var typeFunction = (function() { diff --git a/test/html-to-text.js b/test/html-to-text.js index af7f7aa..13db820 100644 --- a/test/html-to-text.js +++ b/test/html-to-text.js @@ -244,6 +244,11 @@ describe('html-to-text', function() { expect(htmlToText.fromString(testString)).to.equal(' * foo\n * bar'); }); + it('should handle an unordered list with line break', function() { + var testString = '