makepp

 view release on metacpan or  search on metacpan

pod/html/html.pl  view on Meta::CPAN

        # have a look for all-space lines
      if( ${$dataref}[$i] =~ /^\s+$/m and $dataref->[$i] !~ /^\s/ ){
	    my @chunks = split( /^\s+$/m, ${$dataref}[$i] );
	    splice( @$dataref, $i, 1, @chunks );
	}
    }
}


sub pod2html {
    local(@ARGV) = @_;
    local($/);
    local $_;

    init_globals();

    $Is83 = 0 if (defined (&Dos::UseLFN) && Dos::UseLFN());

    # cache of %Pages and %Items from last time we ran pod2html

    #undef $opt_help if defined $opt_help;

    # parse the command-line parameters
    parse_command_line();

    # escape the backlink argument (same goes for title but is done later...)
    $Backlink = html_escape($Backlink) if defined $Backlink;

    # set some variables to their default values if necessary
    my $pod;
    unless (@ARGV && $ARGV[0]) {
	if ($Podfile and $Podfile ne '-') {
	    open $pod, '<', $Podfile
		or die "$0: cannot open $Podfile file for input: $!\n";
	    binmode $pod, ':utf8' if $] > 5.008; # suppress warning
	} else {
	    open $pod, '-';
	}
    } else {
	$Podfile = $ARGV[0];  # XXX: might be more filenames
	$pod = *ARGV;
    }
    $Htmlfile = "-" unless $Htmlfile;	# stdout
    $Htmlroot = "" if $Htmlroot eq "/";	# so we don't get a //
    $Htmldir =~ s#/\z## ;               # so we don't get a //
    if (  $Htmlroot eq ''
       && defined( $Htmldir )
       && $Htmldir ne ''
       && substr( $Htmlfile, 0, length( $Htmldir ) ) eq $Htmldir
       )
    {
	# Set the 'base' url for this file, so that we can use it
	# as the location from which to calculate relative links
	# to other files. If this is '', then absolute links will
	# be used throughout.
        $Htmlfileurl= "$Htmldir/" . substr( $Htmlfile, length( $Htmldir ) + 1);
    }

    # read the pod a paragraph at a time
    warn "Scanning for sections in input file(s)\n" if $Verbose;
    $/ = "";
    my @poddata  = <$pod>;
    close $pod;

    # be eol agnostic
    for (@poddata) {
	if (/\r/) {
	    if (/\r\n/) {
		@poddata = map { s/\r\n/\n/g;
				 /\n\n/ ?
				     map { "$_\n\n" } split /\n\n/ :
				     $_ } @poddata;
	    } else {
		@poddata = map { s/\r/\n/g;
				 /\n\n/ ?
				     map { "$_\n\n" } split /\n\n/ :
				     $_ } @poddata;
	    }
	    last;
	}
    }

    clean_data( \@poddata );

    # scan the pod for =head[1-6] directives and build an index
    my $index = scan_headings(\%Sections, @poddata);

    unless($index) {
	warn "No headings in $Podfile\n" if $Verbose;
    }

    # open the output file
    my $html;
    if($Htmlfile and $Htmlfile ne '-') {
        open $html, ">", $Htmlfile
            or die "$0: cannot open $Htmlfile file for output: $!\n";
	binmode $html, ':utf8' if $] > 5.008; # suppress warning
    } else {
        open $html, ">-";
    }

    # put a title in the HTML file if one wasn't specified
    if ($Title eq '') {
	TITLE_SEARCH: {
 	    for (my $i = 0; $i < @poddata; $i++) {
		if ($poddata[$i] =~ /^=head1\s*NAME\b/m) {
 		    for my $para ( @poddata[$i, $i+1] ) {
			last TITLE_SEARCH
			    if ($Title) = $para =~ /(\S+\s+-+.*\S)/s;
		    }
		}

	    }
	}
    }
    if (!$Title and $Podfile =~ /\.pod\z/) {
	# probably a split pod so take first =head[12] as title
 	for (my $i = 0; $i < @poddata; $i++) {
	    last if ($Title) = $poddata[$i] =~ /^=head[12]\s*(.*)/;
	}
	warn "adopted '$Title' as title for $Podfile\n"



( run in 1.053 second using v1.01-cache-2.11-cpan-364913b4093 )