Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1f8b0477

Von Moritz Bunkus vor fast 3 Jahren hinzugefügt

  • ID 1f8b0477b52069959871280c0899f461f5855b1c
  • Vorgänger ea32f94d
  • Nachfolger 7c9b978a

SL::HTML::Util: Helferfunktion zur Wandlung von Text nach HTML

Unterschiede anzeigen:

SL/HTML/Util.pm
41 41
  return delete $stripper{text};
42 42
}
43 43

  
44
sub plain_text_to_html {
45
  my ($class_or_text) = @_;
46

  
47
  my $text = !ref($class_or_text) && (($class_or_text // '') eq 'SL::HTML::Util') ? $_[1] : $class_or_text;
48

  
49
  return $text if $text =~ m{^<p>.*</p>$};
50

  
51
  $text =~ s{\r+}{}g;
52
  $text =~ s{^[[:space:]]+|[[:space:]]+$}{}g;
53

  
54
  return '' if $text eq '';
55

  
56
  my @paragraphs;
57

  
58
  foreach my $paragraph (split m{\n{2,}}, $text) {
59
    no warnings 'once';
60
    $paragraph =  $::locale->quote_special_chars('HTML', $paragraph);
61
    $paragraph =~ s{\n}{<br>}g;
62

  
63
    push @paragraphs, $paragraph;
64
  }
65

  
66
  return '<p>' . join('</p><p>', @paragraphs) . '</p>';
67
}
68

  
44 69
1;
45 70
__END__
46 71

  
......
65 90
Removes all HTML elements and tags from C<$html_content> and returns
66 91
the remaining plain text.
67 92

  
93
=item C<plain_text_to_html $text>
94

  
95
Converts a plain text to HTML: paragraphs will be recognized by empty
96
lines; remaining newlines will be converted into forced line breaks;
97
the rest will be HTML escaped.
98

  
68 99
=back
69 100

  
70 101
=head1 BUGS

Auch abrufbar als: Unified diff