| 1293 |
dpurdie |
1 |
package Codestriker::Template::Plugin::FormatWhitespace;
|
|
|
2 |
|
|
|
3 |
# Simple template toolkit plugin module for formatting whitespace.
|
|
|
4 |
|
|
|
5 |
use Template::Plugin::Filter;
|
|
|
6 |
use Codestriker;
|
|
|
7 |
|
|
|
8 |
use base qw( Template::Plugin::Filter );
|
|
|
9 |
|
|
|
10 |
sub filter {
|
|
|
11 |
my ($self, $text) = @_;
|
|
|
12 |
|
|
|
13 |
# Get the tabwidth setting from the config.
|
|
|
14 |
my $tabwidth = $self->{ _CONFIG }->{tabwidth};
|
|
|
15 |
|
|
|
16 |
# Replace newlines with <br>s.
|
|
|
17 |
$text =~ s/\n/<br>/mgo;
|
|
|
18 |
|
|
|
19 |
# Replace consective spaces with entities. Its important
|
|
|
20 |
# start start with a leading space, so that the text can be
|
|
|
21 |
# broken up when it appears inside a floating div or a table row.
|
|
|
22 |
$text =~ s/ \s+/' ' x (length($&)-1)/emgo;
|
|
|
23 |
|
|
|
24 |
# Replace tabs.
|
|
|
25 |
$text = Codestriker::Http::Render::tabadjust($tabwidth, $text, 1);
|
|
|
26 |
|
|
|
27 |
return $text;
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
1;
|