Truncate_html

screenshot of Truncate_html

truncates html so you don't have to

Overview

The TruncateHtmlBuild library offers a sleek solution for handling HTML strings by effectively truncating them while ensuring that any open tags are properly closed. This tool is particularly valuable for developers looking to manage HTML content dynamically within their applications. With the ability to work seamlessly, both with and without Rails, it stands out for its simplicity and reliance on regular expressions—eliminating the need for additional dependencies.

Whether you want to briefly display content or ensure that your HTML remains well-structured, TruncateHtmlBuild is designed to cater to your needs. By allowing for customizable options and configurations, this library delivers flexibility for developers seeking precise control over content truncation.

Features

  • Dependency-Free: TruncateHtmlBuild does not rely on external libraries, making it lightweight and easy to integrate.
  • Word Boundary Truncation: By default, HTML strings are truncated at word boundaries, maintaining the readability of the resulting content.
  • Custom Length Options: For more control, you can truncate strictly at a specified length by passing the word_boundary: false option.
  • Nil Input Handling: If the input HTML is nil, the library conveniently returns an empty string, preventing errors in your application.
  • Script Tag Preservation: <script> tags are ignored during truncation, meaning they won’t affect the final output's length or structure.
  • Configurable Global Options: Developers can set global configuration options at application boot for consistent truncation behavior across the app.
  • Dynamic Break Point: Utilize the :break_token to truncate content based on specific textual cues rather than a fixed length, allowing for data-driven content management.
  • Rails Compatibility: Designed for use with Rails, it's easy to implement in applications running Rails 2.x and 3.x, with straightforward installation instructions.