SGML-DTDParse

 view release on metacpan or  search on metacpan

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

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

    return "";
}

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

    $html .= "<P></P>\n";
    $html .= "<HR>\n";
    $html .= "HTML Presentation of ";
    $html .= $dtd->getDocumentElement()->getAttribute('title');
    $html .= " by <A HREF=\"$dtdparseHomepage\">";
    $html .= "DTDParse</A> (version $main::VERSION).\n";
    $html .= "</BODY>\n";
    $html .= "</HTML>\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 = "";

    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/html.pl  view on Meta::CPAN

	    $html .= "<P><B>System identifier</B>: $system</P>\n" if $system;
	} else {
	    $html .= "<H3>Parameter Entity</H3>\n";
	    $html .= "<PRE>";

	    # 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}) {
			my $href = $ENTBASE{$name} . $fileext;
			$html .= "<A HREF=\"$href\">$match</A>";
		    } else { 
			$html .= $match;
		    }
		} elsif ($cmfragment) {
		    $name = $match;
		    $name = lc($name) if !$option{'namecase-general'};
		    if (exists $elements{$name}) {
			my $href = $ELEMBASE{$name} . $fileext;
			my $dir = $config{$expanded . "-element-dir"};
			$html .= "<A HREF=\"../$dir/$href\">$match</A>";
		    } else {
			$html .= $match;
		    }
		} else {
		    $html .= $match;
		}
	    }
	    $html .= $text;
	    $html .= "</PRE>\n";
	}
    }

    if ($type eq 'sdata' || $type eq 'pi') {
	$html .= "<H3>" . uc($type) . " Entity</H3>\n";
	$text =~ s/\&/\&amp;/sg;
	if ($text =~ /\"/) {
	    $html .= "<P>'$text'</P>\n";
	} else {
	    $html .= "<P>\"$text\"</P>\n";
	}
    }

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

	$html .= "<H3>" . uc($type) . " Entity</H3>\n";
	$html .= "<P><B>Notation</B>: $notation</P>\n";
	$html .= "<P><B>Public identifier</B>: $public</P>\n" if $public;
	$html .= "<P><B>System identifier</B>: $system</P>\n" if $system;
    }

    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 .= "<H3>Parameter Entities</H3>\n";
	$html .= "<P>The following parameter entities contain ";
	$html .= $entity->getAttribute('name') . ":\n";

	my $first = 1;
	for (my $count = 0; $count <= $#ents; $count++) {
	    my $entity = $entities{$ents[$count]};
	    my $basename = $ENTBASE{$ents[$count]} . $fileext;
	    $html .= ",\n" if !$first;
	    $first = 0;
	    $html .= "<A HREF=\"$basename\">";
	    $html .= $entity->getAttribute('name');
	    $html .= "</A>";
	}

	$html .= "</P>";
    }

    return $html;
}

sub formatEntityDescription {
    my $count   = shift;
    my $name    = $entities[$count];
    my $entity  = $entities{$name};

    return "";
}

sub formatEntityExamples {
    my $count   = shift;
    my $name    = $entities[$count];
    my $entity  = $entities{$name};

    return "";
}



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