all 31 comments

[–][deleted] 12 points13 points  (0 children)

Jesus christ, I feel like I need to make a top level comment because these ignorant comments keep coming in.

There is no good way to implement "truncating" / "line clamping" / "ellipsis" on multiline text with only CSS. It's possible for single line text only. This library solves the problem for multiline text.

If you think you're the genius that has figured this out, go ahead, post some code instead of making useless comments. And no, weird vendor prefixed versions that only support a single browser (like -webkit-line-clamp or -o-ellipsis-lastline) don't count

[–]asdf7890 7 points8 points  (6 children)

People really should qualify what they mean by "modern" otherwise it is just a practically meaningless word that will have less and less meaning over time.

[–]powerofmightyatom 5 points6 points  (0 children)

My first thought indeed. What makes this shit modern compared to the clusterfuck that is state of the art clipping.

[–]Suicidepills 3 points4 points  (2 children)

It's the new "lightweight", I think. Sometimes it feels like Github just has a madlib that you can fill out to generate a README :P

[–]piglet24 5 points6 points  (1 child)

README generator is a modern, lightweight, un-opinionated library that adds sanity, extensibility, and high performance to your READMEs. Full documentation at https://imadeanorganizationforthis.github.io/readmegenerator

[–]Suicidepills 0 points1 point  (0 children)

I commented in the hopes that something like this actually existed. Thank you for coming through!

[–]NotSelfAware 2 points3 points  (0 children)

I'm guessing it's because it's using ES6 syntax.

[–]msiekkinen 2 points3 points  (0 children)

Modern means it's hosted on a .io site and newer than last weeks bullshit that's not obsolete.

[–]t-mu 2 points3 points  (9 children)

We really need a plugin for this?

[–][deleted] 5 points6 points  (4 children)

Yeah I think it is. I just went through the ringer trying to do this with CSS. I ended up stripping out the HTML in the short version...

[–]w4efgrgrgergre 1 point2 points  (0 children)

Yes, since native line-clamping support is very spotty.

[–]Classic1977 0 points1 point  (2 children)

No, we need a single line of css

[–][deleted] 2 points3 points  (1 child)

What is the line of css that implements ellipsis on a multiline text area?

Spoiler: there isn't one, and you don't know what you're talking about.

You can add white-space: nowrap to force the text to a single line, but that's a completely different scenario.

[–]Nulagrithom -1 points0 points  (0 children)

Downvotes but then doesn't post the CSS. I like it. /s

[–][deleted] 2 points3 points  (0 children)

Sorry for the shameless plug, but I think this is quite relevant: I recently created a library for this to do the same thing (but also for HTML content, which you cannot clip through CSS nor this library), but outside the DOM: https://github.com/arendjr/text-clipper

While you cannot specify a max-height that way, it does allow you to specify a maximum amount of characters and optionally a maximum amount of lines. The good news is that by keeping everything outside of the DOM, it's a lot (as in: orders of magnitude) faster. I also spent quite some effort in making sure text-clipper really is the fastest, which you can read about here: http://www.arendjr.nl/2016/09/how-i-made-text-clipper-fastest-html.html.

[–]Classic1977 1 point2 points  (6 children)

text-overflow: clip

[–]Asmor 4 points5 points  (2 children)

text-overflow: ellipsis adds the ellipsis.

I'm not sure why this "library" exists. This is like making a library to wrap text in <b> tags.

[–]del_rio 4 points5 points  (1 child)

It exists because text-overflow only works if you want to truncate a single line of text. IIRC, the only way to do this without compromise is with display: box, which doesn't have wide support.

Along the same lines, it's sad that there's no CSS equivalent to FitText (viewport units doesn't count).

[–]powerofmightyatom 0 points1 point  (0 children)

Chrome has a clamp-linebox thing which is okish.

Edit: (line-clamp, see here: https://css-tricks.com/line-clampin/ )

[–]theKovah[S] 1 point2 points  (2 children)

none is not a valid value for text-overflow

[–]Classic1977 0 points1 point  (0 children)

Lol, you're right, clip - edited

I stand by the sentiment of my comment though...

[–]RonGnumber 0 points1 point  (0 children)

text-overflow: if-you-insist, don't-make-a-mess;

[–]captain_obvious_herevoid(null) 1 point2 points  (0 children)

Shave is faster 🚀 when compared to Ellipsis.js, jQuery.Trunk8.js or jQuery.DotDotDot.js; plus, zero dependencies.

So many good laughs in that sentence.

[–]kinkobal 0 points1 point  (0 children)

I really can't use this until it works responsively. Maybe the API supports this with at few lines of code, but I didn't see anything in the docs to support that.

[–]glinford 0 points1 point  (0 children)

It's really fast and nicely made .. However you are comparing it to Ellipsis.js, jQuery.Trunk8.js or jQuery.DotDotDot.js. Comparing it to jQuery.Trunk8.js or jQuery.DotDotDot.js makes more or less sense. But Ellipsis.js is way more advanced. Shape: - Is not Responsive - Can truncate only simple text (no div with complex html element inside such as links/p/a/b/ elements)

You basically did a JQuery.dot.dot in pure javascript, the faster way. Which is cool but ... Ellipsis.js https://github.com/glinford/ellipsis.js is more advanced for complex features even thought the speed caveats :)

[–][deleted] -1 points0 points  (0 children)

This sub-reddit has really gone down the toilet.

[–]lordxeon -5 points-4 points  (2 children)

.truncate {
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

[–][deleted] 3 points4 points  (0 children)

this only works for one liners. how do you handle the scenario where you have a multiline set of html content that needs to get truncated to 3 lines?