Text-Restructured

 view release on metacpan or  search on metacpan

lib/Text/Restructured/Transforms.pm  view on Meta::CPAN

		    }
		    elsif ($fb->num_contents > 1) {
			# Multiple paragraphs
			foreach ($fb->contents) {
			    my $author = $DOM->new('author');
			    $bib->append($author);
			    $author->append($_->contents);
			}
		    }
		    elsif ($fb->first->tag eq 'bullet_list') {
			my $bl = $fb->first;
			foreach ($bl->contents) {
			    my $author = $DOM->new('author');
			    $bib->append($author);
			    $author->append($_->first->contents);
			}
		    }
		    else {
			my $text;
			$fb->Recurse(sub {
			    my ($dom) = @_;
			    $text .= $dom->{text}
			    if $dom->tag eq '#PCDATA';
			});
			my @authors = $text =~ /;/ ?
			    split(/\s*;\s*/, $text) :
			    split(/\s*,\s*/, $text);
			foreach (@authors) {
			    my $author = $DOM->new('author');
			    $bib->append($author);
			    $author->append($DOM->newPCDATA($_));
			}
		    }
		    if ($bib->num_contents == 1) {
			$docinfo->append($bib->first);
		    }
		    elsif ($bib->num_contents > 1) {
			$docinfo->append($bib);
		    }
		}
		elsif ($fb->num_contents > 1) {
		    $fb->append
			($parser->system_message(2, $field->{source},
					     $field->{lineno},
					     qq(Cannot extract compound bibliographic field "$origname".)));
		    $docinfo->append($field);
		}
		elsif ($fb->first->tag ne 'paragraph') {
		    $fb->append
			($parser->system_message(2, $field->{source},
					     $field->{lineno},
					     qq(Cannot extract bibliographic field "$origname" containing anything other than a single paragraph.)));
		    $docinfo->append($field);
		}
		else {
		    my $bib = $DOM->new($name);
		    %{$bib->{attr}} = (%Text::Restructured::XML_SPACE)
			if $name =~ /^address$/i;
		    $docinfo->append($bib);
		    my @contents = $fb->first->contents;
		    my $pcdata = $contents[0];
		    $pcdata->{text} =~ s/\$\w+:\s*(.+?)(?:,v)?\s\$/$1/g
			if defined $pcdata->{text};
		    $bib->append(@contents);
		}
	    }
	    else {
		$docinfo->append($field);
	    }
	}

	# Anything before the docinfo that's not a title, subtitle, or
	# decoration has to move after it.
	my $i;
	my $docinfo_seen = 0;
	my @new_content;  
	for ($i=0; $i < $dom->num_contents; $i++) {
	    my $c = $dom->child($i);
	    if ($docinfo_seen || $c->tag =~ /^((sub)?title|decoration)$/) {
		push @new_content, $c;
	    }
	    elsif ($c->tag eq 'docinfo') {
		$docinfo_seen = 1;
		push @new_content, $c, @postdocinfo;
	    }
	    else {
		push @postdocinfo, $c;
	    }
	}
	$dom->replace(@new_content);
#	$dom->{content} = \@new_content;
    }
}
}

# Processes a docutils.transforms.frontmatter.DocInfo transform.
# Processes field lists at the beginning of the DOM that are one of
# the docinfo types into a docinfo section.
# Arguments: top-level DOM, parser obj
sub DocInfo {
    my ($dom, $parser, $level) = @_;

    $level = $level || 0;
    process_docinfo($dom, $parser);
    if ($level < ($parser->{opt}{D}{docinfo_levels} || 0)) {
	my @sections = grep($_->tag eq 'section', $dom->contents);
	foreach my $section (@sections) {
	    process_docinfo($section, $parser);
	}
    }
}

# Processes a docutils.transforms.frontmatter.DocTitle transform.
# Creates a document title if the top-level DOM has only one top-level
# section.  Creates a subtitle if a unique top-level section has a
# unique second-level section.
# Arguments: top-level DOM, parser obj
sub DocTitle {
    my ($dom, $parser) = @_;

    create_title($dom, $parser);
    $dom->{attr}{title} = $dom->{'.details'}{title}
        if defined $dom->{'.details'}{title};



( run in 0.788 second using v1.01-cache-2.11-cpan-39bf76dae61 )