Commit | Line | Data |
73849855 |
1 | # Pod::Text::Overstrike -- Convert POD data to formatted overstrike text |
59548eca |
2 | # $Id: Overstrike.pm,v 1.3 2001/10/20 08:11:29 eagle Exp $ |
73849855 |
3 | # |
4 | # Created by Joe Smith <Joe.Smith@inwap.com> 30-Nov-2000 |
5 | # (based on Pod::Text::Color by Russ Allbery <rra@stanford.edu>) |
6 | # |
3c014959 |
7 | # This program is free software; you may redistribute it and/or modify it |
73849855 |
8 | # under the same terms as Perl itself. |
9 | # |
10 | # This was written because the output from: |
11 | # |
12 | # pod2text Text.pm > plain.txt; less plain.txt |
13 | # |
14 | # is not as rich as the output from |
15 | # |
16 | # pod2man Text.pm | nroff -man > fancy.txt; less fancy.txt |
17 | # |
18 | # and because both Pod::Text::Color and Pod::Text::Termcap are not device |
19 | # independent. |
20 | |
3c014959 |
21 | ############################################################################## |
73849855 |
22 | # Modules and declarations |
3c014959 |
23 | ############################################################################## |
73849855 |
24 | |
25 | package Pod::Text::Overstrike; |
26 | |
27 | require 5.004; |
28 | |
29 | use Pod::Text (); |
30 | |
31 | use strict; |
32 | use vars qw(@ISA $VERSION); |
33 | |
34 | @ISA = qw(Pod::Text); |
35 | |
3c014959 |
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. |
59548eca |
39 | $VERSION = 1.03; |
73849855 |
40 | |
41 | |
3c014959 |
42 | ############################################################################## |
73849855 |
43 | # Overrides |
3c014959 |
44 | ############################################################################## |
73849855 |
45 | |
46 | # Make level one headings bold, overridding any existing formatting. |
47 | sub cmd_head1 { |
48 | my $self = shift; |
49 | local $_ = shift; |
50 | s/\s+$//; |
51 | s/(.)\cH\1//g; |
52 | s/_\cH//g; |
53 | s/(.)/$1\b$1/g; |
54 | $self->SUPER::cmd_head1 ($_); |
55 | } |
56 | |
57 | # Make level two headings bold, overriding any existing formatting. |
58 | sub cmd_head2 { |
59 | my $self = shift; |
60 | local $_ = shift; |
61 | s/\s+$//; |
62 | s/(.)\cH\1//g; |
63 | s/_\cH//g; |
64 | s/(.)/$1\b$1/g; |
65 | $self->SUPER::cmd_head2 ($_); |
66 | } |
67 | |
68 | # Make level three headings underscored, overriding any existing formatting. |
69 | sub cmd_head3 { |
70 | my $self = shift; |
71 | local $_ = shift; |
72 | s/\s+$//; |
73 | s/(.)\cH\1//g; |
74 | s/_\cH//g; |
75 | s/(.)/_\b$1/g; |
76 | $self->SUPER::cmd_head3 ($_); |
77 | } |
78 | |
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; $_ } |
83 | |
59548eca |
84 | # Output any included code in bold. |
85 | sub output_code { |
86 | my ($self, $code) = @_; |
87 | $code =~ s/(.)/$1\b$1/g; |
88 | $self->output ($code); |
89 | } |
90 | |
73849855 |
91 | # We unfortunately have to override the wrapping code here, since the normal |
92 | # wrapping code gets really confused by all the escape sequences. |
93 | sub wrap { |
94 | my $self = shift; |
95 | local $_ = shift; |
96 | my $output = ''; |
97 | my $spaces = ' ' x $$self{MARGIN}; |
98 | my $width = $$self{width} - $$self{MARGIN}; |
99 | while (length > $width) { |
59548eca |
100 | if (s/^((?:(?:[^\n]\cH)?[^\n]){0,$width})(\Z|\s+)// |
73849855 |
101 | || s/^((?:(?:[^\n]\cH)?[^\n]){$width})//) { |
102 | $output .= $spaces . $1 . "\n"; |
103 | } else { |
104 | last; |
105 | } |
106 | } |
107 | $output .= $spaces . $_; |
108 | $output =~ s/\s+$/\n\n/; |
109 | $output; |
110 | } |
111 | |
3c014959 |
112 | ############################################################################## |
73849855 |
113 | # Module return value and documentation |
3c014959 |
114 | ############################################################################## |
73849855 |
115 | |
116 | 1; |
117 | __END__ |
118 | |
119 | =head1 NAME |
120 | |
121 | Pod::Text::Overstrike - Convert POD data to formatted overstrike text |
122 | |
123 | =head1 SYNOPSIS |
124 | |
125 | use Pod::Text::Overstrike; |
126 | my $parser = Pod::Text::Overstrike->new (sentence => 0, width => 78); |
127 | |
128 | # Read POD from STDIN and write to STDOUT. |
129 | $parser->parse_from_filehandle; |
130 | |
131 | # Read POD from file.pod and write to file.txt. |
132 | $parser->parse_from_file ('file.pod', 'file.txt'); |
133 | |
134 | =head1 DESCRIPTION |
135 | |
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) |
142 | terminals. |
143 | |
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. |
147 | |
148 | Apart from the overstrike, it in all ways functions like Pod::Text. See |
149 | L<Pod::Text> for details and available options. |
150 | |
151 | =head1 BUGS |
152 | |
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. |
156 | |
157 | =head1 SEE ALSO |
158 | |
159 | L<Pod::Text|Pod::Text>, L<Pod::Parser|Pod::Parser> |
160 | |
161 | =head1 AUTHOR |
162 | |
3c014959 |
163 | Joe Smith <Joe.Smith@inwap.com>, using the framework created by Russ Allbery |
164 | <rra@stanford.edu>. |
165 | |
166 | =head1 COPYRIGHT AND LICENSE |
167 | |
168 | Copyright 2000 by Joe Smith <Joe.Smith@inwap.com>. |
59548eca |
169 | Copyright 2001 by Russ Allbery <rra@stanford.edu>. |
3c014959 |
170 | |
171 | This program is free software; you may redistribute it and/or modify it |
172 | under the same terms as Perl itself. |
73849855 |
173 | |
174 | =cut |