summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-04-06 05:15:52 (GMT)
committerDavid A. Madore <david+git@madore.org>2010-04-06 05:15:52 (GMT)
commitf7010f673ef32f8b76ca2d4029e60133b693050b (patch)
treee947491deefd6a11e2e41c89bf4f47e8019f0bc0
parentcc7a5fb4a33deb036aacd44a95288149bb429781 (diff)
downloadblogengine-f7010f673ef32f8b76ca2d4029e60133b693050b.zip
blogengine-f7010f673ef32f8b76ca2d4029e60133b693050b.tar.gz
blogengine-f7010f673ef32f8b76ca2d4029e60133b693050b.tar.bz2
Introduce some kind of attribute handing.
But we encounter a bug/limitation in XML::LibXML, which does not remove namespace declarations which have become useless.
-rwxr-xr-xdaml2html.pl52
1 files changed, 46 insertions, 6 deletions
diff --git a/daml2html.pl b/daml2html.pl
index 74876f7..9baf97c 100755
--- a/daml2html.pl
+++ b/daml2html.pl
@@ -199,11 +199,22 @@ if ( open my $common_script_file, "<", "included.js" ) {
close $common_script_file;
}
+sub default_handler_attributes {
+ my $node = shift;
+ my $ctxref = shift;
+ my $optref = shift;
+ foreach my $attr ( $node->attributes ) {
+ if ( $attr->nodeType == XML_ATTRIBUTE_NODE
+ && defined($attr->namespaceURI) ) {
+ push @todo_stack, ["attr", $attr, $ctxref, {}, $node];
+ }
+ }
+}
+
sub default_handler_nodeonly {
my $node = shift;
my $ctxref = shift;
my $optref = shift;
- print STDERR "warning: default handler doesn't handle arguments\n" if @_;
# return unless $node->nodeType == XML_ELEMENT_NODE;
my @child_nodes = $node->childNodes;
my @to_process;
@@ -218,7 +229,9 @@ sub default_handler {
my $node = shift;
my $ctxref = shift;
my $optref = shift;
- default_handler_nodeonly $node, $optref;
+ print STDERR "warning: default handler doesn't handle arguments\n" if @_;
+ default_handler_attributes $node, $ctxref, $optref;
+ default_handler_nodeonly $node, $ctxref, $optref;
}
sub do_title_or_subtitle_handler {
@@ -949,6 +962,19 @@ sub do_comments_handler {
$span->appendChild($doc->createComment(" EMPTY "));
}
+sub wref_attr_handler {
+ my $attr = shift;
+ my $ctxref = shift;
+ my $optref = shift;
+ my $pnode = shift;
+ die "wref attribute makes sense only on an a element"
+ unless $pnode->namespaceURI eq XHTML_NS && $pnode->localName eq "a";
+ my $tgt = $attr->nodeValue;
+ $attr->unbindNode;
+ $pnode->setAttributeNS("", "href", $tgt);
+ decontaminate_node $pnode;
+}
+
my %daml_handler = (
"daml" => \&daml_handler,
"body" => \&body_handler,
@@ -976,10 +1002,14 @@ my %daml_handler = (
"date-extra" => \&date_extra_handler,
);
+my %daml_attr_handler = (
+ "wref" => \&wref_attr_handler,
+ );
+
TODO_LOOP:
while ( my $process = shift @todo_stack ) {
my $call_this = shift @$process;
- if ( defined($call_this) ) {
+ if ( ref($call_this) eq "CODE" ) {
&$call_this(@$process);
next TODO_LOOP;
}
@@ -988,10 +1018,20 @@ while ( my $process = shift @todo_stack ) {
printf STDERR "warning: skipping %s node with missing namespace\n", $node->nodeName;
next TODO_LOOP;
}
- if ( $node->namespaceURI eq DAML_NS && defined($daml_handler{$node->localName}) ) {
- &{$daml_handler{$node->localName}}(@$process);
+ if ( defined($call_this) && $call_this eq "attr" ) {
+ if ( $node->namespaceURI eq DAML_NS
+ && defined($daml_attr_handler{$node->localName}) ) {
+ &{$daml_attr_handler{$node->localName}}(@$process);
+ } else {
+ # Just leave it alone...
+ }
} else {
- default_handler(@$process);
+ if ( $node->namespaceURI eq DAML_NS
+ && defined($daml_handler{$node->localName}) ) {
+ &{$daml_handler{$node->localName}}(@$process);
+ } else {
+ default_handler(@$process);
+ }
}
}