-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Don't put the ellipsis in a <details>
tag
#41
Comments
The condition may vary depending on whether the If the If the I don't think it's a good idea to deal with this condition in this lib. |
To my mind, the value of the lib is specifically to at least try to know about and handle all the weird cases so users don't have to. Is there even a way for a user to handle this outside the lib without essentially re-implementing the whole thing? To my mind, |
In my opinion, the There should be a way to customize when to ignore a tag. Please allow me some time to consider this matter thoroughly. |
… truncate strategy #41 2. Rewrite the library to a purely functional library to prevent configurations from getting polluted. 3. Update the build toolchain to Vite and Vitetest.
A new option You can run For your requirements, the following code may achieve your needs: import truncate, { type IOptions, type ICustomNodeStrategy } from 'truncate-html'
// argument node is a cheerio instance
const customNodeStrategy: ICustomNodeStrategy = node => {
// keep details and treat it as nothing inside
if (node.is('details')) {
return 'keep'
}
}
const html = '<div><details><summary>Click me</summary><p>Some details</p></details>other things</div>'
const options: IOptions = {
length: 3,
customNodeStrategy
}
truncate(html, options)
// => <div><details><summary>Click me</summary><p>Some details</p></details>oth...</div> |
@nex3 Hi, is there any problem with this beta version? I'd like to make an official release in a few days. |
Sorry, I haven't had a chance to try it yet. I'll see if I can give it a shot tonight. |
If the last text in the truncated HTML is a
<details>
tag, the ellipsis should probably go after it, since it'll be collapsed by default in the tag itself.The text was updated successfully, but these errors were encountered: