Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
4.8 KiB

  1. # Pod::Text::Overstrike -- Convert POD data to formatted overstrike text
  2. # $Id: Overstrike.pm,v 1.1 2000/12/25 12:51:23 eagle Exp $
  3. #
  4. # Created by Joe Smith <[email protected]> 30-Nov-2000
  5. # (based on Pod::Text::Color by Russ Allbery <[email protected]>)
  6. #
  7. # This program is free software; you can redistribute it and/or modify it
  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. ############################################################################
  21. # Modules and declarations
  22. ############################################################################
  23. package Pod::Text::Overstrike;
  24. require 5.004;
  25. use Pod::Text ();
  26. use strict;
  27. use vars qw(@ISA $VERSION);
  28. @ISA = qw(Pod::Text);
  29. # Don't use the CVS revision as the version, since this module is also in
  30. # Perl core and too many things could munge CVS magic revision strings.
  31. # This number should ideally be the same as the CVS revision in podlators,
  32. # however.
  33. $VERSION = 1.01;
  34. ############################################################################
  35. # Overrides
  36. ############################################################################
  37. # Make level one headings bold, overridding any existing formatting.
  38. sub cmd_head1 {
  39. my $self = shift;
  40. local $_ = shift;
  41. s/\s+$//;
  42. s/(.)\cH\1//g;
  43. s/_\cH//g;
  44. s/(.)/$1\b$1/g;
  45. $self->SUPER::cmd_head1 ($_);
  46. }
  47. # Make level two headings bold, overriding any existing formatting.
  48. sub cmd_head2 {
  49. my $self = shift;
  50. local $_ = shift;
  51. s/\s+$//;
  52. s/(.)\cH\1//g;
  53. s/_\cH//g;
  54. s/(.)/$1\b$1/g;
  55. $self->SUPER::cmd_head2 ($_);
  56. }
  57. # Make level three headings underscored, overriding any existing formatting.
  58. sub cmd_head3 {
  59. my $self = shift;
  60. local $_ = shift;
  61. s/\s+$//;
  62. s/(.)\cH\1//g;
  63. s/_\cH//g;
  64. s/(.)/_\b$1/g;
  65. $self->SUPER::cmd_head3 ($_);
  66. }
  67. # Fix the various interior sequences.
  68. sub seq_b { local $_ = $_[1]; s/(.)\cH\1//g; s/_\cH//g; s/(.)/$1\b$1/g; $_ }
  69. sub seq_f { local $_ = $_[1]; s/(.)\cH\1//g; s/_\cH//g; s/(.)/_\b$1/g; $_ }
  70. sub seq_i { local $_ = $_[1]; s/(.)\cH\1//g; s/_\cH//g; s/(.)/_\b$1/g; $_ }
  71. # We unfortunately have to override the wrapping code here, since the normal
  72. # wrapping code gets really confused by all the escape sequences.
  73. sub wrap {
  74. my $self = shift;
  75. local $_ = shift;
  76. my $output = '';
  77. my $spaces = ' ' x $$self{MARGIN};
  78. my $width = $$self{width} - $$self{MARGIN};
  79. while (length > $width) {
  80. if (s/^((?:(?:[^\n]\cH)?[^\n]){0,$width})\s+//
  81. || s/^((?:(?:[^\n]\cH)?[^\n]){$width})//) {
  82. $output .= $spaces . $1 . "\n";
  83. } else {
  84. last;
  85. }
  86. }
  87. $output .= $spaces . $_;
  88. $output =~ s/\s+$/\n\n/;
  89. $output;
  90. }
  91. ############################################################################
  92. # Module return value and documentation
  93. ############################################################################
  94. 1;
  95. __END__
  96. =head1 NAME
  97. Pod::Text::Overstrike - Convert POD data to formatted overstrike text
  98. =head1 SYNOPSIS
  99. use Pod::Text::Overstrike;
  100. my $parser = Pod::Text::Overstrike->new (sentence => 0, width => 78);
  101. # Read POD from STDIN and write to STDOUT.
  102. $parser->parse_from_filehandle;
  103. # Read POD from file.pod and write to file.txt.
  104. $parser->parse_from_file ('file.pod', 'file.txt');
  105. =head1 DESCRIPTION
  106. Pod::Text::Overstrike is a simple subclass of Pod::Text that highlights
  107. output text using overstrike sequences, in a manner similar to nroff.
  108. Characters in bold text are overstruck (character, backspace, character) and
  109. characters in underlined text are converted to overstruck underscores
  110. (underscore, backspace, character). This format was originally designed for
  111. hardcopy terminals and/or lineprinters, yet is readable on softcopy (CRT)
  112. terminals.
  113. Overstruck text is best viewed by page-at-a-time programs that take
  114. advantage of the terminal's B<stand-out> and I<underline> capabilities, such
  115. as the less program on Unix.
  116. Apart from the overstrike, it in all ways functions like Pod::Text. See
  117. L<Pod::Text> for details and available options.
  118. =head1 BUGS
  119. Currently, the outermost formatting instruction wins, so for example
  120. underlined text inside a region of bold text is displayed as simply bold.
  121. There may be some better approach possible.
  122. =head1 SEE ALSO
  123. L<Pod::Text|Pod::Text>, L<Pod::Parser|Pod::Parser>
  124. =head1 AUTHOR
  125. Joe Smith E<lt>Joe.Smith@inwap.comE<gt>, using the framework created by Russ
  126. Allbery E<lt>rra@stanford.eduE<gt>.
  127. =cut