1 # Pod::Text::Overstrike -- Convert POD data to formatted overstrike text
2 # $Id: Overstrike.pm,v 1.5 2001/11/23 09:57:15 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.
48 my ($self, $text, $line) = @_;
50 $text = $self->strip_format ($self->interpolate ($text, $line));
51 $text =~ s/(.)/$1\b$1/g;
52 $self->SUPER::cmd_head1 ($text);
55 # Make level two headings bold, overriding any existing formatting.
57 my ($self, $text, $line) = @_;
59 $text = $self->strip_format ($self->interpolate ($text, $line));
60 $text =~ s/(.)/$1\b$1/g;
61 $self->SUPER::cmd_head2 ($text);
64 # Make level three headings underscored, overriding any existing formatting.
66 my ($self, $text, $line) = @_;
68 $text = $self->strip_format ($self->interpolate ($text, $line));
69 $text =~ s/(.)/_\b$1/g;
70 $self->SUPER::cmd_head3 ($text);
73 # Level four headings look like level three headings.
75 my ($self, $text, $line) = @_;
77 $text = $self->strip_format ($self->interpolate ($text, $line));
78 $text =~ s/(.)/_\b$1/g;
79 $self->SUPER::cmd_head4 ($text);
82 # The common code for handling all headers. We have to override to avoid
83 # interpolating twice and because we don't want to honor alt.
85 my ($self, $text, $line, $indent, $marker) = @_;
86 $self->item ("\n\n") if defined $$self{ITEM};
87 $text .= "\n" if $$self{loose};
88 $self->output (' ' x $indent . $text . "\n");
91 # Fix the various interior sequences.
92 sub seq_b { local $_ = strip_format (@_); s/(.)/$1\b$1/g; $_ }
93 sub seq_f { local $_ = strip_format (@_); s/(.)/_\b$1/g; $_ }
94 sub seq_i { local $_ = strip_format (@_); s/(.)/_\b$1/g; $_ }
96 # Output any included code in bold.
98 my ($self, $code) = @_;
99 $code =~ s/(.)/$1\b$1/g;
100 $self->output ($code);
103 # We unfortunately have to override the wrapping code here, since the normal
104 # wrapping code gets really confused by all the escape sequences.
109 my $spaces = ' ' x $$self{MARGIN};
110 my $width = $$self{width} - $$self{MARGIN};
111 while (length > $width) {
112 if (s/^((?:(?:[^\n]\cH)?[^\n]){0,$width})(\Z|\s+)//
113 || s/^((?:(?:[^\n]\cH)?[^\n]){$width})//) {
114 $output .= $spaces . $1 . "\n";
119 $output .= $spaces . $_;
120 $output =~ s/\s+$/\n\n/;
124 ##############################################################################
126 ##############################################################################
128 # Strip all of the formatting from a provided string, returning the stripped
131 my ($self, $text) = @_;
132 $text =~ s/(.)\cH\1/$1/g;
137 ##############################################################################
138 # Module return value and documentation
139 ##############################################################################
146 Pod::Text::Overstrike - Convert POD data to formatted overstrike text
150 use Pod::Text::Overstrike;
151 my $parser = Pod::Text::Overstrike->new (sentence => 0, width => 78);
153 # Read POD from STDIN and write to STDOUT.
154 $parser->parse_from_filehandle;
156 # Read POD from file.pod and write to file.txt.
157 $parser->parse_from_file ('file.pod', 'file.txt');
161 Pod::Text::Overstrike is a simple subclass of Pod::Text that highlights
162 output text using overstrike sequences, in a manner similar to nroff.
163 Characters in bold text are overstruck (character, backspace, character) and
164 characters in underlined text are converted to overstruck underscores
165 (underscore, backspace, character). This format was originally designed for
166 hardcopy terminals and/or lineprinters, yet is readable on softcopy (CRT)
169 Overstruck text is best viewed by page-at-a-time programs that take
170 advantage of the terminal's B<stand-out> and I<underline> capabilities, such
171 as the less program on Unix.
173 Apart from the overstrike, it in all ways functions like Pod::Text. See
174 L<Pod::Text> for details and available options.
178 Currently, the outermost formatting instruction wins, so for example
179 underlined text inside a region of bold text is displayed as simply bold.
180 There may be some better approach possible.
184 L<Pod::Text>, L<Pod::Parser>
188 Joe Smith <Joe.Smith@inwap.com>, using the framework created by Russ Allbery
191 =head1 COPYRIGHT AND LICENSE
193 Copyright 2000 by Joe Smith <Joe.Smith@inwap.com>.
194 Copyright 2001 by Russ Allbery <rra@stanford.edu>.
196 This program is free software; you may redistribute it and/or modify it
197 under the same terms as Perl itself.