File Coverage

blib/lib/String/Tagged/HTML.pm
Criterion Covered Total %
statement 133 135 98.5
branch 35 42 83.3
condition 1 2 50.0
subroutine 18 18 100.0
pod 4 4 100.0
total 191 201 95.0


line stmt bran cond sub pod time code
1             # You may distribute under the terms of either the GNU General Public License
2             # or the Artistic License (the same terms as Perl itself)
3             #
4             # (C) Paul Evans, 2011-2026 -- leonerd@leonerd.org.uk
5              
6             package String::Tagged::HTML 0.04;
7              
8 7     7   1892650 use v5.20;
  7         30  
9 7     7   53 use warnings;
  7         15  
  7         476  
10              
11 7     7   48 use feature qw( postderef signatures );
  7         13  
  7         1740  
12 7     7   57 no warnings qw( experimental::postderef experimental::signatures );
  7         31  
  7         471  
13              
14 7     7   45 use base qw( String::Tagged );
  7         14  
  7         5573  
15             String::Tagged->VERSION( '0.20' );
16              
17             =head1 NAME
18              
19             C - handle HTML content using C
20              
21             =head1 SYNOPSIS
22              
23             =for highlighter language=perl
24              
25             use String::Tagged::HTML;
26              
27             my $st = String::Tagged::HTML->new( "An important message" );
28              
29             $st->apply_tag( 3, 9, b => 1 );
30              
31             print $st->as_html( "h1" );
32              
33             =head1 DESCRIPTION
34              
35             This subclass of L provides a method, C, for rendering
36             the string as an HTML fragment, using the tags to provide formatting. For
37             example, the SYNOPSIS example will produce the output
38              
39             =for highlighter language=html
40              
41            

An important message

42              
43             With the exception of tags named C, a tag applied to an extent of the
44             C will be rendered using start and end HTML tags of the
45             same name. If the tag's value is a C reference, then this hash will be
46             used to provide additional attributes for the HTML element. Tags whose names
47             begin with C<_> will be ignored for this purpose.
48              
49             =for highlighter language=perl
50              
51             my $str = String::Tagged::HTML->new( "click " )
52             ->append_tagged( "here", a => { href => "/see/other.html" } );
53              
54             print $str->as_html( "p" );
55              
56             Z<>
57              
58             =for highlighter language=html
59              
60            

click here

61              
62             If it is not a C reference, then its value ought to be a simple boolean
63             true value, such as C<1>.
64              
65             The special tag named C disables HTML entity escaping over its extent.
66              
67             =for highlighter language=perl
68              
69             my $str = String::Tagged::HTML->new( "This is escaped" );
70              
71             my $br = String::Tagged::HTML->new_tagged( "
", raw => 1 );
72              
73             print +( $str . $br )->as_html( "p" );
74              
75             Z<>
76              
77             =for highlighter language=html
78              
79            

This <content> is escaped

80              
81             =head2 Automatic C<< >> Generation
82              
83             Tags whose names begin C<_span_style_...> are used to create a C