Comments (4)
Yeah, you could cut based on character length and add the elipses before the last uncut word. Nice gem.
from html-truncator.
Hi, I've added this option:
HTML_Truncator.truncate("<p>Lorem ipsum dolor sit amet.</p>", 12, :length_in_chars => true)
# => "<p>Lorem ipsum …</p>"
Let me know if it does what you want or if I should modify it.
from html-truncator.
Awesome job, exactly as i expected it to work. Thanks!
from html-truncator.
How about a hybrid approach? Say you want to truncate at ~500 characters, but you don't want to potentially truncate part of a word.
I've forked in hopes of implementing this myself. I'll send a pull request if I manage to do it and specs pass. As I expected, this code is non-trivial, particularly approaching it cold.
from html-truncator.
Related Issues (15)
- The ellipsis should not be put in code tags HOT 2
- Strips iframe tags on ruby 2.1 HOT 1
- Is there any way to ignore specified tags? HOT 2
- Strips script and style
- Not work with russian language HOT 5
- HTML encoded strings are decoded HOT 2
- Truncations after tag boundary HOT 3
- Current implementation creates a Singleton class and prevents marshaling HOT 2
- Messing up Nokogiri HOT 1
- For speed, allow Nokogiri nodes to be passed in HOT 3
- Pattern in words scan HOT 1
- Removing img tag HOT 3
- Comma after text HOT 2
- number of words vs number of chars HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from html-truncator.