|
|
@ -1,62 +1,93 @@ |
|
|
|
#!/usr/bin/perl |
|
|
|
|
|
|
|
=pod |
|
|
|
|
|
|
|
=head1 NAME |
|
|
|
|
|
|
|
Display::HTML |
|
|
|
|
|
|
|
=cut |
|
|
|
|
|
|
|
package Display::HTML; |
|
|
|
|
|
|
|
use strict; |
|
|
|
use warnings; |
|
|
|
no warnings 'uninitialized'; |
|
|
|
|
|
|
|
use Display::GenHTML qw(:all); |
|
|
|
|
|
|
|
use Exporter; |
|
|
|
our @ISA = qw(Exporter); |
|
|
|
our @EXPORT_OK = qw(p a ornament heading em entry_markup table table_cell table_row small); |
|
|
|
our @EXPORT; |
|
|
|
|
|
|
|
=item entry_markup |
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw(a div p em small strong table |
|
|
|
table_row table_cell entry_markup |
|
|
|
heading) ], |
|
|
|
|
|
|
|
'highlevel' => [ qw(a p em small strong table |
|
|
|
table_row table_cell |
|
|
|
entry_markup heading) ] ); |
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|
|
|
our @EXPORT = qw( ); |
|
|
|
|
|
|
|
# Generate subs for these: |
|
|
|
my %tags = ( |
|
|
|
p => \&tag, |
|
|
|
em => \&tag, |
|
|
|
small => \&tag, |
|
|
|
strong => \&tag, |
|
|
|
table => \&tag, |
|
|
|
tr => \&tag, |
|
|
|
td => \&tag, |
|
|
|
a => \&tag, |
|
|
|
div => \&tag, |
|
|
|
); |
|
|
|
|
|
|
|
# ...but map these tags to different sub names: |
|
|
|
my %tagmap = ( |
|
|
|
tr => 'table_row', |
|
|
|
td => 'table_cell', |
|
|
|
); |
|
|
|
|
|
|
|
# Install appropriate subs in symbol table: |
|
|
|
{ no strict 'refs'; |
|
|
|
|
|
|
|
for my $key (keys %tags) { |
|
|
|
my $subname = $tagmap{$key}; |
|
|
|
$subname = $key unless ($subname); |
|
|
|
|
|
|
|
*{ $subname } = sub { $tags{$key}->($key, @_); }; |
|
|
|
} |
|
|
|
|
|
|
|
Return text wrapped in the appropriate markup for an entry. Just a wrapper |
|
|
|
around div() at the moment. |
|
|
|
|
|
|
|
=cut |
|
|
|
|
|
|
|
sub entry_markup { |
|
|
|
my ($text) = @_; |
|
|
|
return div($text, 'class: entry') . "\n"; |
|
|
|
} |
|
|
|
|
|
|
|
# handle most HTML tags: |
|
|
|
sub tag { |
|
|
|
my ($tag) = shift; |
|
|
|
my (@params) = @_; |
|
|
|
|
|
|
|
=item ornament |
|
|
|
|
|
|
|
Returns a type ornament. |
|
|
|
my ($attr_string, $text); |
|
|
|
|
|
|
|
=cut |
|
|
|
for my $param (@params) { |
|
|
|
|
|
|
|
sub ornament { |
|
|
|
return '<small>§</small>'; |
|
|
|
} |
|
|
|
if ($param =~ m/^([a-z]+): ?(.*)$/) { |
|
|
|
my ($name, $value) = ($1, $2); |
|
|
|
$attr_string .= qq{ $name="$value"} |
|
|
|
} |
|
|
|
else { |
|
|
|
$text .= "\n" if length($text) > 0; |
|
|
|
$text .= $param; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
=item heading |
|
|
|
# voila, an X(HT)ML tag: |
|
|
|
return "<${tag}${attr_string}>$text</$tag>"; |
|
|
|
|
|
|
|
Returns a heading of the specified level. |
|
|
|
} |
|
|
|
|
|
|
|
For example, heading("p1k3", 1) == "<h1>p1k3</h1>"; |
|
|
|
######################################## |
|
|
|
# Special cases and higher-level markup |
|
|
|
|
|
|
|
=cut |
|
|
|
sub entry_markup { |
|
|
|
my ($text) = @_; |
|
|
|
return div($text, 'class: entry') . "\n"; |
|
|
|
} |
|
|
|
|
|
|
|
sub heading { |
|
|
|
my ($text, $level) = @_; |
|
|
|
my $tag = "h$level"; |
|
|
|
return "<$tag>$text</$tag>"; |
|
|
|
my $h = "h$level"; |
|
|
|
return tag($h, $text); |
|
|
|
} |
|
|
|
|
|
|
|
1; |