SHOW:
|
|
- or go back to the newest paste.
1 | use Term::ANSIColor qw(:constants color); | |
2 | ||
3 | - | $line = "<b><font color=blue>blue and bold</font>bold but not blue</b>neither blue nor bold<font color=blue>blue but not bold</font>"; |
3 | + | $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>"; |
4 | @colors = (); # colors stack | |
5 | ||
6 | for (split /(<[^>]+>)/, $line) { | |
7 | if (/^<([^\/>][^>]*)>$/) { # opening tag | |
8 | if ($1 eq 'b') { # bold | |
9 | print color 'bold'; | |
10 | push @colors, 'bold'; | |
11 | } elsif (/\s+color="?(\w+)"?/) { # font color | |
12 | print color $1; | |
13 | push @colors, $1; | |
14 | } | |
15 | } elsif (/^<(\/[^>]+)>$/) { #closing tag | |
16 | pop @colors; | |
17 | print color 'reset'; | |
18 | for $color (@colors) { | |
19 | print color $color; | |
20 | } | |
21 | } else { # regular string | |
22 | print "$_\n" if ($_); | |
23 | } | |
24 | } |