summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-03-08 20:11:30 (GMT)
committerDavid A. Madore <david+git@madore.org>2010-03-08 20:11:30 (GMT)
commitd2e31598c8663f03dd571b53f4cf2e510f1d259b (patch)
tree21c80a5cda68b1870c0ce247daddaed1ff2c278f
parent7bb3aa43584e0ebd397ca08bfbcd5e14bcdc22f4 (diff)
downloadblogengine-d2e31598c8663f03dd571b53f4cf2e510f1d259b.zip
blogengine-d2e31598c8663f03dd571b53f4cf2e510f1d259b.tar.gz
blogengine-d2e31598c8663f03dd571b53f4cf2e510f1d259b.tar.bz2
Continue writing daml2html converter: handle some meta, copy body stupidly...
-rwxr-xr-xdaml2html.pl44
1 files changed, 41 insertions, 3 deletions
diff --git a/daml2html.pl b/daml2html.pl
index 2bce970..bd23f32 100755
--- a/daml2html.pl
+++ b/daml2html.pl
@@ -87,6 +87,9 @@ if ( defined($ARGV[0]) ) {
$in_doc = $parser->parse_fh(\*STDIN);
}
+die "Root element should be daml"
+ unless $in_doc->documentElement->localname eq "daml";
+
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");
@@ -106,29 +109,64 @@ $out_html->appendChild($out_body);
$out_body->appendChild($out_doc->createTextNode("\n"));
$out_html->appendChild($out_doc->createTextNode("\n"));
+my $top_lang = $in_doc->documentElement->getAttributeNS(XML_XML_NS, "lang");
+if ( defined($top_lang) ) {
+ $out_html->setAttributeNS(XML_XML_NS, "lang", $top_lang);
+}
+
my $xpc = XML::LibXML::XPathContext->new($in_doc);
#$xpc->registerNs('h', XHTML_NS);
my $in_title = ($xpc->findnodes("/daml/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");
+ $out_meta_title->setAttributeNS("", "name", "Title");
+ $out_meta_title->setAttributeNS("", "content", $in_title->textContent);
+ $out_head->appendChild($out_meta_title);
+ $out_head->appendChild($out_doc->createTextNode("\n"));
my $out_h1 = $out_doc->createElementNS(XHTML_NS, "h1");
$out_h1->setAttributeNS("", "class", "title");
$out_body->appendChild($out_h1);
$out_body->appendChild($out_doc->createTextNode("\n"));
- foreach my $child ( $out_title->childNodes ) {
+ foreach my $child ( $in_title->childNodes ) {
$out_h1->appendChild($out_doc->importNode($child,1));
}
}
my $in_subtitle = ($xpc->findnodes("/daml/subtitle"))[0];
-if ( defined($in_title) ) {
+if ( defined($in_subtitle) ) {
my $out_p = $out_doc->createElementNS(XHTML_NS, "p");
$out_p->setAttributeNS("", "class", "subtitle");
$out_body->appendChild($out_p);
$out_body->appendChild($out_doc->createTextNode("\n"));
- foreach my $child ( $out_title->childNodes ) {
+ foreach my $child ( $in_subtitle->childNodes ) {
$out_p->appendChild($out_doc->importNode($child,1));
}
}
+my $in_meta_description = ($xpc->findnodes("/daml/meta-description"))[0];
+if ( defined($in_meta_description) ) {
+ my $out_meta_description = $out_doc->createElementNS(XHTML_NS, "meta");
+ $out_meta_description->setAttributeNS("", "name", "Description");
+ $out_meta_description->setAttributeNS("", "content",
+ $in_meta_description->textContent);
+ $out_head->appendChild($out_meta_description);
+ $out_head->appendChild($out_doc->createTextNode("\n"));
+}
+my $in_meta_keywords = ($xpc->findnodes("/daml/meta-keywords"))[0];
+if ( defined($in_meta_keywords) ) {
+ my $out_meta_keywords = $out_doc->createElementNS(XHTML_NS, "meta");
+ $out_meta_keywords->setAttributeNS("", "name", "Keywords");
+ $out_meta_keywords->setAttributeNS("", "content",
+ $in_meta_keywords->textContent);
+ $out_head->appendChild($out_meta_keywords);
+ $out_head->appendChild($out_doc->createTextNode("\n"));
+}
+my $in_body = ($xpc->findnodes("/daml/body"))[0];
+if ( defined($in_body) ) {
+ foreach my $child ( $in_body->childNodes ) {
+ $out_doc->adoptNode($child);
+ $out_body->appendChild($child);
+ }
+}
# sub map_children {
# my $fun = shift;