26 |
my $target_lang = shift || 'en'; |
my $target_lang = shift || 'en'; |
27 |
|
|
28 |
my @node = (@{$doc->child_nodes}); |
my @node = (@{$doc->child_nodes}); |
29 |
|
my $title; |
30 |
|
my $title_parent; |
31 |
while (@node) { |
while (@node) { |
32 |
my $node = shift @node; |
my $node = shift @node; |
33 |
if ($node->node_type == $node->ELEMENT_NODE) { |
if ($node->node_type == $node->ELEMENT_NODE) { |
34 |
if ($node->namespace_uri eq $HTML_NS) { |
if ($node->namespace_uri eq $HTML_NS) { |
35 |
if ($node->manakai_local_name eq 'title') { |
if ($node->manakai_local_name eq 'title') { |
36 |
unless ($node->get_attribute_ns ($XML_NS, 'lang') eq $target_lang) { |
$title_parent = $node->parent_node; |
37 |
|
if ($node->get_attribute_ns ($XML_NS, 'lang') eq $target_lang) { |
38 |
|
$title = $node; |
39 |
|
} else { |
40 |
|
$title ||= $node; |
41 |
$node->parent_node->remove_child ($node); |
$node->parent_node->remove_child ($node); |
42 |
} |
} |
43 |
} else { |
} else { |
109 |
} |
} |
110 |
} |
} |
111 |
$doc->document_element->set_attribute_ns (undef, lang => $target_lang); |
$doc->document_element->set_attribute_ns (undef, lang => $target_lang); |
112 |
|
$title_parent->append_child ($title) if $title; |
113 |
|
|
114 |
print $doc->inner_html; |
print $doc->inner_html; |