1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
##
## wml::fmt::sdf - Simple Document Format (SDF)
## Copyright (c) 1997-2001 Ralf S. Engelschall, All Rights Reserved.
##
# The <preserve>/<restore> tags with multiple arguments require WML 2.0.3
#use wml::mod::version
<require 2.0.3 />
#use wml::std::tags
<protect pass=2>
<:
# the conversion function
sub wml_fmt_sdf {
my ($arg) = @_;
my ($buf);
local (*FP);
# read the sdf result
my $sdf = '';
foreach $path (split(/:/, $ENV{PATH})) {
if (-x "$path/sdf") {
$sdf = "$path/sdf";
last;
}
}
if ($sdf eq '') {
print STDERR "** wml::fmt::sdf: external filter `sdf' not found\n";
exit(1);
}
open(FP, "$sdf -2html -o- $arg->{FILE}|");
local ($/) = undef;
$buf = <FP>;
close(FP);
# cut out the body
$buf =~ s|^.*<BODY>||is;
$buf =~ s|</BODY>.*$||is;
# make headlines more typographic
if (not $arg->{NOTYPO}) {
$buf =~ s|^(<H([1-6])><A NAME="(.+?)">)(.+?)(</A></H\2>)|$1<font face=\"Arial,Helvetica\">$4</font>$5|mg;
}
# remove the nasty horizontal rules
if (not $arg->{KEEPHR}) {
$buf =~ s|<HR>||isg;
}
# more cleanup of HTML markup
$buf =~ s|<P>\s*\n<P>|<P>|isg;
$buf =~ s|</DL>\s*\n?$||is;
return $buf;
}
:>
</protect>
<define-tag sdf endtag=required>
<preserve keephr notypo />
<set-var keephr=* />
<set-var notypo=* />
<set-var %attributes />
<perl>
{
my $tmpfile = "$(WML_TMPDIR)/wml.sdf2html.$$.tmp";
my $keephr = (qq|<get-var keephr />| eq '' ? 1 : 0);
my $notypo = (qq|<get-var notypo />| eq '' ? 1 : 0);
my $buf;
<perl:assign:sq $buf>%body</perl:assign:sq>
# there is no reason to nest <sdf> tags, so the <perl:print>
# statement is unnecessary
open(SDF, ">$tmpfile");
print SDF $buf;
close(SDF);
<perl:print:
"&wml_fmt_sdf({ FILE => $tmpfile,
KEEPHR => $keephr,
NOTYPO => $notypo })" />
unlink($tmpfile);
}
</perl>
<restore keephr notypo />
</define-tag>
##EOF##
__END__
=head1 NAME
wml::fmt::sdf - Simple Document Format (SDF)
=head1 SYNOPSIS
#use wml::fmt::sdf
<: print &wml_fmt_sdf({ FILE => $file, ... }); :>
<sdf>
H1: ...
...
H2: ...
...
</sdf>
=head1 DESCRIPTION
The usage is simple: surround all SDF source text with the C<E<lt>sdfE<gt>>
container tag and then just write SDF format inside it as you would do when
writing plain SDF documents. The corresponding HTML code is created via SDF's
F<sdf2html> filter.
=head1 AUTHOR
Ralf S. Engelschall
rse@engelschall.com
www.engelschall.com
=head1 REQUIRES
Internal: P1, P2, P3
External: sdf
=head1 SEE ALSO
sdf(1), http://www.mincom.com/mtr/sdf/
=cut
|