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

Cannot remove newlines between tags even with options #310

Open
TrofinSorin opened this issue Jan 24, 2024 · 1 comment
Open

Cannot remove newlines between tags even with options #310

TrofinSorin opened this issue Jan 24, 2024 · 1 comment

Comments

@TrofinSorin
Copy link

TrofinSorin commented Jan 24, 2024

Minimal HTML example

<h1>1</h1>
<h1>2</h1>
<h1>3</h1>

Options

{
        wordwrap: false,
        preserveNewlines: false,
        selectors: [
          { selector: 'p', options: { leadingLineBreaks: 0, trailingLineBreaks: 0 } },
          { selector: 'h1', options: { leadingLineBreaks: 0, trailingLineBreaks: 0 } },
          { selector: 'h2', options: { leadingLineBreaks: 0, trailingLineBreaks: 0 } },
          { selector: 'h3', options: { leadingLineBreaks: 0, trailingLineBreaks: 0 } },
        ]
      }

Observed output
Before the selector options there were 2 newlines. But with those options it's reduced to one newline.

1
(newline here)
2
(newline here)
3

Expected output

I want this output without newlines

1
2
3

The same as inside wysiwig, without newlines but H1

Version information

  • html-to-text: 9.0.5
  • node: 18.19.0

@KillyMXI
Copy link
Member

KillyMXI commented Jan 24, 2024

These options will work:

{
  selectors: [
    { selector: 'h1', options: { leadingLineBreaks: 1, trailingLineBreaks: 1 } },
  ]
}

What happens with zero:
The condition 0 || 2 equates to the default value of 2.

Notice that this counts line breaks, not empty lines.
Zero line breaks would mean "continue on the same line" which doesn't make sense for block level tags.

I agree that this logic might be somewhat less intuitive though. It should probably be clamped to the closest valid value and sent a warning when misused...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants