summaryrefslogtreecommitdiffstats
path: root/daml2html.pl
diff options
context:
space:
mode:
Diffstat (limited to 'daml2html.pl')
-rwxr-xr-xdaml2html.pl23
1 files changed, 13 insertions, 10 deletions
diff --git a/daml2html.pl b/daml2html.pl
index eb43e64..3ec1db6 100755
--- a/daml2html.pl
+++ b/daml2html.pl
@@ -21,6 +21,7 @@ use constant {
XHTML_PUBID => "-//W3C//DTD XHTML 1.0 Strict//EN",
XHTML_URI => "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd",
XHTML_NS => "http://www.w3.org/1999/xhtml",
+ DAML_NS => "http://www.madore.org/~david/NS/daml/",
};
my %opts;
@@ -90,10 +91,12 @@ if ( defined($ARGV[0]) ) {
}
die "Root element should be daml"
- unless $in_doc->documentElement->localname eq "daml";
+ unless ( $in_doc->documentElement->namespaceURI eq DAML_NS
+ && $in_doc->documentElement->localname eq "daml" );
my $xpc = XML::LibXML::XPathContext->new($in_doc);
-#$xpc->registerNs('h', XHTML_NS);
+$xpc->registerNs('h', XHTML_NS);
+$xpc->registerNs('d', DAML_NS);
sub rec_lang {
my $node = shift;
@@ -126,7 +129,7 @@ if ( ! defined($file_name) ) {
}
my $top_lang = rec_lang($in_doc->documentElement);
-my $in_body = ($xpc->findnodes("/daml/body"))[0];
+my $in_body = ($xpc->findnodes("/d:daml/d:body"))[0];
my $body_lang = rec_lang($in_body) // $top_lang;
my $out_doc = XML::LibXML::Document->new("1.0","utf-8");
@@ -153,7 +156,7 @@ set_rec_lang($out_body, $body_lang);
$out_body->appendChild($out_doc->createTextNode("\n"));
$out_html->appendChild($out_doc->createTextNode("\n"));
-my $in_title = ($xpc->findnodes("/daml/title"))[0];
+my $in_title = ($xpc->findnodes("/d:daml/d:title"))[0];
if ( defined($in_title) ) {
$out_title->appendChild($out_doc->createTextNode($in_title->textContent));
my $out_meta_title = $out_doc->createElementNS(XHTML_NS, "meta");
@@ -171,7 +174,7 @@ if ( defined($in_title) ) {
$out_h1->appendChild($out_doc->importNode($child,1));
}
}
-my $in_subtitle = ($xpc->findnodes("/daml/subtitle"))[0];
+my $in_subtitle = ($xpc->findnodes("/d:daml/d:subtitle"))[0];
if ( defined($in_subtitle) ) {
my $out_p = $out_doc->createElementNS(XHTML_NS, "p");
$out_p->setAttributeNS("", "class", "subtitle");
@@ -182,7 +185,7 @@ if ( defined($in_subtitle) ) {
$out_p->appendChild($out_doc->importNode($child,1));
}
}
-my $in_meta_description = ($xpc->findnodes("/daml/meta-description"))[0];
+my $in_meta_description = ($xpc->findnodes("/d:daml/d:meta-description"))[0];
if ( defined($in_meta_description) ) {
my $out_meta_description = $out_doc->createElementNS(XHTML_NS, "meta");
$out_meta_description->setAttributeNS("", "name", "Description");
@@ -226,7 +229,7 @@ if ( defined($body_lang) && $body_lang ne "und" ) {
$out_head->appendChild($out_doc->createTextNode("\n"));
}
-my @in_translations = $xpc->findnodes("/daml/translation");
+my @in_translations = $xpc->findnodes("/d:daml/d:translation");
foreach my $in_translation ( @in_translations ) {
my $lang = $in_translation->getAttributeNS(XML_XML_NS, "lang");
die "xml:lang attribute missing on <translation>" unless defined($lang);
@@ -244,7 +247,7 @@ foreach my $in_translation ( @in_translations ) {
$out_head->appendChild($out_doc->createTextNode("\n"));
}
-my @in_metastuff = $xpc->findnodes("/daml/*[self::meta or self::link]");
+my @in_metastuff = $xpc->findnodes("/d:daml/*[self::h:meta or self::h:link]");
foreach my $in_mnode ( @in_metastuff ) {
$out_head->appendChild($out_doc->importNode($in_mnode,1));
$out_head->appendChild($out_doc->createTextNode("\n"));
@@ -347,7 +350,7 @@ if ( defined($in_body) ) {
$out_body->appendChild($out_doc->createTextNode("\n"));
}
-my $in_last_modified = ($xpc->findnodes("/daml/last-modified"))[0];
+my $in_last_modified = ($xpc->findnodes("/d:daml/d:last-modified"))[0];
if ( defined($in_last_modified) ) {
my $out_last_modified = $out_doc->createElementNS(XHTML_NS, "p");
$out_last_modified->setAttributeNS("", "class", "last-modified");
@@ -377,7 +380,7 @@ if ( open my $common_script_file, "<", "included.js" ) {
close $common_script_file;
}
-my @in_extra_style = $xpc->findnodes("/daml/extra-style");
+my @in_extra_style = $xpc->findnodes("/d:daml/d:extra-style");
foreach my $in_extra_style ( @in_extra_style ) {
$pure_style_content .= $in_extra_style->textContent;
}