Leser: 1
![]() |
![]() |
4 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
my $in_table = 0;
my $in_td = 0;
my $in_th = 0;
while (not $text =~ m/\G\z/gc) { # Noch kein Ende erreicht
if ( $text =~ m/\G<\s*table\b/igc ) { $in_table++ } # Wenn in table dann var incr
elsif ( $text =~ m/\G<\s*td\b/igc ) { $in_td++ } # wenn in td dann var incr
elsif ( $text =~ m/\G<\s*th\b/igc ) { $in_th++ } # wenn in th dann var incr
elsif ( $text =~ m{\G</\s*td\s*>}igc ) { $in_td-- } # wenn td verlassen dann var decr
elsif ( $text =~ m{\G</\s*th\s*>}igc ) { $in_th-- } # wenn th verlassen dann var decr
elsif ( $text =~ m/\G(?=\n)/gc ) { # Wenn ein Newline kommt...
$text =~ s{\G\n}{<br />} if not $in_table;
$text =~ s{\G\n}{} if $in_table && not ($in_td || $in_th);
$text =~ s{\G\n}{<br />} if $in_table && ($in_td || $in_th);
}
else { $text =~ m/\G./igcs } # Regex Engine ein Zeichen weiter Setzen
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use strict;
use warnings;
my $add = 0;
my $text = do { local $/, <DATA> };
for my $line (split /\n/, $text) {
print $line;
if ($line =~ m@<\s*/\s*t[dh]@) {
$add = 0;
} elsif ($line =~ m@<\s*t[dh]@) {
$add = 1;
}
print $add ? '<br>' : "\n";
}
__END__
<html>
<head>
<title>test</title>
</head>
<body>
<table>
<tr>
<th>header1</th>
<th>header2
foo bar
foobar
</th>
</tr>
<tr>
<td>column1
foo bar
foobar
</td>
<td>column2</td>
</tr>
</table>
</html>
![]() |
![]() |
4 Einträge, 1 Seite |