-
Notifications
You must be signed in to change notification settings - Fork 129
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
html tags in children #8
Comments
That's an interesting question, I guess you are talking about preserving something like It might be possible to work out a solution with a combination of Iterating over the child nodes, and appending them unmodified when the text content fits completely. Then, for the first child node that exceeds the boundaries modifying its HTML to make it fit, and finally, appending the ellipsis. This might fail horribly when the width of the If you want to take a shot at implementing this, I'm more than willing to help you figure it out! |
Thanks for the fast reply @pablosichert As we all know, time is usually the issue :) But should I find some this weekend or so, I will see what I can do. Can't promise anything though... |
Digging around a bit, I found out about the Making use of Selecting the nodes accordingly and modifying a node, when the end lies within a non-text node could be tricky. Haven't tried yet. |
Is this still being considered? I'd love HTML support (or at the very least, some sort of markup passthrough) |
Working out a solution would mean investing a considerable amount of time - and unfortunately I didn't have a use case that would have justified the time for me. I think https://github.com/glinford/ellipsis.js made it work, but I didn't get to review yet how it's implemented and what the performance implications would be. If you want to contribute by porting that feature, I would very welcome it. |
@codejet @pablosichert Thanks for pointing me to ellipsis.js I made a simple react component if others are trying to use ellipsis.js within React https://gist.github.com/cbosco/4339f6d842c6c9ac35f21982e98b4412 There is one caveat - ellipsis.js works well with the exception of comment nodes; I put a PR into ellipsis.js: glinford/ellipsis.js#7 Also, ellipsis.js on npm is outdated, you'll want to point to either glinford or cbosco via github |
But if I use Ellipsis.js it does not give me the ontruncate Function and just adds ellipsis.I need both read more/show less and te description needs to be html :) |
My text was an html string (ie.
as a the child element and the html tags worked! |
@jesspoemape Can you share your sample code that you used with |
Hi @kashifshamaz21, if you're still looking to get HTML content working, try this: Simply set the inner HTML on a child component rather than the Truncate component. |
This package works for me: https://www.npmjs.com/package/react-truncate-markup |
Unfortunately react-truncate-markup does not support React components, only true DOM elements, which I found a problem as the markup I want to display is created using a number of nested React components. I wish/hope there is a better way, but I found this "hack" to make it work based on XigeTime's solution above:
PLEASE tell me there is a more elegant way to do this! |
This is not really an issue but rather a question.
In your documentation for the "children" property it says "Anything that can be evaluated as text." and you list examples including markup. I've seen that you are using
textContent
to extract the plain text from what's being passed in as children.What do you think about preserving at least some markup, like a set of allowed tags? I know that it makes things more complicated, but it might be useful.
The text was updated successfully, but these errors were encountered: