1 # Pod::Text::Overstrike -- Convert POD data to formatted overstrike text
3 # Created by Joe Smith <Joe.Smith@inwap.com> 30-Nov-2000
4 # (based on Pod::Text::Color by Russ Allbery <rra@stanford.edu>)
5 # Copyright 2000 Joe Smith <Joe.Smith@inwap.com>.
6 # Copyright 2001, 2004, 2008 Russ Allbery <rra@stanford.edu>.
8 # This program is free software; you may redistribute it and/or modify it
9 # under the same terms as Perl itself.
11 # This was written because the output from:
13 # pod2text Text.pm > plain.txt; less plain.txt
15 # is not as rich as the output from
17 # pod2man Text.pm | nroff -man > fancy.txt; less fancy.txt
19 # and because both Pod::Text::Color and Pod::Text::Termcap are not device
22 ##############################################################################
23 # Modules and declarations
24 ##############################################################################
26 package Pod::Text::Overstrike;
33 use vars qw(@ISA $VERSION);
39 ##############################################################################
41 ##############################################################################
43 # Make level one headings bold, overridding any existing formatting.
45 my ($self, $attrs, $text) = @_;
47 $text = $self->strip_format ($text);
48 $text =~ s/(.)/$1\b$1/g;
49 return $self->SUPER::cmd_head1 ($attrs, $text);
52 # Make level two headings bold, overriding any existing formatting.
54 my ($self, $attrs, $text) = @_;
56 $text = $self->strip_format ($text);
57 $text =~ s/(.)/$1\b$1/g;
58 return $self->SUPER::cmd_head2 ($attrs, $text);
61 # Make level three headings underscored, overriding any existing formatting.
63 my ($self, $attrs, $text) = @_;
65 $text = $self->strip_format ($text);
66 $text =~ s/(.)/_\b$1/g;
67 return $self->SUPER::cmd_head3 ($attrs, $text);
70 # Level four headings look like level three headings.
72 my ($self, $attrs, $text) = @_;
74 $text = $self->strip_format ($text);
75 $text =~ s/(.)/_\b$1/g;
76 return $self->SUPER::cmd_head4 ($attrs, $text);
79 # The common code for handling all headers. We have to override to avoid
80 # interpolating twice and because we don't want to honor alt.
82 my ($self, $text, $indent, $marker) = @_;
83 $self->item ("\n\n") if defined $$self{ITEM};
84 $text .= "\n" if $$self{opt_loose};
85 my $margin = ' ' x ($$self{opt_margin} + $indent);
86 $self->output ($margin . $text . "\n");
90 # Fix the various formatting codes.
91 sub cmd_b { local $_ = $_[0]->strip_format ($_[2]); s/(.)/$1\b$1/g; $_ }
92 sub cmd_f { local $_ = $_[0]->strip_format ($_[2]); s/(.)/_\b$1/g; $_ }
93 sub cmd_i { local $_ = $_[0]->strip_format ($_[2]); s/(.)/_\b$1/g; $_ }
95 # Output any included code in bold.
97 my ($self, $code) = @_;
98 $code =~ s/(.)/$1\b$1/g;
99 $self->output ($code);
102 # We unfortunately have to override the wrapping code here, since the normal
103 # wrapping code gets really confused by all the backspaces.
108 my $spaces = ' ' x $$self{MARGIN};
109 my $width = $$self{opt_width} - $$self{MARGIN};
110 while (length > $width) {
111 # This regex represents a single character, that's possibly underlined
112 # or in bold (in which case, it's three characters; the character, a
113 # backspace, and a character). Use [^\n] rather than . to protect
114 # against odd settings of $*.
115 my $char = '(?:[^\n][\b])?[^\n]';
116 if (s/^((?>$char){0,$width})(?:\Z|\s+)//) {
117 $output .= $spaces . $1 . "\n";
122 $output .= $spaces . $_;
123 $output =~ s/\s+$/\n\n/;
127 ##############################################################################
129 ##############################################################################
131 # Strip all of the formatting from a provided string, returning the stripped
134 my ($self, $text) = @_;
135 $text =~ s/(.)[\b]\1/$1/g;
140 ##############################################################################
141 # Module return value and documentation
142 ##############################################################################
152 Pod::Text::Overstrike - Convert POD data to formatted overstrike text
155 overstruck Overstruck Allbery terminal's
159 use Pod::Text::Overstrike;
160 my $parser = Pod::Text::Overstrike->new (sentence => 0, width => 78);
162 # Read POD from STDIN and write to STDOUT.
163 $parser->parse_from_filehandle;
165 # Read POD from file.pod and write to file.txt.
166 $parser->parse_from_file ('file.pod', 'file.txt');
170 Pod::Text::Overstrike is a simple subclass of Pod::Text that highlights
171 output text using overstrike sequences, in a manner similar to nroff.
172 Characters in bold text are overstruck (character, backspace, character)
173 and characters in underlined text are converted to overstruck underscores
174 (underscore, backspace, character). This format was originally designed
175 for hard-copy terminals and/or line printers, yet is readable on soft-copy
178 Overstruck text is best viewed by page-at-a-time programs that take
179 advantage of the terminal's B<stand-out> and I<underline> capabilities, such
180 as the less program on Unix.
182 Apart from the overstrike, it in all ways functions like Pod::Text. See
183 L<Pod::Text> for details and available options.
187 Currently, the outermost formatting instruction wins, so for example
188 underlined text inside a region of bold text is displayed as simply bold.
189 There may be some better approach possible.
193 L<Pod::Text>, L<Pod::Simple>
195 The current version of this module is always available from its web site at
196 L<http://www.eyrie.org/~eagle/software/podlators/>. It is also part of the
197 Perl core distribution as of 5.6.0.
201 Joe Smith <Joe.Smith@inwap.com>, using the framework created by Russ Allbery
204 =head1 COPYRIGHT AND LICENSE
206 Copyright 2000 by Joe Smith <Joe.Smith@inwap.com>.
207 Copyright 2001, 2004 by Russ Allbery <rra@stanford.edu>.
209 This program is free software; you may redistribute it and/or modify it
210 under the same terms as Perl itself.