1 # Pod::Text::Overstrike -- Convert POD data to formatted overstrike text
2 # $Id: Overstrike.pm,v 1.4 2001/11/15 08:04:18 eagle Exp $
4 # Created by Joe Smith <Joe.Smith@inwap.com> 30-Nov-2000
5 # (based on Pod::Text::Color by Russ Allbery <rra@stanford.edu>)
7 # This program is free software; you may redistribute it and/or modify it
8 # under the same terms as Perl itself.
10 # This was written because the output from:
12 # pod2text Text.pm > plain.txt; less plain.txt
14 # is not as rich as the output from
16 # pod2man Text.pm | nroff -man > fancy.txt; less fancy.txt
18 # and because both Pod::Text::Color and Pod::Text::Termcap are not device
21 ##############################################################################
22 # Modules and declarations
23 ##############################################################################
25 package Pod::Text::Overstrike;
32 use vars qw(@ISA $VERSION);
36 # Don't use the CVS revision as the version, since this module is also in Perl
37 # core and too many things could munge CVS magic revision strings. This
38 # number should ideally be the same as the CVS revision in podlators, however.
42 ##############################################################################
44 ##############################################################################
46 # Make level one headings bold, overridding any existing formatting.
54 $self->SUPER::cmd_head1 ($_);
57 # Make level two headings bold, overriding any existing formatting.
65 $self->SUPER::cmd_head2 ($_);
68 # Make level three headings underscored, overriding any existing formatting.
76 $self->SUPER::cmd_head3 ($_);
79 # Fix the various interior sequences.
80 sub seq_b { local $_ = $_[1]; s/(.)\cH\1//g; s/_\cH//g; s/(.)/$1\b$1/g; $_ }
81 sub seq_f { local $_ = $_[1]; s/(.)\cH\1//g; s/_\cH//g; s/(.)/_\b$1/g; $_ }
82 sub seq_i { local $_ = $_[1]; s/(.)\cH\1//g; s/_\cH//g; s/(.)/_\b$1/g; $_ }
84 # Output any included code in bold.
86 my ($self, $code) = @_;
87 $code =~ s/(.)/$1\b$1/g;
88 $self->output ($code);
91 # We unfortunately have to override the wrapping code here, since the normal
92 # wrapping code gets really confused by all the escape sequences.
97 my $spaces = ' ' x $$self{MARGIN};
98 my $width = $$self{width} - $$self{MARGIN};
99 while (length > $width) {
100 if (s/^((?:(?:[^\n]\cH)?[^\n]){0,$width})(\Z|\s+)//
101 || s/^((?:(?:[^\n]\cH)?[^\n]){$width})//) {
102 $output .= $spaces . $1 . "\n";
107 $output .= $spaces . $_;
108 $output =~ s/\s+$/\n\n/;
112 ##############################################################################
113 # Module return value and documentation
114 ##############################################################################
121 Pod::Text::Overstrike - Convert POD data to formatted overstrike text
125 use Pod::Text::Overstrike;
126 my $parser = Pod::Text::Overstrike->new (sentence => 0, width => 78);
128 # Read POD from STDIN and write to STDOUT.
129 $parser->parse_from_filehandle;
131 # Read POD from file.pod and write to file.txt.
132 $parser->parse_from_file ('file.pod', 'file.txt');
136 Pod::Text::Overstrike is a simple subclass of Pod::Text that highlights
137 output text using overstrike sequences, in a manner similar to nroff.
138 Characters in bold text are overstruck (character, backspace, character) and
139 characters in underlined text are converted to overstruck underscores
140 (underscore, backspace, character). This format was originally designed for
141 hardcopy terminals and/or lineprinters, yet is readable on softcopy (CRT)
144 Overstruck text is best viewed by page-at-a-time programs that take
145 advantage of the terminal's B<stand-out> and I<underline> capabilities, such
146 as the less program on Unix.
148 Apart from the overstrike, it in all ways functions like Pod::Text. See
149 L<Pod::Text> for details and available options.
153 Currently, the outermost formatting instruction wins, so for example
154 underlined text inside a region of bold text is displayed as simply bold.
155 There may be some better approach possible.
159 L<Pod::Text>, L<Pod::Parser>
163 Joe Smith <Joe.Smith@inwap.com>, using the framework created by Russ Allbery
166 =head1 COPYRIGHT AND LICENSE
168 Copyright 2000 by Joe Smith <Joe.Smith@inwap.com>.
169 Copyright 2001 by Russ Allbery <rra@stanford.edu>.
171 This program is free software; you may redistribute it and/or modify it
172 under the same terms as Perl itself.