No commit activity in last 3 years
No release in over 3 years
Extension to monospace_text_formatter Gem. Treats HTML-like tags as zero-length and ensures they are properly closed during text truncation/splitting and reopened after line wrapping.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 2.0

Runtime

 Project Readme

MonospaceTagTextFormatter

MonospaceTagTextFormatter is a Ruby Gem that is an extension to MonospaceTextFormatter Ruby Gem.

Features

  • It treats HTML-like tags as zero-length, according to an assumption that these tags are going to be eventually removed or replaced before the text is displayed (for instance, they may be converted into color ANSI escape sequences by AnsiChameleon Ruby Gem).

Thanks to that, for example, the following text will not be truncated:

  MonospaceTagTextFormatter::Line.new("<tag>Some text.</tag>", :width => 10).to_s
   => "<tag>Some text.</tag>"
  • It treats "&lt;" and "&gt;" character entities as having the length equal to 1 character, according to an assumption that these entities were used to escape HTML-like tags and are going to be replaced with "<" and ">" signs.

For instance, the following text will not be truncated:

  MonospaceTagTextFormatter::Line.new("&lt;div&gt;Some text.&lt;/div&gt;", :width => 21).to_s
   => "&lt;div&gt;Some text.&lt;/div&gt;"
  • It ensures that HTML-like tags are properly closed when a text is truncated.

An example:

  MonospaceTagTextFormatter::Line.new("<tag>This is some text.</tag>", :width => 8).to_s
   => "<tag>This</tag> ..."
  • When a text is wrapped, it closes opened tags at the end of each line, and reopens them at the beginning of the next line, according to an assumption that these tags correspond to some text formatting. Thanks to that feature, formatting of each line is preserved.
  MonospaceTagTextFormatter::Box.new("<tag>This is a bit longer text.</tag>", :width => 8).lines
   => ["<tag>This is</tag> ",
       "<tag>a bit</tag>   ",
       "<tag>longer</tag>  ",
       "<tag>text.</tag>   "]

Installation

As a Ruby Gem, MonospaceTagTextFormatter can be installed either by running

  gem install monospace_tag_text_formatter

or adding

  gem "monospace_tag_text_formatter"

to the Gemfile and then invoking bundle install.

License

License is included in the LICENSE file.