summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-04-06 01:32:35 (GMT)
committerDavid A. Madore <david+git@madore.org>2010-04-06 01:32:35 (GMT)
commitbd20d00b168c6b9fa06b9a2d156a2f674b4a6081 (patch)
tree218d9d6d480615cfa9770be64b11546c9b568fc9
parent3761de04f01d450953df21a5e832279b2ce89eb0 (diff)
downloadblogengine-bd20d00b168c6b9fa06b9a2d156a2f674b4a6081.zip
blogengine-bd20d00b168c6b9fa06b9a2d156a2f674b4a6081.tar.gz
blogengine-bd20d00b168c6b9fa06b9a2d156a2f674b4a6081.tar.bz2
Start handling weblog entries.
-rwxr-xr-xdaml2html.pl132
1 files changed, 109 insertions, 23 deletions
diff --git a/daml2html.pl b/daml2html.pl
index 94dabd5..67c0fc9 100755
--- a/daml2html.pl
+++ b/daml2html.pl
@@ -551,33 +551,31 @@ sub body_handler {
unshift @todo_stack, @to_process;
}
-sub title_handler {
+sub document_title_handler {
my $node = shift;
my $optref = shift;
print STDERR "warning: title handler doesn't handle arguments\n" if @_;
- if ( $$optref{is_daml_child} ) {
- my $title_text = $node->textContent;
- $src_title = $doc->createDocumentFragment;
- $src_title_lang = get_node_lang_rec $node;
- my $src_title_explicit_lang = get_node_lang_norec $node;
- foreach my $child ( $node->childNodes ) {
- $src_title->appendChild($child);
- }
- my $title_node = $doc->createElementNS(XHTML_NS, "title");
- 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;
- }
-# ($doc->documentElement)->appendChild($title_node); # Work around libxml2 bug <URL: https://bugzilla.gnome.org/show_bug.cgi?id=614068 >
- $node->replaceNode($title_node);
- $title_node->appendChild($doc->createTextNode($title_text));
- my $title_parent = $title_node->parentNode;
- $title_parent->insertAfter(
- create_meta_element_helper(undef, "name", "Title",
- $title_text, $src_title_explicit_lang),
- $title_node);
- $title_parent->insertAfter($doc->createTextNode("\n"), $title_node);
+ my $title_text = $node->textContent;
+ $src_title = $doc->createDocumentFragment;
+ $src_title_lang = get_node_lang_rec $node;
+ my $src_title_explicit_lang = get_node_lang_norec $node;
+ foreach my $child ( $node->childNodes ) {
+ $src_title->appendChild($child);
+ }
+ my $title_node = $doc->createElementNS(XHTML_NS, "title");
+ 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;
}
+# ($doc->documentElement)->appendChild($title_node); # Work around libxml2 bug <URL: https://bugzilla.gnome.org/show_bug.cgi?id=614068 >
+ $node->replaceNode($title_node);
+ $title_node->appendChild($doc->createTextNode($title_text));
+ my $title_parent = $title_node->parentNode;
+ $title_parent->insertAfter(
+ create_meta_element_helper(undef, "name", "Title",
+ $title_text, $src_title_explicit_lang),
+ $title_node);
+ $title_parent->insertAfter($doc->createTextNode("\n"), $title_node);
}
sub subtitle_handler {
@@ -766,6 +764,93 @@ sub smiley_handler {
$node->replaceNode($img);
}
+sub entry_handler {
+ my $node = shift;
+ my $optref = shift;
+ print STDERR "warning: entry handler doesn't handle arguments\n" if @_;
+ my $entry_number = $node->getAttributeNS("", "number");
+ die "entry has missing or bad number attribute"
+ unless ( defined($entry_number)
+ && $entry_number =~ /^(\d{4})$/s );
+ my $entry_date = $node->getAttributeNS("", "date");
+ my ($entry_year,$entry_month,$entry_day);
+ die "entry has missing or bad date attribute"
+ unless ( defined($entry_date)
+ && ( ($entry_year,$entry_month,$entry_day)
+ = ( $entry_date =~ /^(\d{4})\-(\d{2})\-(\d{2})$/s ) ) );
+ my $entry_dow = $node->getAttributeNS("", "day_of_week");
+ my $lang = get_node_lang_rec $node;
+ my $div = $doc->createElementNS(XHTML_NS, "div");
+ if ( defined(my $explicit_lang = get_node_lang_norec $node) ) {
+ set_node_lang_norec $div, $explicit_lang;
+ }
+ $div->setAttributeNS("", "id", "d.${entry_date}.${entry_number}");
+ $div->setAttributeNS("", "class", "weblog-entry");
+ if ( defined(my $style = $node->getAttributeNS("", "style")) ) {
+ $div->setAttributeNS("", "style", $style);
+ }
+ $node->replaceNode($div);
+ $div->appendChild($doc->createTextNode("\n"));
+ my $header = $doc->createElementNS(XHTML_NS, "p");
+ $header->setAttributeNS("", "class", "weblog-entry-header");
+ $div->appendChild($header);
+ $div->appendChild($doc->createTextNode("\n"));
+ my $permalink = $doc->createElementNS(XHTML_NS, "a");
+ $permalink->setAttributeNS("", "href", "${entry_year}-${entry_month}.html"
+ ."\#d.${entry_date}.${entry_number}");
+ $permalink->appendChild($doc->createTextNode($entry_date));
+ $header->appendChild($permalink);
+ $header->appendChild($doc->createTextNode(" (".$entry_dow.")"))
+ if defined($entry_dow);
+ my @child_nodes = $node->childNodes;
+ my @to_process;
+ foreach my $child ( @child_nodes ) {
+ if ( $child->nodeType == XML_ELEMENT_NODE ) {
+ $div->appendChild($child);
+ push @to_process, [undef, $child, {is_entry_child=>1,
+ entry_header=>$header}];
+ } elsif ( $child->nodeType == XML_TEXT_NODE
+ || $child->nodeType == XML_CDATA_SECTION_NODE ) {
+ die "entry element cannot contain text"
+ unless $child->data =~ m/^\s*$/s;
+ $div->appendChild($doc->createTextNode("\n"));
+ # Don't copy whitespace, like previous engine, to faciliate comparison.
+ }
+ }
+ unshift @todo_stack, @to_process;
+}
+
+sub entry_title_handler {
+ my $node = shift;
+ my $optref = shift;
+ print STDERR "warning: title handler doesn't handle arguments\n" if @_;
+ my $h2 = $doc->createElementNS(XHTML_NS, "h2");
+ if ( my $lang = get_node_lang_norec $node ) {
+ set_node_lang_norec $h2, $lang;
+ }
+ $h2->setAttributeNS("", "class", "weblog-entry-title");
+ $node->replaceNode($h2);
+ my @child_nodes = $node->childNodes;
+ my @to_process;
+ foreach my $child ( @child_nodes ) {
+ $h2->appendChild($child);
+ push @to_process, [undef, $child, {}]
+ if $child->nodeType == XML_ELEMENT_NODE;
+ }
+ unshift @todo_stack, @to_process;
+}
+
+sub title_handler {
+ my $node = shift;
+ my $optref = shift;
+ print STDERR "warning: title handler doesn't handle arguments\n" if @_;
+ if ( $$optref{is_daml_child} ) {
+ document_title_handler $node, $optref;
+ } elsif ( $$optref{is_entry_child} ) {
+ entry_title_handler $node, $optref;
+ }
+}
+
my %daml_handler = (
"daml" => \&daml_handler,
"body" => \&body_handler,
@@ -789,6 +874,7 @@ my %daml_handler = (
"smiley-neutral" => \&smiley_handler,
"smiley-twisted" => \&smiley_handler,
"smiley-cry" => \&smiley_handler,
+ "entry" => \&entry_handler,
);
TODO_LOOP: