arendjr / text-clipper

Fast and correct clip functions for HTML and plain text
MIT License
133 stars 13 forks source link

Missing indicator on html tag cut #19

Closed Eomm closed 3 months ago

Eomm commented 2 years ago

Hi, given this example:

const tc = require('text-clipper').default
tc('<p>12345</p><p>67890</p>', 8, {
      html: true,
      breakWords: true,
      indicator: '...',
    })

I would expect this output:

<p>12345...</p>

// or
<p>12345</p><p>...</p>

Instead, I got:

<p>12345</p>

What do you think?

arendjr commented 2 years ago

Thanks for the report. I can confirm the current output is as intended, because as the README describes, the indicator is not inserted at a linebreak, which also applies to the start of a new paragraph. The rationale for this is that users are expected to display a “Read more” link or such anyway, so there shouldn’t be any confusion and the extra ellipses tend to look off in such cases.

That said, you’re not the first to raise this question, so it seems not to be entirely intuitive to everyone. If you’re interested I’d welcome a PR to make this behavior configurable. I think an insertIndicatorAtLinebreak option would be reasonable to have. If such option were to be set to true, I think the output <p>12345...</p> would be preferred indeed.

arendjr commented 3 months ago

Implemented at last :)