summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-03-22 15:28:22 (GMT)
committerDavid A. Madore <david+git@madore.org>2010-03-22 15:28:22 (GMT)
commitc29589777c52771bed4cbbb43ba140feb71ca568 (patch)
tree5ed820920fcee1680c5008c171a76dfce86ecbf5
parentcbeedb93f339e7da62251dd66cb54acf5b76fa81 (diff)
downloadblogengine-c29589777c52771bed4cbbb43ba140feb71ca568.zip
blogengine-c29589777c52771bed4cbbb43ba140feb71ca568.tar.gz
blogengine-c29589777c52771bed4cbbb43ba140feb71ca568.tar.bz2
***Broken*** (work in progress), but need to push now.
This does not compile, let alone work, but I need to push to continue working elsewhere.
-rwxr-xr-xdaml2html.pl79
1 files changed, 47 insertions, 32 deletions
diff --git a/daml2html.pl b/daml2html.pl
index 3ec1db6..d1d0c51 100755
--- a/daml2html.pl
+++ b/daml2html.pl
@@ -83,16 +83,20 @@ $parser->input_callbacks($input_callbacks);
# Avoid accessing the W3C web site all the time.
$parser->load_catalog("/etc/xml/catalog");
-my $in_doc;
+my $doc;
if ( defined($ARGV[0]) ) {
- $in_doc = $parser->parse_file($ARGV[0]);
+ $doc = $parser->parse_file($ARGV[0]);
} else {
- $in_doc = $parser->parse_fh(\*STDIN);
+ $doc = $parser->parse_fh(\*STDIN);
}
-die "Root element should be daml"
- unless ( $in_doc->documentElement->namespaceURI eq DAML_NS
- && $in_doc->documentElement->localname eq "daml" );
+my $doc_is_daml = ( $doc->documentElement->namespaceURI eq DAML_NS
+ && $doc->documentElement->localname eq "daml" );
+my $doc_is_html = ( $doc->documentElement->namespaceURI eq XHTML_NS
+ && $doc->documentElement->localname eq "html" );
+
+die "Root element should be d:daml or html"
+ unless ( $doc_is_daml || $doc_is_html );
my $xpc = XML::LibXML::XPathContext->new($in_doc);
$xpc->registerNs('h', XHTML_NS);
@@ -122,39 +126,50 @@ sub set_rec_lang {
}
}
-my $uri_to_top = $in_doc->documentElement->getAttributeNS("", "uri-to-top") // "";
-my $file_name = $in_doc->documentElement->getAttributeNS("", "file.name");
-if ( ! defined($file_name) ) {
- print STDERR "Warning: file.name unspecified!\n";
-}
my $top_lang = rec_lang($in_doc->documentElement);
-
-my $in_body = ($xpc->findnodes("/d:daml/d:body"))[0];
-my $body_lang = rec_lang($in_body) // $top_lang;
+my $body_lang = $top_lang;
+my $uri_to_top;
+my $file_name;
my $out_doc = XML::LibXML::Document->new("1.0","utf-8");
my $out_dtd = $out_doc->createInternalSubset("html", XHTML_PUBID, XHTML_URI);
-my $out_html = $out_doc->createElementNS(XHTML_NS, "html");
+my $out_html = $out_doc->createElementNS(XHTML_NS, "html");;
+my $out_head;
+my $out_body;
+
+if ( $in_doc_is_daml ) {
+ $uri_to_top = $in_doc->documentElement->getAttributeNS("", "uri-to-top")
+ // "";
+ $file_name = $in_doc->documentElement->getAttributeNS("", "file.name");
+ set_rec_lang($out_html, $top_lang) if defined($top_lang);
+ my $in_body = ($xpc->findnodes("/d:daml/d:body"))[0];
+ $body_lang = rec_lang($in_body) // $top_lang;
+ $out_html->appendChild($out_doc->createTextNode("\n"));
+ $out_html->appendChild($out_doc->createComment(" This file is automatically generated. Do not edit! "));
+ $out_html->appendChild($out_doc->createTextNode("\n"));
+ $out_head = $out_doc->createElementNS(XHTML_NS, "head");
+ $out_html->appendChild($out_head);
+ $out_head->appendChild($out_doc->createTextNode("\n"));
+ my $out_title = $out_doc->createElementNS(XHTML_NS, "title");
+ $out_head->appendChild($out_title);
+ $out_head->appendChild($out_doc->createTextNode("\n"));
+ $out_html->appendChild($out_doc->createTextNode("\n"));
+ my $out_body = $out_doc->createElementNS(XHTML_NS, "body");
+ $out_html->appendChild($out_body);
+ $out_body->setAttributeNS("","onload","onLoad()");
+ set_rec_lang($out_body, $body_lang);
+ $out_body->appendChild($out_doc->createTextNode("\n"));
+ $out_html->appendChild($out_doc->createTextNode("\n"));
+} elsif ( $in_doc_is_html ) {
+ my $in_body = ($xpc->findnodes("/h:html/h:body"))[0];
+ $body_lang = rec_lang($in_body) // $top_lang;
+}
+
+my $out_doc
+my
$out_doc->setDocumentElement($out_html);
if ( defined($top_lang) ) {
- set_rec_lang($out_html, $top_lang);
}
-$out_html->appendChild($out_doc->createTextNode("\n"));
-$out_html->appendChild($out_doc->createComment(" This file is automatically generated. Do not edit! "));
-$out_html->appendChild($out_doc->createTextNode("\n"));
-my $out_head = $out_doc->createElementNS(XHTML_NS, "head");
-$out_html->appendChild($out_head);
-$out_head->appendChild($out_doc->createTextNode("\n"));
-my $out_title = $out_doc->createElementNS(XHTML_NS, "title");
-$out_head->appendChild($out_title);
-$out_head->appendChild($out_doc->createTextNode("\n"));
-$out_html->appendChild($out_doc->createTextNode("\n"));
-my $out_body = $out_doc->createElementNS(XHTML_NS, "body");
-$out_html->appendChild($out_body);
-$out_body->setAttributeNS("","onload","onLoad()");
-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("/d:daml/d:title"))[0];
if ( defined($in_title) ) {