From 46321d7c7e11e2199eea9c6f1480255b41ef6727 Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 14 Nov 2023 12:05:47 -0600 Subject: [PATCH] fix: updated formatUnorderedList to support empty itemPrefix --- packages/html-to-text/src/text-formatters.js | 2 +- packages/html-to-text/test/tags.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/html-to-text/src/text-formatters.js b/packages/html-to-text/src/text-formatters.js index 5b9dc96..2802fbb 100644 --- a/packages/html-to-text/src/text-formatters.js +++ b/packages/html-to-text/src/text-formatters.js @@ -231,7 +231,7 @@ function formatList (elem, walk, builder, formatOptions, nextPrefixCallback) { * @type { FormatCallback } */ function formatUnorderedList (elem, walk, builder, formatOptions) { - const prefix = formatOptions.itemPrefix || ' * '; + const prefix = (typeof formatOptions.itemPrefix === 'string') ? formatOptions.itemPrefix : ' * '; return formatList(elem, walk, builder, formatOptions, () => prefix); } diff --git a/packages/html-to-text/test/tags.js b/packages/html-to-text/test/tags.js index b2e042f..e761e7b 100644 --- a/packages/html-to-text/test/tags.js +++ b/packages/html-to-text/test/tags.js @@ -427,6 +427,17 @@ describe('tags', function () { expect(htmlToText(html, options)).to.equal(expected); }); + it('should handle an unordered list with an empty prefix option', function () { + const html = ''; + const options = { + selectors: [ + { selector: 'ul', options: { itemPrefix: '' } } + ] + }; + const expected = 'foo\nbar'; + expect(htmlToText(html, options)).to.equal(expected); + }); + it('should handle nested ul correctly', function () { const html = /*html*/``; const expected = ' * foo\n * bar\n * baz.1\n * baz.2';