Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use Term::ANSIColor qw(:constants color);
- $line = "<b><font color=blue>blue and bold</font>bold but not blue</b>neither blue nor bold<font color=red>red but not bold</font>";
- @colors = (); # colors stack
- for (split /(<[^>]+>)/, $line) {
- if (/^<([^\/>][^>]*)>$/) { # opening tag
- if ($1 eq 'b') { # bold
- print color 'bold';
- push @colors, 'bold';
- } elsif (/\s+color="?(\w+)"?/) { # font color
- print color $1;
- push @colors, $1;
- }
- } elsif (/^<(\/[^>]+)>$/) { #closing tag
- pop @colors;
- print color 'reset';
- for $color (@colors) {
- print color $color;
- }
- } else { # regular string
- print "$_\n" if ($_);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment