SGML-DTDParse

 view release on metacpan or  search on metacpan

lib/SGML/DTDParse/Format/refentry.pl  view on Meta::CPAN

    return $html;
}

sub formatElementExamples {
    my $count   = shift;
    my $name    = $elements[$count];
    my $element = $elements{$name};

    return "";
}

sub formatElementFooter {
    my $count = shift;
    my $html = "";

    $html .= "</refentry>\n";

    return $html;
}

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

my $state = 'NONE';
my $depth = 0;
my $col = 0;

sub formatContentModel {
    my $count = shift;
    my $cm = shift;
    my $node = $cm->getFirstChild();
    my $html = "";

    $state = "NONE";
    $depth = 0;
    $col = 0;
    while ($node) {
	if ($node->getNodeType == XML::DOM::ELEMENT_NODE) {
	    $html .= formatContentModelElement($node);
	}
	$node = $node->getNextSibling();
    }

    return $html;
}

sub formatContentModelElement {
    my $node = shift;
    my $html = "";

    if ($node->getNodeType == XML::DOM::ELEMENT_NODE) {
	if ($node->getTagName() eq 'sequence-group') {
	    $html .= &formatCMGroup($node, ",");
	} elsif ($node->getTagName() eq 'or-group') {
	    $html .= &formatCMGroup($node, "|");
	} elsif ($node->getTagName() eq 'and-group') {
	    $html .= &formatCMGroup($node, "&");
	} elsif ($node->getTagName() eq 'element-name') {
	    $html .= &formatCMElement($node);
	} elsif ($node->getTagName() eq 'parament-name') {
	    $html .= &formatCMParament($node);
	} elsif ($node->getTagName() eq 'pcdata') {
	    $html .= &formatCMPCDATA($node);
	} elsif ($node->getTagName() eq 'cdata') {
	    $html .= &formatCMCDATA($node);
	} elsif ($node->getTagName() eq 'rcdata') {
	    $html .= &formatCMRCDATA($node);
	} elsif ($node->getTagName() eq 'empty') {
	    $html .= &formatCMEMPTY($node);
	} elsif ($node->getTagName() eq 'any') {
	    $html .= &formatCMANY($node);
	} else {
	    die "Unexpected node: \"" . $node->getTagName() . "\"\n";
	}
	$node = $node->getNextSibling();
    } else {
	die "Unexpected node type.\n";
    }

    return $html;
}

sub formatCMGroup {
    my $group = shift;
    my $occur = $group->getAttribute('occurrence');
    my $sep = shift;
    my $first = 1;
    my $html = "";

    if ($state ne 'NONE' && $state ne 'OPEN') {
	$html .= "\n";
	$html .= " " x $depth if $depth > 0;
	$col = $depth;
	$state = 'NEWLINE';
    }

    $html .= "(";
    $state = 'OPEN';
    $depth++;
    $col++;

    my $node = $group->getFirstChild();
    while ($node) {
	if ($node->getNodeType == XML::DOM::ELEMENT_NODE) {
	    if (!$first) {
		$html .= $sep;
		$col++;

		if ($state ne 'NEWLINE' && ($col > 60)) {
		    $html .= "\n";
		    $html .= " " x $depth if $depth > 0;
		    $col = $depth;
		    $state = 'NEWLINE';
		}
	    }
	    $html .= &formatContentModelElement($node);
	    $first = 0;
	}
	$node = $node->getNextSibling();
    }

    $html .= ")";
    $col++;

    if ($occur) {
	$html .= $occur;

lib/SGML/DTDParse/Format/refentry.pl  view on Meta::CPAN

# ======================================================================

sub formatEntity {
    my $count   = shift;
    my $name    = $entities[$count];
    my $entity  = $entities{$name};
    my $html    = "";
    my $textnl;

    if ($expanded eq 'expanded') {
	$textnl = $entity->getElementsByTagName("text-expanded");
    } else {
	$textnl = $entity->getElementsByTagName("text");
    }

    $html .= &formatEntityHeader($count);

    $html .= &formatEntityTitle($count);

    $html .= &formatEntitySynopsis($count, $textnl)
	if $option{'synopsis'};

    $html .= &formatEntityAppearsIn($count) if $option{'appears-in'};

    $html .= &formatEntityDescription($count) if $option{'description'};

    $html .= &formatEntityExamples($count) if $option{'examples'};

    $html .= &formatEntityFooter($count);

    return $html;
}

sub formatEntityHeader {
    my $count     = shift;
    my $html      = "";
    my $name      = $entities[$count];

    $html .= "<refentry id=\"$baseid.param.$name\">\n";
    $html .= "<!-- Generated by DTDParse version $main::VERSION -->\n";
    $html .= "<!-- see $dtdparseHomepage -->\n\n";

    return $html;
}

sub formatEntityTitle {
    my $count  = shift;
    my $name   = $entities[$count];
    my $entity = $entities{$name};
    my $type   = $entity->getAttribute("type");
    my $html   = "";

    $html .= "<refmeta>\n";
    $html .= "<refentrytitle>";
    $html .= $entity->getAttribute('name');
    $html .= "</refentrytitle>\n";

    if ($type eq 'gen') {
	$html .= "<refmiscinfo>General Entity</refmiscinfo>\n";
    } elsif ($type eq 'ndata'
	     || $type eq 'cdata'
	     || $type eq 'sdata'
	     || $type eq 'pi') {
	$html .= "<refmiscinfo>" . uc($type) . " Entity</refmiscinfo>\n";
    } else {
	$html .= "<refmiscinfo>Parameter Entity</refmiscinfo>\n";
    }

    $html .= "</refmeta>\n\n";

    $html .= "<refnamediv>\n";
    $html .= "<refname>" . $entity->getAttribute('name') . "</refname>\n";
    $html .= "<refpurpose>";
    $html .= &entityRefpurpose($count);
    $html .= "</refpurpose>\n";
    $html .= "</refnamediv>\n\n";
}

sub formatEntitySynopsis {
    my $count   = shift;
    my $textnl  = shift;
    my $name    = $entities[$count];
    my $entity  = $entities{$name};
    my $html    = "";
    my $type    = $entity->getAttribute("type");
    my $public  = entify($entity->getAttribute("public"));
    my $system  = entify($entity->getAttribute("system"));
    my $text    = "";

    if ($textnl->getLength() > 0) {
	my $textnode = $textnl->item(0);
	my $content = $textnode->getFirstChild();
	if ($content) {
	    $text = $content->getData();
	} else {
	    $text = "";
	}
    }

    $html .= "<refsynopsisdiv>\n";
    $html .= "<informaltable frame='all' role='elemsynop'>\n";
    $html .= "<tgroup cols='3'>\n";
    $html .= "<colspec colnum='1' colname='c1'/>\n";
    $html .= "<colspec colnum='2' colname='c2'/>\n";
    $html .= "<colspec colnum='3' colname='c3'/>\n";
    $html .= "<tbody>\n";

    $html .= "<row rowsep='0' role='cmtitle'>\n";
    $html .= "<entry namest='c1' nameend='c3' align='left'\n";
    $html .= "><emphasis role='bold'>";

    if ($type eq 'gen') {
	if ($public || $system) {
	    $html .= "External General Entity";
	    $html .= "</emphasis></entry>\n";
	    $html .= "</row>\n";
	    $html .= "<row rowsep='1' role='cmsynop'>\n";
	    $html .= "<entry namest='c1' nameend='c3' align='left'\n";
	    $html .= ">";

	    $html .= "<para><emphasis role='bold'>Public identifier</emphasis>: $public\n</para>" if $public;

lib/SGML/DTDParse/Format/refentry.pl  view on Meta::CPAN

	    $html .= "<entry namest='c1' nameend='c3' align='left'\n";
	    $html .= ">";

	    $html .= "<para><emphasis role='bold'>Public identifier</emphasis>: $public\n</para>" if $public;
	    $html .= "<para><emphasis role='bold'>System identifier</emphasis>: $system\n</para>" if $system;

	    $html .= "</entry>\n";
	    $html .= "</row>\n";
	} else {
	    $html .= "Parameter Entity\n";
	    $html .= "</emphasis></entry>\n";
	    $html .= "</row>\n";
	    $html .= "<row rowsep='1' role='cmsynop'>\n";
	    $html .= "<entry namest='c1' nameend='c3' align='left'\n";
	    $html .= "><synopsis>";

	    # OK, it's a parameter entity. Now, does it look like a
	    # content model fragment

	    my $cmfragment = &cmFragment($text);

	    while ($text =~ /\%?[-a-z0-9.:_]+;?/is) {
		my $pre = $`;
		my $match = $&;
		$text = $';

		$html .= $pre;

		if ($pre =~ /\#$/) {
		    # if it comes after a '#', it's a keyword...
		    $html .= $match;
		    next;
		}

		if ($match =~ /\%([^;]+);?/) {
		    $name = $1;
		    if (exists $entities{$name}) {
			$html .= $match;
		    } else {
			$html .= $match;
		    }
		} elsif ($cmfragment) {
		    $name = $match;
		    $name = lc($name) if !$option{'case-sensitive'};
		    if (exists $elements{$name}) {
			my $linkend = "$baseid.elem.$name";
			$html .= "<link linkend=\"$linkend\">$match</link>";
		    } else {
			$html .= $match;
		    }
		} else {
		    $html .= $match;
		}
	    }
	    $html .= $text;
	    $html .= "</synopsis></entry>\n";
	    $html .= "</row>\n";
	}
    }

    if ($type eq 'ndata' || $type eq 'cdata') {
	my $notation = $entity->getAttribute('notation');

	$html .= uc($type) . " Entity";
	$html .= "</emphasis></entry>\n";
	$html .= "</row>\n";
	$html .= "<row rowsep='1' role='cmsynop'>\n";
	$html .= "<entry namest='c1' nameend='c3' align='left'\n";
	$html .= ">";

	$html .= "<para><emphasis role='bold'>Notation</emphasis>: $notation\n</para>";
	$html .= "<para><emphasis role='bold'>Public identifier</emphasis>: $public\n</para>" if $public;
	$html .= "<para><emphasis role='bold'>System identifier</emphasis>: $system\n</para>" if $system;

	$html .= "</entry>\n";
	$html .= "</row>\n";
    }

    if ($type eq 'sdata' || $type eq 'pi') {
	$html .= uc($type) . " Entity";
	$html .= "</emphasis></entry>\n";
	$html .= "</row>\n";
	$html .= "<row rowsep='1' role='cmsynop'>\n";
	$html .= "<entry namest='c1' nameend='c3' align='left'\n";
	$html .= "><synopsis>";

	if ($text =~ /\"/) {
	    $html .= "'$text'\n";
	} else {
	    $html .= "\"$text\"\n";
	}

	$html .= "</synopsis></entry>\n";
	$html .= "</row>\n";
    }

    $html .= "</tbody>\n";
    $html .= "</tgroup>\n";
    $html .= "</informaltable>\n";
    $html .= "</refsynopsisdiv>\n\n";

    return $html;
}

sub formatEntityAppearsIn {
    my $count = shift;
    my $html = "";
    my $entityname = $entities[$count];
    my $entity = $entities{$entityname};
    my %appears = ();
    my $key = "%$entityname";

    %appears = %{$APPEARSIN{$key}} if exists $APPEARSIN{$key};

    if (%appears) {
	my @ents = sort { uc($a) cmp uc($b) } keys %appears;

	$html .= "<refsect1><title>Parameter Entities</title>\n";
	$html .= "<para>The following parameter entities contain ";
	$html .= $entity->getAttribute('name') . ":\n";
	$html .= "<simplelist type='inline'>\n";



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