| Text-Smart documentation | Contained in the Text-Smart distribution. |
Text::Smart::HTML - Smart text outputter for HTML
use Text::Smart::HTML; my $markup = Text::Smart::HTML->new(%params);
Creates a new smart text processor which outputs HTML markup.
The only target parameter is used to specify the hyperlink
window target (via the 'target' attribute on the <a> tag)
Generates a horizontal divider using the <hr> tag.
Generates an itemized list of bullet points using the <ul> tag.
Generates an itemized list of numbered points using the <ol> tag
Generates a heading using one of the tags <h1> through <h6>
Gnerates a paragraph using the <P> tag.
Generates bold text using the <strong> tag
Generates italic text using the <em> tag.
Generates monospaced text using the <code> tag.
Generates a hyperlink using the <a> tag.
Generates entities using the ½, ¼, ¾, ©, ® and <sup> TM </sup> entities / markup.
Escapes the ampersand, and angle bracket characters
Daniel Berrange <dan@berrange.com>
Copyright (C) 2000-2004 Daniel P. Berrange <dan@berrange.com>
perl(1)
| Text-Smart documentation | Contained in the Text-Smart distribution. |
# -*- perl -*- # # Text::Smart::HTML by Daniel Berrange <dan@berrange.com> # # Copyright (C) 2000-2004 Daniel P. Berrange <dan@berrange.com> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # $Id: HTML.pm,v 1.2 2004/12/31 16:00:45 dan Exp $
package Text::Smart::HTML; use strict; use warnings; use Text::Smart; use vars qw(@ISA); @ISA = qw(Text::Smart);
sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = $class->SUPER::new(); my %params = @_; $self->{target} = exists $params{target} ? $params{target} : undef; bless $self, $class; return $self; }
sub generate_divider { my $self = shift; return "<hr>\n"; }
sub generate_itemize { my $self = shift; my @items = @_; return "<ul>\n" . (join("\n", map { "<li>$_</li>\n" } @items)) . "</ul>\n"; }
sub generate_enumeration { my $self = shift; my @items = @_; return "<ol>\n" . (join("\n", map { "<li>$_</li>\n" } @items)) . "</ol>\n"; }
sub generate_heading { my $self = shift; local $_ = $_[0]; my $level = $_[1]; my %levels = ( "title" => "h1", "subtitle" => "h2", "section" => "h3", "subsection" => "h4", "subsubsection" => "h5", "paragraph" => "h6", ); return "<" . $levels{$level} . ">$_</" . $levels{$level} . ">\n"; }
sub generate_paragraph { my $self = shift; local $_ = $_[0]; return "<p>$_</p>\n"; }
sub generate_bold { my $self = shift; local $_ = $_[0]; return "<strong>$_</strong>"; }
sub generate_italic { my $self = shift; local $_ = $_[0]; return "<em>$_</em>"; }
sub generate_monospace { my $self = shift; local $_ = $_[0]; return "<code>$_</code>"; }
sub generate_link { my $self = shift; my $url = shift; local $_ = $_[0]; if ($self->{target}) { return "<a target=\"$self->{target}\" href=\"$url\">$_</a>"; } else { return "<a href=\"$url\">$_</a>"; } }
sub generate_entity { my $self = shift; my $entity = shift; my %entities = ( fraction12 => "½", fraction14 => "¼", fraction34 => "¾", copyright => "©", registered => "®", trademark => "<sup>TM</sup>", ); return exists $entities{$entity} ? $entities{$entity} : $entity; }
sub escape { my $self = shift; local $_ = $_[0]; s/&/&/g; s/</</g; s/>/>/g; return $_; } 1 # So that the require or use succeeds. __END__