Term::ANSIColor::Markup - Colorize tagged strings for screen output


Term-ANSIColor-Markup documentation Contained in the Term-ANSIColor-Markup distribution.

Index


Code Index:

NAME

Top

Term::ANSIColor::Markup - Colorize tagged strings for screen output

SYNOPSIS

Top

  use Term::ANSIColor::Markup;

  my $text = qq{aaa<red>bbb<bold>ccc</bold>ddd<black><on_yellow>eee</on_yellow></black>fff</red> &gt; ggg};

  my $parser = Term::ANSIColor::Markup->new;
  $parser->parse($text);
  print $parser->text;

  # or just call colorize method this way:

  print Term::ANSIColor::Markup->colorize($text);

DESCRIPTION

Top

Term::ANSIColor::Markup provides a simple and friendly way to colorize screen output; You can do it using HTML-like tags.

You can use the same names for tag names as ones Term::ANSIColor provides. See the documentation of Term::ANSIColor to get to know what names you can use.

METHODS

Top

new ()

  my $parser = Term::ANSIColor::Markup->new;

Creates and returns a new Term::ANSIColor::Markup object.

parse ( $text )

  $parser->parse($text);

Parses given $text. If start tag and end tag aren't correspondent with each other, this method croaks immediately.

Note that "<" and ">" which are not part of tags must be escaped into "&lt;" and "&gt;".

text ()

  print $parser->text;

Returns parsed text.

colorize ($text)

  print Term::ANSIColor::Markup->colorize($text);

Returns parsed text in just one way.

REPOSITORY

Top

https://github.com/kentaro/perl-term-ansicolor-markup/tree

SEE ALSO

Top

* TermColor

The idea, converts tagged string to colorized one for term, was borrowed from http://github.com/jugyo/termcolor/tree/master

* Term::ANSIColor

You might want to consult the documentation of Term::ANSIColor to get to know what tags you can use.

AUTHOR

Top

Kentaro Kuribayashi <kentaro@cpan.org>

SEE ALSO

Top

COPYRIGHT AND LICENSE (The MIT License)

Top


Term-ANSIColor-Markup documentation Contained in the Term-ANSIColor-Markup distribution.

package Term::ANSIColor::Markup;
use 5.008_001;
use strict;
use warnings;
use Term::ANSIColor::Markup::Parser;
use base qw(Class::Accessor::Lvalue::Fast);

our $VERSION = '0.06';

__PACKAGE__->mk_accessors(qw(parser text));

sub new {
    my $class  = shift;
    bless {
        parser => Term::ANSIColor::Markup::Parser->new,
        text   => '',
    }, $class;
}

sub parse {
    my ($self, $text) = @_;
    $self->parser->parse($text);
    $self->parser->eof;
    $self->text = $self->parser->text;
}

sub colorize {
    my ($class, $text) = @_;
    my $self = $class->new;
       $self->parse($text);
       $self->text;
}

1;

__END__