⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plaintext.pm

📁 mrtg 监控,请认真阅读您的文件包然后写出其具体功能
💻 PM
📖 第 1 页 / 共 2 页
字号:
    $$self{VERBATIM} = 0;}    # One paragraph for a particular translator.  Ignore it unless it's intended# for text, in which case we treat it as a verbatim text block.sub cmd_for {    my $self = shift;    local $_ = shift;    my $line = shift;    return unless s/^text\b[ \t]*\n?//;    $self->verbatim ($_, $line);}############################################################################# Interior sequences############################################################################# The simple formatting ones.  These are here mostly so that subclasses can# override them and do more complicated things.sub seq_b { return $_[0]{alt} ? "``$_[1]''" : $_[1] }sub seq_c { return $_[0]{alt} ? "``$_[1]''" : "`$_[1]'" }sub seq_f { return $_[0]{alt} ? "\"$_[1]\"" : $_[1] }sub seq_i { return '*' . $_[1] . '*' }# The complicated one.  Handle links.  Since this is plain text, we can't# actually make any real links, so this is all to figure out what text we# print out.sub seq_l {    my $self = shift;    local $_ = shift;    # Smash whitespace in case we were split across multiple lines.    s/\s+/ /g;    # If we were given any explicit text, just output it.    if (/^([^|]+)\|/) { return $1 }    # Okay, leading and trailing whitespace isn't important; get rid of it.    s/^\s+//;    s/\s+$//;    # Default to using the whole content of the link entry as a section    # name.  Note that L<manpage/> forces a manpage interpretation, as does    # something looking like L<manpage(section)>.  The latter is an    # enhancement over the original Pod::Text.    my ($manpage, $section) = ('', $_);    if (/^"\s*(.*?)\s*"$/) {        $section = '"' . $1 . '"';    } elsif (m/^[-:.\w]+(?:\(\S+\))?$/) {        ($manpage, $section) = ($_, '');    } elsif (m%/%) {        ($manpage, $section) = split (/\s*\/\s*/, $_, 2);    }    # Now build the actual output text.    my $text = '';    if (!length $section) {        $text = "the $manpage manpage" if length $manpage;    } elsif ($section =~ /^[:\w]+(?:\(\))?/) {        $text .= 'the ' . $section . ' entry';        $text .= (length $manpage) ? " in the $manpage manpage"                                   : " elsewhere in this document";    } else {        $section =~ s/^\"\s*//;        $section =~ s/\s*\"$//;        $text .= 'the section on "' . $section . '"';        $text .= " in the $manpage manpage" if length $manpage;    }    $text;}############################################################################# List handling############################################################################# This method is called whenever an =item command is complete (in other# words, we've seen its associated paragraph or know for certain that it# doesn't have one).  It gets the paragraph associated with the item as an# argument.  If that argument is empty, just output the item tag; if it# contains a newline, output the item tag followed by the newline.# Otherwise, see if there's enough room for us to output the item tag in the# margin of the text or if we have to put it on a separate line.sub item {    my $self = shift;    local $_ = shift;    my $tag = $$self{ITEM};    unless (defined $tag) {        carp "item called without tag";        return;    }    undef $$self{ITEM};    my $indent = $$self{INDENTS}[-1];    unless (defined $indent) { $indent = $$self{indent} }    my $space = ' ' x $indent;    $space =~ s/^ /:/ if $$self{alt};    if (!$_ || /^\s+$/ || ($$self{MARGIN} - $indent < length ($tag) + 1)) {        my $margin = $$self{MARGIN};        $$self{MARGIN} = $indent;        my $output = $self->reformat ($tag);        $output =~ s/\n*$/\n/;        $self->output ($output);        $$self{MARGIN} = $margin;        $self->output ($self->reformat ($_)) if /\S/;    } else {        $_ = $self->reformat ($_);        s/^ /:/ if ($$self{alt} && $indent > 0);        my $tagspace = ' ' x length $tag;        s/^($space)$tagspace/$1$tag/ or warn "Bizarre space in item";        $self->output ($_);    }}############################################################################# Output formatting############################################################################# Wrap a line, indenting by the current left margin.  We can't use# Text::Wrap because it plays games with tabs.  We can't use formline, even# though we'd really like to, because it screws up non-printing characters.# So we have to do the wrapping ourselves.sub wrap {    my $self = shift;    local $_ = shift;    my $output = '';    my $spaces = ' ' x $$self{MARGIN};    my $width = $$self{width} - $$self{MARGIN};    while (length > $width) {        if (s/^([^\n]{0,$width})\s+// || s/^([^\n]{$width})//) {            $output .= $spaces . $1 . "\n";        } else {            last;        }    }    $output .= $spaces . $_;    $output =~ s/\s+$/\n\n/;    $output;}# Reformat a paragraph of text for the current margin.  Takes the text to# reformat and returns the formatted text.sub reformat {    my $self = shift;    local $_ = shift;    # If we're trying to preserve two spaces after sentences, do some    # munging to support that.  Otherwise, smash all repeated whitespace.    if ($$self{sentence}) {        s/ +$//mg;        s/\.\n/. \n/g;        s/\n/ /g;        s/   +/  /g;    } else {        s/\s+/ /g;    }    $self->wrap ($_);}# Output text to the output device.sub output { $_[1] =~ tr/\01/ /; print { $_[0]->output_handle } $_[1] }############################################################################# Backwards compatibility############################################################################# The old Pod::Text module did everything in a pod2text() function.  This# tries to provide the same interface for legacy applications.sub pod2text {    my @args;    # This is really ugly; I hate doing option parsing in the middle of a    # module.  But the old Pod::Text module supported passing flags to its    # entry function, so handle -a and -<number>.    while ($_[0] =~ /^-/) {        my $flag = shift;        if    ($flag eq '-a')       { push (@args, alt => 1)    }        elsif ($flag =~ /^-(\d+)$/) { push (@args, width => $1) }        else {            unshift (@_, $flag);            last;        }    }    # Now that we know what arguments we're using, create the parser.    my $parser = Pod::PlainText->new (@args);    # If two arguments were given, the second argument is going to be a file    # handle.  That means we want to call parse_from_filehandle(), which    # means we need to turn the first argument into a file handle.  Magic    # open will handle the <&STDIN case automagically.    if (defined $_[1]) {        local *IN;        unless (open (IN, $_[0])) {            croak ("Can't open $_[0] for reading: $!\n");            return;        }        $_[0] = \*IN;        return $parser->parse_from_filehandle (@_);    } else {        return $parser->parse_from_file (@_);    }}############################################################################# Module return value and documentation############################################################################1;__END__=head1 NAMEPod::PlainText - Convert POD data to formatted ASCII text=head1 SYNOPSIS    use Pod::PlainText;    my $parser = Pod::PlainText->new (sentence => 0, width => 78);    # Read POD from STDIN and write to STDOUT.    $parser->parse_from_filehandle;    # Read POD from file.pod and write to file.txt.    $parser->parse_from_file ('file.pod', 'file.txt');=head1 DESCRIPTIONPod::PlainText is a module that can convert documentation in the POD format (thepreferred language for documenting Perl) into formatted ASCII.  It uses nospecial formatting controls or codes whatsoever, and its output is thereforesuitable for nearly any device.As a derived class from Pod::Parser, Pod::PlainText supports the same methods andinterfaces.  See L<Pod::Parser> for all the details; briefly, one creates anew parser with C<Pod::PlainText-E<gt>new()> and then calls eitherparse_from_filehandle() or parse_from_file().new() can take options, in the form of key/value pairs, that control thebehavior of the parser.  The currently recognized options are:=over 4=item altIf set to a true value, selects an alternate output format that, among otherthings, uses a different heading style and marks C<=item> entries with acolon in the left margin.  Defaults to false.=item indentThe number of spaces to indent regular text, and the default indentation forC<=over> blocks.  Defaults to 4.=item looseIf set to a true value, a blank line is printed after a C<=head1> heading.If set to false (the default), no blank line is printed after C<=head1>,although one is still printed after C<=head2>.  This is the default becauseit's the expected formatting for manual pages; if you're formattingarbitrary text documents, setting this to true may result in more pleasingoutput.=item sentenceIf set to a true value, Pod::PlainText will assume that each sentence ends in twospaces, and will try to preserve that spacing.  If set to false, allconsecutive whitespace in non-verbatim paragraphs is compressed into asingle space.  Defaults to true.=item widthThe column at which to wrap text on the right-hand side.  Defaults to 76.=backThe standard Pod::Parser method parse_from_filehandle() takes up to twoarguments, the first being the file handle to read POD from and the secondbeing the file handle to write the formatted output to.  The first defaultsto STDIN if not given, and the second defaults to STDOUT.  The methodparse_from_file() is almost identical, except that its two arguments are theinput and output disk files instead.  See L<Pod::Parser> for the specificdetails.=head1 DIAGNOSTICS=over 4=item Bizarre space in item(W) Something has gone wrong in internal C<=item> processing.  This messageindicates a bug in Pod::PlainText; you should never see it.=item Can't open %s for reading: %s(F) Pod::PlainText was invoked via the compatibility mode pod2text() interfaceand the input file it was given could not be opened.=item Unknown escape: %s(W) The POD source contained an C<EE<lt>E<gt>> escape that Pod::PlainText didn'tknow about.=item Unknown sequence: %s(W) The POD source contained a non-standard internal sequence (something ofthe form C<XE<lt>E<gt>>) that Pod::PlainText didn't know about.=item Unmatched =back(W) Pod::PlainText encountered a C<=back> command that didn't correspond to anC<=over> command.=back=head1 RESTRICTIONSEmbedded Ctrl-As (octal 001) in the input will be mapped to spaces onoutput, due to an internal implementation detail.=head1 NOTESThis is a replacement for an earlier Pod::Text module written by TomChristiansen.  It has a revamped interface, since it now uses Pod::Parser,but an interface roughly compatible with the old Pod::Text::pod2text()function is still available.  Please change to the new calling convention,though.The original Pod::Text contained code to do formatting via termcapsequences, although it wasn't turned on by default and it was problematic toget it to work at all.  This rewrite doesn't even try to do that, but asubclass of it does.  Look for L<Pod::Text::Termcap|Pod::Text::Termcap>.=head1 SEE ALSOL<Pod::Parser|Pod::Parser>, L<Pod::Text::Termcap|Pod::Text::Termcap>,pod2text(1)=head1 AUTHORRuss Allbery E<lt>rra@stanford.eduE<gt>, based I<very> heavily on theoriginal Pod::Text by Tom Christiansen E<lt>tchrist@mox.perl.comE<gt> andits conversion to Pod::Parser by Brad AppletonE<lt>bradapp@enteract.comE<gt>.=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -