summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-04-06 02:27:20 (GMT)
committerDavid A. Madore <david+git@madore.org>2010-04-06 02:27:20 (GMT)
commitcc7a5fb4a33deb036aacd44a95288149bb429781 (patch)
treef85b9d10f43b96765698da825747056efbcf8867
parentc3e737ab4574ba2569c7bcdc3c3e5fa7951c11ee (diff)
downloadblogengine-cc7a5fb4a33deb036aacd44a95288149bb429781.zip
blogengine-cc7a5fb4a33deb036aacd44a95288149bb429781.tar.gz
blogengine-cc7a5fb4a33deb036aacd44a95288149bb429781.tar.bz2
Handle date-extra, comments link. Plus, fix some forgotten context passing.
-rwxr-xr-xdaml2html.pl88
1 files changed, 76 insertions, 12 deletions
diff --git a/daml2html.pl b/daml2html.pl
index 6822447..74876f7 100755
--- a/daml2html.pl
+++ b/daml2html.pl
@@ -499,10 +499,10 @@ sub daml_handler {
}
unshift @todo_stack, @to_process;
push @todo_stack, [\&create_style_or_script_node, $head_node,
- {special=>1}, {special=>1},
+ {%$ctxref, special=>1}, {special=>1},
"style", \$style_content];
push @todo_stack, [\&create_style_or_script_node, $head_node,
- {special=>1}, {special=>1},
+ {%$ctxref, special=>1}, {special=>1},
"script", \$script_content];
}
@@ -525,7 +525,8 @@ sub body_handler {
my $token = $doc->createElementNS(DAML_NS, "d:implicit-do-title");
$body_node->appendChild($doc->createTextNode("\n"));
$body_node->appendChild($token);
- unshift @to_process, [\&do_title_handler, $token, {implicit=>1}];
+ unshift @to_process, [\&do_title_handler, $token,
+ $ctxref, {implicit=>1}];
}
}
unless ( $node->getAttributeNS("", "nosubtitle") ) {
@@ -533,21 +534,24 @@ sub body_handler {
my $token = $doc->createElementNS(DAML_NS, "d:implicit-do-subtitle");
$body_node->appendChild($doc->createTextNode("\n"));
$body_node->appendChild($token);
- unshift @to_process, [\&do_subtitle_handler, $token, {implicit=>1}];
+ unshift @to_process, [\&do_subtitle_handler, $token,
+ $ctxref, {implicit=>1}];
}
}
unless ( $node->getAttributeNS("", "nonavbar") ) {
my $token = $doc->createElementNS(DAML_NS, "d:implicit-do-navbar");
$body_node->appendChild($doc->createTextNode("\n"));
$body_node->appendChild($token);
- unshift @to_process, [\&do_navbar_handler, $token, {implicit=>1}];
+ unshift @to_process, [\&do_navbar_handler, $token,
+ $ctxref, {implicit=>1}];
}
unless ( $node->getAttributeNS("", "notranslations") ) {
if ( @translations ) {
my $token = $doc->createElementNS(DAML_NS, "d:implicit-do-translations");
$body_node->appendChild($doc->createTextNode("\n"));
$body_node->appendChild($token);
- unshift @to_process, [\&do_translations_handler, $token, {implicit=>1}];
+ unshift @to_process, [\&do_translations_handler, $token,
+ $ctxref, {implicit=>1}];
}
}
foreach my $child ( @child_nodes ) {
@@ -564,7 +568,8 @@ 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,
+ $ctxref, {implicit=>1}];
}
unshift @todo_stack, @to_process;
}
@@ -741,7 +746,8 @@ sub email_despammed_handler {
my @to_process;
foreach my $child ( @child_nodes ) {
$out1->appendChild($child);
- push @to_process, [undef, $child, $ctxref, {is_email_despammed_child=>1}]
+ push @to_process, [undef, $child,
+ $ctxref, {is_email_despammed_child=>1}]
if $child->nodeType == XML_ELEMENT_NODE;
}
unshift @todo_stack, @to_process;
@@ -808,10 +814,10 @@ sub entry_handler {
&& ( ($entry_year,$entry_month,$entry_day)
= ( $entry_date =~ /^(\d{4})\-(\d{2})\-(\d{2})$/s ) ) );
my $entry_dow = $node->getAttributeNS("", "day_of_week");
+ my $entry_yandm = "${entry_year}-${entry_month}";
my %newctx = (%{$ctxref}, in_entry=>1, entry_number=>$entry_number,
- entry_date=>$entry_date, entry_year=>$entry_year,
- entry_month=>$entry_month, entry_day=>$entry_day,
- entry_dow=>$entry_dow);
+ entry_date=>$entry_date, entry_yandm=>$entry_yandm,
+ entry_dow=>$entry_dow);
my $lang = get_node_lang_rec $node;
my $div = $doc->createElementNS(XHTML_NS, "div");
if ( defined(my $explicit_lang = get_node_lang_norec $node) ) {
@@ -829,7 +835,7 @@ sub entry_handler {
$div->appendChild($header);
$div->appendChild($doc->createTextNode("\n"));
my $permalink = $doc->createElementNS(XHTML_NS, "a");
- $permalink->setAttributeNS("", "href", "${entry_year}-${entry_month}.html"
+ $permalink->setAttributeNS("", "href", "${entry_yandm}.html"
."\#d.${entry_date}.${entry_number}");
$permalink->appendChild($doc->createTextNode($entry_date));
$header->appendChild($permalink);
@@ -850,6 +856,13 @@ sub entry_handler {
# Don't copy whitespace, like previous engine, to faciliate comparison.
}
}
+ unless ( $node->getAttributeNS("", "nocomments") ) {
+ my $token = $doc->createElementNS(DAML_NS, "d:implicit-do-comments");
+ $div->appendChild($token);
+ $div->appendChild($doc->createTextNode("\n"));
+ unshift @to_process, [\&do_comments_handler, $token,
+ \%newctx, {implicit=>1}];
+ }
unshift @todo_stack, @to_process;
}
@@ -883,7 +896,57 @@ sub title_handler {
document_title_handler $node, $ctxref, $optref;
} elsif ( $$optref{is_entry_child} ) {
entry_title_handler $node, $ctxref, $optref;
+ } else {
+ die "misplaced title element";
+ }
+}
+
+sub date_extra_handler {
+ my $node = shift;
+ my $ctxref = shift;
+ my $optref = shift;
+ print STDERR "warning: date-extra handler doesn't handle arguments\n" if @_;
+ die "misplaced date-extra element: makes sense only as a child of entry"
+ unless $$optref{is_entry_child};
+ die "this is impossible" unless defined($$ctxref{entry_header});
+ $$ctxref{entry_header}->appendChild(
+ $doc->createTextNode(" ยท ".$node->textContent));
+}
+
+sub do_comments_handler {
+ my $node = shift;
+ my $ctxref = shift;
+ my $optref = shift;
+ print STDERR "warning: do-comments handler doesn't handle arguments\n" if @_;
+ my $p = $doc->createElementNS(XHTML_NS, "p");
+ my $lang = get_node_lang_rec $node;
+ my $explicit_lang = get_node_lang_norec $node;
+ my %link_name = ( "en" => "Comments", "fr" => "Commentaires",
+ "de" => "Kommentare", "ia" => "Commentos" );
+ unless ( defined($lang) && defined($link_name{$lang}) ) {
+ print STDERR "warning: will use English comments link\n";
+ $lang = "en";
+ $explicit_lang = "en";
}
+ if ( defined($explicit_lang) ) {
+ set_node_lang_norec $p, $explicit_lang;
+ }
+ $p->setAttributeNS("", "class", "talkback-link");
+ $node->replaceNode($p);
+ my $a = $doc->createElementNS(XHTML_NS, "a");
+ my $cmt_url = "http://www.madore.org/cgi-bin/comment.pl/"
+ ."showcomments?href=http%3a%2f%2fwww.madore.org%2f"
+ ."%7edavid%2fweblog%2f".$$ctxref{entry_yandm}
+ .".html%23d.".$$ctxref{entry_date}.".".$$ctxref{entry_number};
+ $a->setAttributeNS("", "href", $cmt_url);
+ $p->appendChild($a);
+ $a->appendChild($doc->createTextNode($link_name{$lang}));
+ my $span = $doc->createElementNS(XHTML_NS, "span");
+ $span->setAttributeNS("", "id",
+ "d.".$$ctxref{entry_date}.".".$$ctxref{entry_number}
+ .".numcomments");
+ $p->appendChild($span);
+ $span->appendChild($doc->createComment(" EMPTY "));
}
my %daml_handler = (
@@ -910,6 +973,7 @@ my %daml_handler = (
"smiley-twisted" => \&smiley_handler,
"smiley-cry" => \&smiley_handler,
"entry" => \&entry_handler,
+ "date-extra" => \&date_extra_handler,
);
TODO_LOOP: