summaryrefslogtreecommitdiffstats
path: root/daml2html.pl
diff options
context:
space:
mode:
Diffstat (limited to 'daml2html.pl')
-rwxr-xr-xdaml2html.pl138
1 files changed, 128 insertions, 10 deletions
diff --git a/daml2html.pl b/daml2html.pl
index 58196fd..ec4c139 100755
--- a/daml2html.pl
+++ b/daml2html.pl
@@ -222,7 +222,7 @@ sub do_title_or_subtitle_handler {
unless defined($type) && ($type eq "title" || $type eq "subtitle");
my $src_t = shift or die "missing src_t argument";
my $src_t_lang = shift;
- if ( $src_t_lang ) {
+ if ( defined($src_t_lang) ) {
printf STDERR ("warning: ignoring xml:lang attribute on %s node\n",
$src_t->nodeName)
if get_node_lang_norec $node;
@@ -231,7 +231,7 @@ sub do_title_or_subtitle_handler {
my $new_t_node = $doc->createElementNS(XHTML_NS,
($type eq "title" ? "h1" : "p"));
$new_t_node->setAttributeNS("", "class", $type);
- if ( my $lang = get_node_lang_norec $node ) {
+ if ( defined(my $lang = get_node_lang_norec $node) ) {
set_node_lang_norec $new_t_node, $lang;
}
$node->replaceNode($new_t_node);
@@ -263,6 +263,7 @@ sub do_translations_handler {
foreach my $lang ( @translations ) {
my $p = $doc->createElementNS(XHTML_NS, "p");
set_node_lang_norec $p, $lang;
+ $p->setAttributeNS("", "class", "translation-offer");
$parent->insertBefore($p, $node);
$parent->insertBefore($doc->createTextNode("\n"), $node);
my $str = "[";
@@ -274,8 +275,8 @@ sub do_translations_handler {
$p->appendChild($doc->createTextNode($str));
my $a = $doc->createElementNS(XHTML_NS, "a");
$p->appendChild($a);
- $a->setAttributeNS("", "hreflang", $lang);
$a->setAttributeNS("", "href", ($file_name//"").".".$lang);
+ $a->setAttributeNS("", "hreflang", $lang);
$str = $lang;
if ( $lang eq "en" ) {
$str = "English version";
@@ -287,7 +288,7 @@ sub do_translations_handler {
if ( $lang eq "en" ) {
$str = " of this page is also available.]";
} elsif ( $lang eq "fr" ) {
- $str = " de cette page est également diponible.]";
+ $str = " de cette page est également disponible.]";
}
$p->appendChild($doc->createTextNode($str));
}
@@ -340,6 +341,41 @@ sub do_navbar_handler {
$a->setAttributeNS("", "href", ($uri_to_top//"")."weblog/");
$p->appendChild($a);
$a->appendChild($doc->createTextNode("WebLog"));
+ unshift @todo_stack, [undef, $p, {}];
+}
+
+sub do_footer_handler {
+ my $node = shift;
+ my $optref = shift;
+ print STDERR "warning: do-footer handler doesn't handle arguments\n" if @_;
+ my $parent = $node->parentNode;
+ my $hr = $doc->createElementNS(XHTML_NS, "hr");
+ $hr->setAttributeNS("", "class", "cleared");
+ $parent->insertBefore($hr, $node);
+ $parent->insertBefore($doc->createTextNode("\n"), $node);
+ my $address = $doc->createElementNS(XHTML_NS, "address");
+ $parent->insertBefore($address, $node);
+ $parent->insertBefore($doc->createTextNode("\n"), $node);
+ my $a = $doc->createElementNS(XHTML_NS, "a");
+ $a->setAttributeNS("", "href", $uri_to_top//"http://www.madore.org/~david/");
+ $address->appendChild($a);
+ $a->appendChild($doc->createTextNode("David Madore"));
+ $address->appendChild($doc->createTextNode(" ("));
+ my $email = $doc->createElementNS(DAML_NS, "d:email-despammed");
+ $address->appendChild($email);
+ $address->appendChild($doc->createTextNode(")"));
+ $email->appendChild($doc->createTextNode("david+www"));
+ $email->appendChild($doc->createElementNS(DAML_NS, "d:email-at"));
+ $email->appendChild($doc->createTextNode("madore"));
+ $email->appendChild($doc->createElementNS(DAML_NS, "d:email-dot"));
+ $email->appendChild($doc->createTextNode("org"));
+ if ( ($node->nextSibling)->nodeType == XML_TEXT_NODE
+ && ($node->nextSibling)->data =~ m/^\s*$/s ) {
+ $node->nextSibling->unbindNode;
+ }
+ $node->unbindNode;
+ unshift @todo_stack, [undef, $hr, {}]; # Pretty useless...
+ unshift @todo_stack, [undef, $address, {}];
}
sub create_meta_element_helper {
@@ -352,7 +388,7 @@ sub create_meta_element_helper {
if ( defined($src_node) && !defined($lang) ) {
$lang = get_node_lang_norec $src_node;
}
- if ( $lang ) {
+ if ( defined($lang) ) {
set_node_lang_norec $meta, $lang;
}
$meta->setAttributeNS("", $name_or_http_equiv, $meta_name);
@@ -403,7 +439,7 @@ sub daml_handler {
die "\$html_node already defined: what magic is this?" if defined($html_node);
$html_node = $doc->createElementNS(XHTML_NS, "html");
my $lang;
- if ( $lang = get_node_lang_norec $node ) {
+ if ( defined($lang = get_node_lang_norec $node) ) {
set_node_lang_norec $html_node, $lang;
}
$doc->setDocumentElement($html_node);
@@ -455,7 +491,7 @@ sub body_handler {
my $optref = shift;
print STDERR "warning: body handler doesn't handle arguments\n" if @_;
my $body_node = $doc->createElementNS(XHTML_NS, "body");
- if ( my $lang = get_node_lang_norec $node ) {
+ if ( defined(my $lang = get_node_lang_norec $node) ) {
set_node_lang_norec $body_node, $lang;
}
$body_node->setAttributeNS("", "onload", "onLoad()");
@@ -507,7 +543,7 @@ sub body_handler {
my $token = $doc->createElementNS(DAML_NS, "d:implicit-do-footer");
$body_node->appendChild($token);
$body_node->appendChild($doc->createTextNode("\n"));
-# unshift @to_process, [\&do_footer_handler, $token, {implicit=>1}];
+ unshift @to_process, [\&do_footer_handler, $token, {implicit=>1}];
}
unshift @todo_stack, @to_process;
}
@@ -525,7 +561,7 @@ sub title_handler {
$src_title->appendChild($child);
}
my $title_node = $doc->createElementNS(XHTML_NS, "title");
- if ( $src_title_explicit_lang ) {
+ if ( defined($src_title_explicit_lang) ) {
# Note here this is with norec, earlier with rec...
set_node_lang_norec $title_node, $src_title_explicit_lang;
}
@@ -595,6 +631,85 @@ sub extra_style_handler {
$node->unbindNode;
}
+sub email_at_or_dot_handler {
+ my $node = shift;
+ my $optref = shift;
+ my $type = shift;
+ die "email_at_or_dot_handler called with type other than \"at\" or \"dot\""
+ unless defined($type) && ($type eq "at" || $type eq "dot");
+ die "email-$type can only be a child of email-despammed"
+ unless $$optref{is_email_despammed_child};
+ my ($char_name, $img_name, $en_name, $fr_name);
+ if ( $type eq "at" ) {
+ $char_name = "commercial-at";
+ $img_name = "commercial_at.png";
+ $en_name = "at sign";
+ $fr_name = "arobase";
+ } else {
+ $char_name = "full-stop";
+ $img_name = "full_stop.png";
+ $en_name = "dot";
+ $fr_name = "point";
+ }
+ my $span0 = $doc->createElementNS(XHTML_NS, "span");
+ my $lang = get_node_lang_rec $node;
+ my $explicit_lang = get_node_lang_norec $node;
+ unless ( defined($lang) && ( $lang eq "en" || $lang eq "fr" ) ) {
+ $lang = "en";
+ $explicit_lang = "en";
+ }
+ if ( defined($explicit_lang) ) {
+ set_node_lang_norec $span0, $explicit_lang;
+ }
+ $span0->setAttributeNS("", "class", "replace-$char_name");
+ $node->replaceNode($span0);
+ my $span1 = $doc->createElementNS(XHTML_NS, "span");
+ $span1->setAttributeNS("", "class", "subreplace-$char_name");
+ $span0->appendChild($span1);
+ my $img = $doc->createElementNS(XHTML_NS, "img");
+ $img->setAttributeNS("", "src", ($uri_to_top//"")."images/".$img_name);
+ $img->setAttributeNS("", "alt", "[".($lang eq "fr" ? $fr_name : $en_name)."]");
+ $img->setAttributeNS("", "height", "15");
+ $img->setAttributeNS("", "width", "16");
+ $span1->appendChild($img);
+}
+
+sub email_at_handler {
+ my $node = shift;
+ my $optref = shift;
+ print STDERR "warning: email-at handler doesn't handle arguments\n" if @_;
+ email_at_or_dot_handler $node, $optref, "at";
+}
+
+sub email_dot_handler {
+ my $node = shift;
+ my $optref = shift;
+ print STDERR "warning: email-dot handler doesn't handle arguments\n" if @_;
+ email_at_or_dot_handler $node, $optref, "dot";
+}
+
+sub email_despammed_handler {
+ my $node = shift;
+ my $optref = shift;
+ print STDERR "warning: email-despammed handler doesn't handle arguments\n" if @_;
+ my $out0 = $doc->createElementNS(XHTML_NS, "code");
+ if ( defined(my $lang = get_node_lang_norec $node) ) {
+ set_node_lang_norec $out0, $lang;
+ }
+ $node->replaceNode($out0);
+ my $out1 = $doc->createElementNS(XHTML_NS, "a");
+ $out1->setAttributeNS("", "class", "despammed-address");
+ $out0->appendChild($out1);
+ my @child_nodes = $node->childNodes;
+ my @to_process;
+ foreach my $child ( @child_nodes ) {
+ $out1->appendChild($child);
+ push @to_process, [undef, $child, {is_email_despammed_child=>1}]
+ if $child->nodeType == XML_ELEMENT_NODE;
+ }
+ unshift @todo_stack, @to_process;
+}
+
my %daml_handler = (
"daml" => \&daml_handler,
"body" => \&body_handler,
@@ -604,12 +719,15 @@ my %daml_handler = (
"meta-keywords" => \&meta_handler,
"translation" => \&translation_handler,
"extra-style" => \&extra_style_handler,
+ "email-despammed" => \&email_despammed_handler,
+ "email-at" => \&email_at_handler,
+ "email-dot" => \&email_dot_handler,
);
TODO_LOOP:
while ( my $process = shift @todo_stack ) {
my $call_this = shift @$process;
- if ( $call_this ) {
+ if ( defined($call_this) ) {
&$call_this(@$process);
next TODO_LOOP;
}