Pod-PXML

 view release on metacpan or  search on metacpan

lib/Pod/PXML.pm  view on Meta::CPAN

        qq{<pod xmlns=\"$XMLNS\">},
        "<!-- (translated from pod, by " . __PACKAGE__ . " v$VERSION) -->",
        '',
        '',
      ;

      $post = "</pod>\n";  # harmless newline, I figure.
      
    } elsif($type eq 'for') {
      $out .= "<for target=\"" . xml_attr_escape($it->get_arg) . "\">";
      $out .= xml_escape_maybe_cdata($it->get_text);
      $out .= "</for>\n\n";
      return;
      
    } elsif($type eq 'sequence') {
      $type = lc($it->get_letter);
      DEBUG and print "Sequence type \"$type\"\n";
      if($type eq 'e') {
        # An unresolved entity.
        $x = $it->get_children;
        if($x and @$x ==1 and $x->[0]->get_type eq 'text') {

lib/Pod/PXML.pm  view on Meta::CPAN

      # Recurse for the item's children:
      foreach my $c (@{ $it->get_children || $nil }) { $trav->($c) }
      $out .= "</item>\n\n";

      # Then recurse for the bastards further down...
      
    } elsif($type eq 'verbatim') {
      ( $FUSE_ADJACENT_PRES and $out =~ s/<\/pre>\n\n$//s )
       or $out .= "<pre>";
       # possibly combine adjacent verbatims into a single 'pre'
      $out .= xml_escape_maybe_cdata("\n" . $it->get_text . "\n");
      $out =~ s/]]><!\[CDATA\[// if $out =~ m/]]>$/s;
       # combining adjacent CDATA sections is nice, and always harmless
      $out .= "</pre>\n\n";
      return;
      
    } elsif($type eq 'text') {
      $out .= xml_escape($it->get_text);
      return;
      
    } else {

lib/Pod/PXML.pm  view on Meta::CPAN

  undef $trav;  # break cyclicity
  print "\n\n" if DEBUG;

  sanitize_newlines($out);

  return $out;
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub xml_escape_maybe_cdata {  # not destructive
  my $x;
  $x = '' unless defined($x = $_[0]);
  if($x =~ m/[&<>]/ and not $x =~ m/[^\x00-\x80]/) {
    # CDATA only if uses those [&<>], and does not use anything highbit.
    $x =~ s/]]>/]]>]]&gt;<!\[CDATA\[/g;  # "escape" any ]]'s
    $x = "<![CDATA[" . $x . "]]>";
  } else {
    # Otherwise escape things.
    $x =~ s/&/&amp;/g;
    $x =~ s/</&lt;/g;

lib/Pod/PXML.pm  view on Meta::CPAN

}

###########################################################################
###########################################################################

use vars qw(%Acceptable_children);
{
  # This just recapitulates what's in the DTD:
  my $style  = {map{;$_,1} qw(b   i   c   x   f   s   link)};
  my $pstyle = {'#PCDATA',1, %$style};
  my $pcdata = {'#PCDATA',1};
  %Acceptable_children = (
   'pod'  => {map{;$_,1} qw(head1 head2 head3 head4 p pre list for)},
   map(($_=>$pstyle), qw(head1 head2 head3 head4 p)),
   'pre'  => $pcdata,
   'list' => {map{;$_,1} qw(item p pre list for)},
   'item' => $pstyle,
   'for' => $pcdata,
   map(($_=>$pstyle), qw(link b i c f x s)),
  );
}

sub xml2pod ($) {
  my $content = $_[0];
  require XML::Parser;
  
  my $out;
  my($gi, %attr, $text, $cm_set); # scratch



( run in 0.611 second using v1.01-cache-2.11-cpan-454fe037f31 )