kswedberg / jquery-expander

Expand and Collapse HTML content
https://kswedberg.github.io/jquery-expander/
Other
459 stars 168 forks source link

Inaccurate slice for Chinese characters #126

Closed yduke closed 4 years ago

yduke commented 4 years ago

Hi, I've tried jQuery expander on Chinese web pages, as a result, each 1 Chinese character will be counted as 2 characters, so if I set slicePoint: 120, there are actually 240 Chinese characters will be put into the summaryText.

kswedberg commented 4 years ago

I'm confused. If each Chinese 1 character is counted as 2 characters, wouldn't a slicePoint of 120 put 60 characters in the summaryText?

yduke commented 4 years ago

@kswedberg LOL forgive my math, actually I've tried to count the output characters manually, a bit odd that they are not exactly the number as we set, nor 1/2, I set slicePoint to180 or 200, the summary text could sometimes be the same, both english or chinese, would that be a utf-8 problem? It there a better way to fix this?

kswedberg commented 4 years ago

thanks for the report. I'm finally looking into this. It's such an old plugin that I can't get my tests to run, so it might take a while

kswedberg commented 4 years ago

@yduke It looks like I already have a test for Chinese characters. Can you try using the following options object?

{
  preserveWords: false,
  widow: 0
}
yduke commented 4 years ago

Sorry for this late reply, I've been busy with other projects. It is working with your solution. Thank you @kswedberg, good job! :100:

kswedberg commented 4 years ago

You're welcome, @yduke . Glad there is a a solution. Also, because of your issue, I updated the readme. So, thanks!