Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Ruby gem. Extension to monospace_text_formatter Gem that handles HTML-like tags.
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.gitignore
.rvmrc
Changelog
Gemfile
LICENSE
README.md
monospace_tag_text_formatter.gemspec

README.md

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.

Something went wrong with that request. Please try again.