Module ANSI::BBCode
In: lib/ansi/bbcode.rb

The BBCode module helps ease the separation of core and frontend with the core (or submodules) being still able to say, what colors shall be used in it‘s responses. This is achieved by encoding formatting information using the BBCode tokens. This enables you to "pipe" layout information such as colors, style, font, size and alignment through the core to the frontend.

Additionally it converts markups/codes between ANSI, HTML and BBCode almost freely ;)

  # Converting a bbcode string to ANSI and XHTML
  str = "this is [COLOR=red]red[/COLOR], this is [B]bold[/B]"
  print( BBCode.bbcode_to_ansi(str) )
  print( BBCode.bbcode_to_html(str) )

Methods

Constants

ANSINAME2CODE = { "reset" => "\e[0m", "bold" => "\e[1m", "underline" => "\e[4m", "blink" => "\e[5m", "reverse" => "\e[7m", "invisible" => "\e[8m", "black" => "\e[0;30m", "darkgrey" => "\e[1;30m", "red" => "\e[0;31m", "lightred" => "\e[1;31m", "green" => "\e[0;32m", "lightgreen" => "\e[1;32m", "brown" => "\e[0;33m", "yellow" => "\e[1;33m", "blue" => "\e[0;34m", "lightblue" => "\e[1;34m", "purple" => "\e[0;35m", "magenta" => "\e[1;35m", "cyan" => "\e[1;36m", "lightcyan" => "\e[1;36m", "grey" => "\e[0;37m", "white" => "\e[1;37m", "bgblack" => "\e[40m", "bgred" => "\e[41m", "bggreen" => "\e[42m", "bgyellow" => "\e[43m", "bgblue" => "\e[44m", "bgmagenta" => "\e[45m", "bgcyan" => "\e[46m", "bgwhite" => "\e[47m"   ANSIname => ANSIcode LUT
BBCOLOR2ANSI = { "skyblue" => "blue", "royalblue" => "blue", "blue" => "blue", "darkblue" => "blue", "orange" => "red", "orangered" => "red", "crimson" => "red", "red" => "lightred", "firebrick" => "red", "darkred" => "red", "green" => "green", "limegreen" => "green", "seagreen" => "green", "darkgreen" => "green", "deeppink" => "magenta", "tomato" => "red", "coral" => "cyan", "purple" => "purple", "indigo" => "blue", "burlywood" => "red", "sandybrown"=> "red", "sierra" => "sierra", "chocolate" => "brown", "teal" => "teal", "silver" => "white", "black" => "black", "yellow" => "yellow", "magenta" => "magenta", "cyan" => "cyan", "white" => "white"   BBColor => ANSIname LUT
ANSINAME2BBCODE = { "bold" => "B", "underline" => "U", "reverse" => "I", "red" => "COLOR=red", "blue" => "COLOR=blue", "green" => "COLOR=green", "cyan" => "COLOR=cyan", "magenta"=> "COLOR=deeppink", "purple" => "COLOR=purple", "black" => "COLOR=black", "white" => "COLOR=white", "yellow" => "COLOR=yellow", "brown" => "COLOR=chocolate"   ANSInames => BBCode LUT

Public Class methods

Returns the ANSI sequence for given color, if existant

Returns the string with all ansi escape sequences converted to BBCodes

Converts an ANSI string to one with HTML markup. Returns the string with ANSI code sequences converted to XHTML markup.

Converts a BBCode string to one with ANSI sequences. Returns the string with all formatting instructions in BBCodes converted to ANSI code sequences / aligned with spaces to specified width.

Converts a BBCode string to one with HTML markup. Returns the string with all formatting instructions in BBCodes converted to XHTML markups.

Returns the (X)HTML markup code as ANSI sequences

Converts a HTML string into one with BBCode markup (TODO) Returns the (X)HTML markup string as BBCode

strip_bbcode( string ) Will strip any BBCode tags from the given string.

[Validate]