Skip to content

Commit 46321d7

Browse files
committed
fix: updated formatUnorderedList to support empty itemPrefix
1 parent 5b7ca1c commit 46321d7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/html-to-text/src/text-formatters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ function formatList (elem, walk, builder, formatOptions, nextPrefixCallback) {
231231
* @type { FormatCallback }
232232
*/
233233
function formatUnorderedList (elem, walk, builder, formatOptions) {
234-
const prefix = formatOptions.itemPrefix || ' * ';
234+
const prefix = (typeof formatOptions.itemPrefix === 'string') ? formatOptions.itemPrefix : ' * ';
235235
return formatList(elem, walk, builder, formatOptions, () => prefix);
236236
}
237237

packages/html-to-text/test/tags.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,17 @@ describe('tags', function () {
427427
expect(htmlToText(html, options)).to.equal(expected);
428428
});
429429

430+
it('should handle an unordered list with an empty prefix option', function () {
431+
const html = '<ul><li>foo</li><li>bar</li></ul>';
432+
const options = {
433+
selectors: [
434+
{ selector: 'ul', options: { itemPrefix: '' } }
435+
]
436+
};
437+
const expected = 'foo\nbar';
438+
expect(htmlToText(html, options)).to.equal(expected);
439+
});
440+
430441
it('should handle nested ul correctly', function () {
431442
const html = /*html*/`<ul><li>foo<ul><li>bar<ul><li>baz.1</li><li>baz.2</li></ul></li></ul></li></ul>`;
432443
const expected = ' * foo\n * bar\n * baz.1\n * baz.2';

0 commit comments

Comments
 (0)