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 134 135 136 137
|
##
## wml::fmt::text - Plain ASCII with Special Formatting Semantic
## Copyright (c) 1997-2001 Ralf S. Engelschall, All Rights Reserved.
##
#use wml::std::tags
<protect pass=2>
<:
# the conversion function
sub wml_fmt_text {
my ($arg) = @_;
my ($buf);
local (*FP);
# read the txt2html result
open(FP, '-|', "$(WML_LOC_LIBDIR)/exec/wml_aux_txt2html $arg->{OPTIONS} --extract $arg->{FILE} < /dev/null");
local ($/) = undef;
$buf = <FP>;
close(FP);
# give headlines a more typographically strong look
if (not $arg->{NOTYPO}) {
$buf =~ s|^(<A NAME=".+?"><H([1-6])>)(.+?)(</H\2></A>)|$1<font face=\"Arial,Helvetica\">$3</font>$4|isg;
}
return $buf;
}
:>
</protect>
<define-tag text endtag=required>
<preserve notypo options />
<set-var notypo=* />
<set-var options='' />
<set-var %attributes />
<perl>
{
my $tmpfile = "$(WML_TMPDIR)/wml.txt2html.$$.tmp";
my $notypo = (qq|<get-var notypo />| eq '' ? 1 : 0);
my $options = q{<get-var options />};
my $buf;
<perl:assign:sq $buf>%body</perl:assign:sq>
# there is no reason to nest <text> tags, so the <perl:print>
# statement is unnecessary
open(TXT, ">$tmpfile");
print TXT $buf;
close(TXT);
<perl:print:
"&wml_fmt_text({ FILE => $tmpfile, NOTYPO => $notypo, OPTIONS => $options })" />
unlink($tmpfile);
}
</perl>
<restore notypo options />
</define-tag>
##EOF##
__END__
=head1 NAME
wml::fmt::text - Plain ASCII with Special Formatting Semantic
=head1 SYNOPSIS
#use wml::fmt::text
<: print &wml_fmt_text({ FILE => $file, OPTIONS => '--xhtml', ...}); :>
<text notypo>
FOO
===
1. bar
2. quux
a. baz
b. foo
...
</text>
=head1 DESCRIPTION
The usage is simple: Surround the text with the C<E<lt>textE<gt>> container
tag and then just write plain ASCII text inside it. The corresponding HTML
code is created via F<wml_aux_txt2html>(3), a filter which gives the ASCII
text nice formatting semantic which control the HTML result.
If B<OPTIONS> field is specified, a newer F<txt2html>(1) filter is called
instead of F<wml_aux_txt2html>, which is dead upstream. This allows for
instance generation of XGTML markup.
The core conversion function is wml_fmt_text() which also can be used by other
include files.
=head1 ATTRIBUTES
These attributes can be used both in the C<E<lt>textE<gt>> tag (in
lowercase letters) and in C<wml_fmt_text> arguments, as shown in
examples above.
=over 4
=item C<NOTYPO>
By default, font commands are added to headings to highlight them.
This attribute prevents alteration of F<wml_aux_txt2html> output.
=item C<OPTIONS=I<str>>
This attribute performs two actions: select F<txt2html> filter instead of
F<wml_aux_txt2html>, and I<str> arguments are passed literally on the
command line of F<txt2html>.
=back
=head1 AUTHOR
Ralf S. Engelschall
rse@engelschall.com
www.engelschall.com
=head1 REQUIRES
Internal: P1, P2, P3, wml_aux_txt2html (WML)
External: --
=head1 SEE ALSO
txt2html(1), wml_aux_txt2html(3)
=cut
|