Skip to content

Ruby gem. Extension to monospace_text_formatter Gem that handles HTML-like tags.

License

Notifications You must be signed in to change notification settings

jacekmikrut/monospace_tag_text_formatter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Ruby gem. Extension to monospace_text_formatter Gem that handles HTML-like tags.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages