HTML Truncator

screenshot of HTML Truncator

Wants to truncate an HTML string properly? This Ruby gem is for you.

Overview:

The HTML Truncator gem is designed to properly truncate HTML strings using the Nokogiri library in Ruby. With a simple installation process and straightforward implementation, this gem offers a solution for effectively shortening HTML content while maintaining its integrity.

Features:

  • Simple Installation: Easily install the gem using RubyGems or add it to your Gemfile with bundler.
  • Powerful Truncation Method: The truncate method allows you to specify the HTML string, the number of words to keep, and optional settings like the ellipsis.
  • Customizable Options: Adjust settings such as ellipsable tags, self-closing tags, and punctuation characters for tailored truncation.
  • Ellipsis Placement: Ensures that the ellipsis is correctly positioned in the truncated HTML content.
  • Handling of HTML Tags: Maintains tag structure integrity and avoids cutting words or leaving empty DOM nodes.
  • Integration with Nokogiri: Compatible with Nokogiri-parsed HTML documents for seamless truncation of pre-parsed content.
  • Debugging and Testing: Provides methods to check if a string has been truncated and allows for custom configurations to ignore specific elements like images.

Summary:

The HTML Truncator gem offers a user-friendly solution for truncating HTML strings in Ruby applications. By leveraging the power of Nokogiri and providing customizable settings for truncation, this gem ensures proper handling of HTML content without compromising its structure. With features like ellipsis customization, tag-specific truncation, and integration with Nokogiri-parsed documents, the HTML Truncator gem stands out as a reliable tool for efficiently shortening HTML content in Ruby projects.