+sub plain_text_to_html {
+ my ($class_or_text) = @_;
+
+ my $text = !ref($class_or_text) && (($class_or_text // '') eq 'SL::HTML::Util') ? $_[1] : $class_or_text;
+
+ return $text if $text =~ m{^<p>.*</p>$};
+
+ $text =~ s{\r+}{}g;
+ $text =~ s{^[[:space:]]+|[[:space:]]+$}{}g;
+
+ return '' if $text eq '';
+
+ my @paragraphs;
+
+ foreach my $paragraph (split m{\n{2,}}, $text) {
+ no warnings 'once';
+ $paragraph = $::locale->quote_special_chars('HTML', $paragraph);
+ $paragraph =~ s{\n}{<br>}g;
+
+ push @paragraphs, $paragraph;
+ }
+
+ return '<p>' . join('</p><p>', @paragraphs) . '</p>';
+}
+