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: updated formatUnorderedList to support empty itemPrefix #308

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 1 addition & 1 deletion packages/html-to-text/src/text-formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
11 changes: 11 additions & 0 deletions packages/html-to-text/test/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<ul><li>foo</li><li>bar</li></ul>';
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*/`<ul><li>foo<ul><li>bar<ul><li>baz.1</li><li>baz.2</li></ul></li></ul></li></ul>`;
const expected = ' * foo\n * bar\n * baz.1\n * baz.2';
Expand Down