File Coverage

blib/lib/EBook/Ishmael/TextToHtml.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 26 26 100.0


line stmt bran cond sub pod time code
1             package EBook::Ishmael::TextToHtml;
2 17     17   305 use 5.016;
  17         67  
3             our $VERSION = '2.03';
4 17     17   100 use strict;
  17         31  
  17         479  
5 17     17   81 use warnings;
  17         58  
  17         934  
6              
7 17     17   99 use Exporter 'import';
  17         31  
  17         5630  
8             our @EXPORT = qw(text2html);
9              
10             sub text2html {
11              
12 12     12 1 1485 my $text = shift;
13              
14 12         88 $text =~ s/&/&/g;
15 12         525 $text =~ s/
16 12         504 $text =~ s/>/>/g;
17              
18 12         34320 my @paras = split /(\s*\n){2,}/, $text;
19              
20             my $html = join '',
21 1392         3758 map { "

\n" . $_ . "

\n" }
22 12         85 grep { /\S/ }
  2775         5069  
23             @paras;
24              
25 12         817 return $html;
26              
27             }
28              
29             1;
30              
31             =head1 NAME
32              
33             EBook::Ishmael::TextToHtml - Convert plain text to HTML
34              
35             =head1 SYNOPSIS
36              
37             use EBook::Ishmael::TextToHtml;
38              
39             my $html = text2html($text);
40              
41             =head1 DESCRIPTION
42              
43             B is a module that provides the subroutine
44             C to perform basic text-to-HTML conversion. If you are looking for
45             L user documentation, you should consult its manual (this is developer
46             documentation).
47              
48             =head1 SUBROUTINES
49              
50             =head2 $html = text2html($text)
51              
52             Converts the given string C<$text> to HTML, returning the HTML string.
53              
54             =head1 AUTHOR
55              
56             Written by Samuel Young, Esamyoung12788@gmail.comE.
57              
58             This project's source can be found on its
59             L. Comments and pull
60             requests are welcome!
61              
62             =head1 COPYRIGHT
63              
64             Copyright (C) 2025-2026 Samuel Young
65              
66             This program is free software: you can redistribute it and/or modify
67             it under the terms of the GNU General Public License as published by
68             the Free Software Foundation, either version 3 of the License, or
69             (at your option) any later version.
70              
71             =cut