23 |
$doc->manakai_is_html (1); |
$doc->manakai_is_html (1); |
24 |
} |
} |
25 |
|
|
26 |
my $target_lang = 'en'; |
my $target_lang = shift || 'en'; |
27 |
|
|
28 |
my @node = (@{$doc->child_nodes}); |
my @node = (@{$doc->child_nodes}); |
29 |
while (@node) { |
while (@node) { |
30 |
my $node = shift @node; |
my $node = shift @node; |
38 |
unshift @node, @{$node->child_nodes}; |
unshift @node, @{$node->child_nodes}; |
39 |
} |
} |
40 |
} elsif ($node->namespace_uri eq $SRC_NS) { |
} elsif ($node->namespace_uri eq $SRC_NS) { |
41 |
if ($node->manakai_local_name eq 'item') { |
my $ln = $node->manakai_local_name; |
42 |
|
if ($ln eq 'item' or $ln eq 'cat') { |
43 |
my $message; |
my $message; |
44 |
my $desc; |
my $desc; |
45 |
|
my $text; |
46 |
for (@{$node->child_nodes}) { |
for (@{$node->child_nodes}) { |
47 |
if ($_->node_type == $_->ELEMENT_NODE and |
if ($_->node_type == $_->ELEMENT_NODE and |
48 |
$_->namespace_uri eq $SRC_NS) { |
$_->namespace_uri eq $SRC_NS) { |
60 |
} else { |
} else { |
61 |
$message ||= $_; |
$message ||= $_; |
62 |
} |
} |
63 |
|
} elsif ($_->manakai_local_name eq 'text') { |
64 |
|
if ($_->get_attribute_ns ($XML_NS, 'lang') eq $target_lang) { |
65 |
|
$text = $_; |
66 |
|
next; |
67 |
|
} else { |
68 |
|
$text ||= $_; |
69 |
|
} |
70 |
} |
} |
71 |
} |
} |
72 |
} |
} |
73 |
|
|
74 |
my $name = $node->get_attribute_ns (undef, 'name'); |
if ($ln eq 'item' or $desc) { |
75 |
$name =~ tr/ /-/; |
my $name = $node->get_attribute_ns (undef, 'name'); |
76 |
my $level = $node->get_attribute_ns (undef, 'level'); |
$name =~ tr/ /-/; |
77 |
$name = $level . ':' . $name if defined $level; |
|
78 |
my $section = $doc->create_element_ns ($HTML_NS, 'div'); |
my $section = $doc->create_element_ns ($HTML_NS, 'div'); |
79 |
$section->set_attribute_ns |
$section->set_attribute_ns (undef, class => 'section'); |
80 |
(undef, class => 'section ' . |
$section->set_attribute_ns (undef, id => $name); |
81 |
$node->get_attribute_ns (undef, 'class')); |
|
82 |
$section->set_attribute_ns (undef, id => $name); |
my $msg = $section->append_child |
83 |
|
($doc->create_element_ns ($HTML_NS, 'h3')); |
84 |
my @message_child = @{$message->child_nodes}; |
if ($ln eq 'item' and $message) { |
85 |
my $msg = $section->append_child |
my @message_child = @{$message->child_nodes}; |
86 |
($doc->create_element_ns ($HTML_NS, 'h3')); |
$msg->append_child ($_) for @message_child; |
87 |
$msg->append_child ($_) for @message_child; |
} elsif ($ln eq 'cat' and $text) { |
88 |
|
$msg->append_child ($_) for @{$text->child_nodes}; |
89 |
if ($desc) { |
} |
90 |
my @desc_child = @{$desc->child_nodes}; |
|
91 |
$section->append_child ($_) for @desc_child; |
if ($desc) { |
92 |
|
my @desc_child = @{$desc->child_nodes}; |
93 |
|
$section->append_child ($_) for @desc_child; |
94 |
|
} |
95 |
|
|
96 |
|
$node->parent_node->insert_before ($section, $node); |
97 |
} |
} |
|
|
|
|
$node->parent_node->insert_before ($section, $node); |
|
|
$node->parent_node->remove_child ($node); ## TODO: replace_child is not yet implemented |
|
|
} elsif ($node->manakai_local_name eq 'cat') { |
|
98 |
$node->parent_node->remove_child ($node); |
$node->parent_node->remove_child ($node); |
99 |
} else { |
} else { |
100 |
warn "$0: ", $node->manakai_local_name, " is not supported\n"; |
warn "$0: ", $node->manakai_local_name, " is not supported\n"; |