/[suikacvs]/test/html-webhacc/mkdescription.pl
Suika

Contents of /test/html-webhacc/mkdescription.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Mon Jul 16 08:38:48 2007 UTC (17 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.1: +12 -6 lines
File MIME type: text/plain
++ ChangeLog	16 Jul 2007 08:38:44 -0000
	* Makefile (all): |cc-msg.en.txt| is added to the list of
	dependency.
	(cc-msg.en.txt): New rule.

	* mkcatalog.pl: New Perl script.

	* cc-msg.en.txt: Now this file is generated by
	the rule described in |Makefile|.

	* cc.cgi (HTML mode): Set |charset| as |ISO-8859-1|
	if not specified, for now.
	(get_text): Replace |<var>$/n/</var>|, not just |$/n/|,
	to variable.

	* error-description-source.xml: All entries
	in |cc-msg.en.txt| are now described as XML data.

	* mkdescription.pl: Print the result by |inner_html| DOM
	attribute.  Put |level| attribute value, if any, before |name|
	attribute value.  Allow missing of |desc| attribute.
	Ignore any |catalog| element.

2007-07-16  Wakaba  <wakaba@suika.fam.cx>

1 #!/usr/bin/perl
2 use strict;
3 use encoding 'us-ascii', STDOUT => 'utf-8';
4
5 use lib qw[/home/httpd/html/www/markup/html/whatpm
6 /home/wakaba/work/manakai/lib
7 /home/wakaba/public_html/-temp/wiki/lib];
8
9 my $HTML_NS = q<http://www.w3.org/1999/xhtml>;
10 my $SRC_NS = q<http://suika.fam.cx/~wakaba/archive/2007/wdcc-desc/>;
11 my $XML_NS = q<http://www.w3.org/XML/1998/namespace>;
12
13 require Message::DOM::DOMImplementation;
14 my $dom = Message::DOM::DOMImplementation->new;
15
16 my $doc;
17 {
18 my $source_file_name = shift or die "$0: No source file specified\n";
19 open my $source_file, '<', $source_file_name
20 or die "$0: $source_file_name: $!";
21 require Message::DOM::XMLParserTemp;
22 $doc = Message::DOM::XMLParserTemp->parse_byte_stream
23 ($source_file => $dom, undef, charset => 'utf-8');
24 $doc->manakai_is_html (1);
25 }
26
27 my $target_lang = 'en';
28 my @node = (@{$doc->child_nodes});
29 while (@node) {
30 my $node = shift @node;
31 if ($node->node_type == $node->ELEMENT_NODE) {
32 if ($node->namespace_uri eq $HTML_NS) {
33 if ($node->manakai_local_name eq 'title') {
34 unless ($node->get_attribute_ns ($XML_NS, 'lang') eq $target_lang) {
35 $node->parent_node->remove_child ($node);
36 }
37 } else {
38 unshift @node, @{$node->child_nodes};
39 }
40 } elsif ($node->namespace_uri eq $SRC_NS) {
41 if ($node->manakai_local_name eq 'item') {
42 my $message;
43 my $desc;
44 for (@{$node->child_nodes}) {
45 if ($_->node_type == $_->ELEMENT_NODE and
46 $_->namespace_uri eq $SRC_NS) {
47 if ($_->manakai_local_name eq 'desc') {
48 if ($_->get_attribute_ns ($XML_NS, 'lang') eq $target_lang) {
49 $desc = $_;
50 next;
51 } else {
52 $desc ||= $_;
53 }
54 } elsif ($_->manakai_local_name eq 'message') {
55 if ($_->get_attribute_ns ($XML_NS, 'lang') eq $target_lang) {
56 $message = $_;
57 next;
58 } else {
59 $message ||= $_;
60 }
61 }
62 }
63 }
64
65 my $name = $node->get_attribute_ns (undef, 'name');
66 $name =~ tr/ /-/;
67 my $level = $node->get_attribute_ns (undef, 'level');
68 $name = $level . ':' . $name if defined $level;
69 my $section = $doc->create_element_ns ($HTML_NS, 'div');
70 $section->set_attribute_ns
71 (undef, class => 'section ' .
72 $node->get_attribute_ns (undef, 'class'));
73 $section->set_attribute_ns (undef, id => $name);
74
75 my @message_child = @{$message->child_nodes};
76 my $msg = $section->append_child
77 ($doc->create_element_ns ($HTML_NS, 'h3'));
78 $msg->append_child ($_) for @message_child;
79
80 if ($desc) {
81 my @desc_child = @{$desc->child_nodes};
82 $section->append_child ($_) for @desc_child;
83 }
84
85 $node->parent_node->insert_before ($section, $node);
86 $node->parent_node->remove_child ($node); ## TODO: replace_child is not yet implemented
87 } elsif ($node->manakai_local_name eq 'catalog') {
88 #
89 } else {
90 warn "$0: ", $node->manakai_local_name, " is not supported\n";
91 }
92 }
93 }
94 }
95 $doc->document_element->set_attribute_ns (undef, lang => $target_lang);
96
97 print $doc->inner_html;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24