Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 129199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:45:14+00:00 2026-05-11T05:45:14+00:00

I have a page that will list news articles. To cut down on the

  • 0

I have a page that will list news articles. To cut down on the page’s length, I only want to display a teaser (the first 200 words / 600 letters of the article) and then display a ‘more…’ link, that, when clicked, will expand the rest of the article in a jQuery/Javascript way. Now, I’ve all that figured out and even found the following helper method on some paste page, which will make sure, that the news article (string) is not chopped up right in the middle of a word:

 def shorten (string, count = 30)     if string.length >= count       shortened = string[0, count]       splitted = shortened.split(/\s/)       words = splitted.length       splitted[0, words-1].join(' ') + ' ...'     else       string     end   end 

The problem that I have is that the news article bodies that I get from the DB are formatted HTML. So if I’m unlucky, the above helper will chop up my article string right in the middle of an html tag and insert the ‘more…’ string there (e.g. between ”), which will corrupt my html on the page.

Is there any way around this or is there a plugin out there that I can use to generate excerpts/teasers from an HTML string?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:45:15+00:00Added an answer on May 11, 2026 at 5:45 am

    Thanks a lot for your answers! However, in the meantime I stumbled upon the jQuery HTML Truncator plugin, which perfectly fits my purposes and shifts the truncation to the client-side. It doesn’t get any easier 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to create a page using views that will list down
I'm have a page that will be used (and hence styled) only for printing.
I'm creating a WP theme that will have two sections midway down the page.
First high-level: I have a web page that will be showing correspondance between a
I have a page that will basically be used to concatenate a bunch of
I have a page that will have a full size product image and 4
I have a page a query that will set a table to 0 or
I have an asp.net page that calls a dll that will start a long
I have to do a asp.net web page that when load will say something
I am loading content into a page with ajax that will have live click

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.