50 |
my @s = split /\x0D\x0A?|\x0A/, ref $_[0] ? ${$_[0]} : $_[0], -1; |
my @s = split /\x0D\x0A?|\x0A/, ref $_[0] ? ${$_[0]} : $_[0], -1; |
51 |
|
|
52 |
my $doc = $_[1]; |
my $doc = $_[1]; |
53 |
$doc->inner_html |
@{$doc->child_nodes} = (); |
54 |
('<html xmlns="http://www.w3.org/1999/xhtml"><head/><body/></html>'); |
my $html_el = $doc->create_element_ns (HTML_NS, [undef, 'html']); |
55 |
for ($doc, |
$doc->append_child ($html_el); |
56 |
$doc->document_element, |
$html_el->set_attribute_ns |
57 |
$doc->document_element->first_child, |
('http://www.w3.org/2000/xmlns/', [undef, 'xmlns'] => HTML_NS); |
58 |
$doc->document_element->last_child) { |
my $head_el = $doc->create_element_ns (HTML_NS, [undef, 'head']); |
59 |
|
$html_el->append_child ($head_el); |
60 |
|
my $body_el = $doc->create_element_ns (HTML_NS, [undef, 'body']); |
61 |
|
$html_el->append_child ($body_el); |
62 |
|
for ($doc, $html_el, $head_el, $body_el) { |
63 |
$_->set_user_data (manakai_source_line => 1); |
$_->set_user_data (manakai_source_line => 1); |
64 |
$_->set_user_data (manakai_source_column => 1); |
$_->set_user_data (manakai_source_column => 1); |
65 |
} |
} |
416 |
undef $continuous_line; |
undef $continuous_line; |
417 |
return shift @nt; |
return shift @nt; |
418 |
} elsif ($s eq '__IMAGE__') { |
} elsif ($s eq '__IMAGE__') { |
419 |
my $image = $doc->create_element_ns (SW09_NS, 'image'); |
my $image = $doc->create_element_ns (SW09_NS, [undef, 'image']); |
420 |
$image->set_user_data (manakai_source_line => $line); |
$image->set_user_data (manakai_source_line => $line); |
421 |
$image->set_user_data (manakai_source_column => 1); |
$image->set_user_data (manakai_source_column => 1); |
422 |
$image->text_content (join "\x0A", $s, @s); |
$image->text_content (join "\x0A", $s, @s); |
443 |
$column += $+[0] - $-[0]; |
$column += $+[0] - $-[0]; |
444 |
my ($name, $version) = split m#/#, $1, 2; |
my ($name, $version) = split m#/#, $1, 2; |
445 |
my $el = $doc->document_element; |
my $el = $doc->document_element; |
446 |
$el->set_attribute_ns (SW09_NS, 'sw:Name' => $name); |
$el->set_attribute_ns (SW09_NS, ['sw', 'Name'] => $name); |
447 |
$el->set_attribute_ns (SW09_NS, 'sw:Version' => $version) |
$el->set_attribute_ns (SW09_NS, ['sw', 'Version'] => $version) |
448 |
if defined $version; |
if defined $version; |
449 |
} |
} |
450 |
|
|
|
my $head = $doc->first_child->first_child; |
|
451 |
while (length $s) { |
while (length $s) { |
452 |
$column += $+[0] - $-[0] if $s =~ s/^[\x09\x20]+//; |
$column += $+[0] - $-[0] if $s =~ s/^[\x09\x20]+//; |
453 |
my $name = ''; |
my $name = ''; |
455 |
$name = $1; |
$name = $1; |
456 |
$column += length $name + 1; |
$column += length $name + 1; |
457 |
} |
} |
458 |
my $param = $doc->create_element_ns (SW09_NS, 'parameter'); |
my $param = $doc->create_element_ns (SW09_NS, [undef, 'parameter']); |
459 |
$param->set_attribute (name => $name); |
$param->set_attribute_ns (undef, [undef, 'name'] => $name); |
460 |
$param->set_user_data (manakai_source_line => $line); |
$param->set_user_data (manakai_source_line => $line); |
461 |
$param->set_user_data (manakai_source_column => $column); |
$param->set_user_data (manakai_source_column => $column); |
462 |
$head->append_child ($param); |
$head_el->append_child ($param); |
463 |
|
|
464 |
$column++ if $s =~ s/^"//; |
$column++ if $s =~ s/^"//; |
465 |
if ($s =~ s/^([^"]+)//) { |
if ($s =~ s/^([^"]+)//) { |
467 |
$column += length $values; |
$column += length $values; |
468 |
$values =~ tr/\\//d; |
$values =~ tr/\\//d; |
469 |
for (split /,/, $values, -1) { |
for (split /,/, $values, -1) { |
470 |
my $value = $doc->create_element_ns (SW09_NS, 'value'); |
my $value = $doc->create_element_ns (SW09_NS, [undef, 'value']); |
471 |
$value->text_content ($_); |
$value->text_content ($_); |
472 |
$value->set_user_data (manakai_source_line => $line); |
$value->set_user_data (manakai_source_line => $line); |
473 |
$value->set_user_data (manakai_source_column => $column); |
$value->set_user_data (manakai_source_column => $column); |
483 |
|
|
484 |
## NOTE: Switched to the "body" mode. |
## NOTE: Switched to the "body" mode. |
485 |
|
|
486 |
my $oe = [{node => $doc->document_element->last_child, |
my $oe = [{node => $body_el, |
487 |
section_depth => 0, |
section_depth => 0, |
488 |
quotation_depth => 0, |
quotation_depth => 0, |
489 |
list_depth => 0}]; |
list_depth => 0}]; |
505 |
redo A; |
redo A; |
506 |
} elsif ($token->{type} == INLINE_START_TAG_TOKEN) { |
} elsif ($token->{type} == INLINE_START_TAG_TOKEN) { |
507 |
if (not defined $token->{tag_name}) { |
if (not defined $token->{tag_name}) { |
508 |
my $el = $doc->create_element_ns (SW09_NS, 'anchor'); |
my $el = $doc->create_element_ns (SW09_NS, [undef, 'anchor']); |
509 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
510 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
511 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
538 |
VAR => [HTML_NS, 'var'], |
VAR => [HTML_NS, 'var'], |
539 |
WEAK => [SW09_NS, 'weak'], |
WEAK => [SW09_NS, 'weak'], |
540 |
}->{$token->{tag_name}} || [SW10_NS, $token->{tag_name}]; |
}->{$token->{tag_name}} || [SW10_NS, $token->{tag_name}]; |
541 |
my $el = $doc->create_element_ns (SW10_NS, 'td'); |
my $el = $doc->create_element_ns (SW10_NS, [undef, 'td']); |
542 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
543 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
544 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
545 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
546 |
|
|
547 |
$el->set_attribute (class => $token->{classes}) |
$el->set_attribute_ns (undef, [undef, 'class'] => $token->{classes}) |
548 |
if defined $token->{classes}; |
if defined $token->{classes}; |
549 |
$el->set_attribute_ns (XML_NS, 'xml:lang' => $token->{language}) |
$el->set_attribute_ns (XML_NS, ['xml', 'lang'] => $token->{language}) |
550 |
if defined $token->{language}; |
if defined $token->{language}; |
551 |
|
|
552 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
563 |
}->{$oe->[-1]->{node}->manakai_local_name} || [SW10_NS, 'title']}; |
}->{$oe->[-1]->{node}->manakai_local_name} || [SW10_NS, 'title']}; |
564 |
pop @$oe if $pop; |
pop @$oe if $pop; |
565 |
|
|
566 |
my $el = $doc->create_element_ns ($ns, $ln); |
my $el = $doc->create_element_ns ($ns, [undef, $ln]); |
567 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
568 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
569 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
570 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
571 |
|
|
572 |
$el->set_attribute_ns (XML_NS, 'xml:lang' => $token->{language}) |
$el->set_attribute_ns (XML_NS, ['xml', 'lang'] => $token->{language}) |
573 |
if defined $token->{language}; |
if defined $token->{language}; |
574 |
|
|
575 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
583 |
strong => 1, em => 1}->{$oe->[-1]->{node}->manakai_local_name}) { |
strong => 1, em => 1}->{$oe->[-1]->{node}->manakai_local_name}) { |
584 |
my $el = $doc->create_element_ns |
my $el = $doc->create_element_ns |
585 |
(SW09_NS, |
(SW09_NS, |
586 |
defined $token->{res_scheme} |
[undef, defined $token->{res_scheme} |
587 |
? 'anchor-external' : 'anchor-internal'); |
? 'anchor-external' : 'anchor-internal']); |
588 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
589 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
590 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
592 |
$el->text_content (']]'); |
$el->text_content (']]'); |
593 |
} |
} |
594 |
|
|
595 |
$oe->[-1]->{node}->set_attribute_ns (SW09_NS, 'sw:anchor', |
$oe->[-1]->{node}->set_attribute_ns (SW09_NS, ['sw', 'anchor'], |
596 |
$token->{anchor}) |
$token->{anchor}) |
597 |
if defined $token->{anchor}; |
if defined $token->{anchor}; |
598 |
$oe->[-1]->{node}->set_attribute_ns (SW09_NS, 'sw:resScheme', |
$oe->[-1]->{node}->set_attribute_ns (SW09_NS, ['sw', 'resScheme'], |
599 |
$token->{res_scheme}) |
$token->{res_scheme}) |
600 |
if defined $token->{res_scheme}; |
if defined $token->{res_scheme}; |
601 |
$oe->[-1]->{node}->set_attribute_ns (SW09_NS, 'sw:resParameter', |
$oe->[-1]->{node}->set_attribute_ns (SW09_NS, ['sw', 'resParameter'], |
602 |
$token->{res_parameter}) |
$token->{res_parameter}) |
603 |
if defined $token->{res_parameter}; |
if defined $token->{res_parameter}; |
604 |
|
|
607 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
608 |
redo A; |
redo A; |
609 |
} elsif ($token->{type} == STRONG_TOKEN) { |
} elsif ($token->{type} == STRONG_TOKEN) { |
610 |
my $el = $doc->create_element_ns (HTML_NS, 'strong'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'strong']); |
611 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
612 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
613 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
616 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
617 |
redo A; |
redo A; |
618 |
} elsif ($token->{type} == EMPHASIS_TOKEN) { |
} elsif ($token->{type} == EMPHASIS_TOKEN) { |
619 |
my $el = $doc->create_element_ns (HTML_NS, 'em'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'em']); |
620 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
621 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
622 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
627 |
} elsif ($token->{type} == FORM_TOKEN) { |
} elsif ($token->{type} == FORM_TOKEN) { |
628 |
## There is an exact code clone. |
## There is an exact code clone. |
629 |
if ($token->{name} eq 'form') { |
if ($token->{name} eq 'form') { |
630 |
my $el = $doc->create_element_ns (SW09_NS, 'form'); |
my $el = $doc->create_element_ns (SW09_NS, [undef, 'form']); |
631 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
632 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
633 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
634 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
635 |
|
|
636 |
$el->set_attribute (id => $token->{id}) if defined $token->{id}; |
$el->set_attribute_ns (undef, [undef, 'id'] |
637 |
$el->set_attribute (input => shift @{$token->{parameters}}) |
=> $token->{id}) if defined $token->{id}; |
638 |
|
$el->set_attribute_ns (undef, [undef, 'input'] |
639 |
|
=> shift @{$token->{parameters}}) |
640 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
641 |
$el->set_attribute (template => shift @{$token->{parameters}}) |
$el->set_attribute_ns (undef, [undef, 'template'] |
642 |
|
=> shift @{$token->{parameters}}) |
643 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
644 |
$el->set_attribute (option => shift @{$token->{parameters}}) |
$el->set_attribute_ns (undef, [undef, 'option'] |
645 |
|
=> shift @{$token->{parameters}}) |
646 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
647 |
$el->set_attribute (parameter => join ':', @{$token->{parameters}}) |
$el->set_attribute_ns (undef, [undef, 'parameter'] |
648 |
|
=> join ':', @{$token->{parameters}}) |
649 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
650 |
|
|
651 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
652 |
redo A; |
redo A; |
653 |
} else { |
} else { |
654 |
my $el = $doc->create_element_ns (SW09_NS, 'form'); |
my $el = $doc->create_element_ns (SW09_NS, [undef, 'form']); |
655 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
656 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
657 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
658 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
659 |
|
|
660 |
$el->set_attribute (ref => $token->{name}); |
$el->set_attribute_ns (undef, [undef, 'ref'] |
661 |
$el->set_attribute (id => $token->{id}) if defined $token->{id}; |
=> $token->{name}); |
662 |
$el->set_attribute (parameter => join ':', @{$token->{parameters}}) |
$el->set_attribute_ns (undef, [undef, 'id'] |
663 |
|
=> $token->{id}) if defined $token->{id}; |
664 |
|
$el->set_attribute_ns (undef, [undef, 'parameter'] |
665 |
|
=> join ':', @{$token->{parameters}}) |
666 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
667 |
|
|
668 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
671 |
} elsif ($token->{type} == ELEMENT_TOKEN) { |
} elsif ($token->{type} == ELEMENT_TOKEN) { |
672 |
## NOTE: There is an exact code clone. |
## NOTE: There is an exact code clone. |
673 |
my $el = $doc->create_element_ns |
my $el = $doc->create_element_ns |
674 |
($token->{namespace}, $token->{local_name}); |
($token->{namespace}, [undef, $token->{local_name}]); |
675 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
676 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
677 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
678 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
679 |
|
|
680 |
$el->set_attribute_ns (SW09_NS, 'sw:anchor', $token->{anchor}) |
$el->set_attribute_ns (SW09_NS, ['sw', 'anchor'], $token->{anchor}) |
681 |
if defined $token->{anchor}; |
if defined $token->{anchor}; |
682 |
$el->set_attribute (by => $token->{by}) if defined $token->{by}; |
$el->set_attribute_ns (undef, [undef, 'by'] |
683 |
$el->set_attribute_ns (SW09_NS, 'sw:resScheme', $token->{res_scheme}) |
=> $token->{by}) if defined $token->{by}; |
684 |
|
$el->set_attribute_ns (SW09_NS, ['sw', 'resScheme'], |
685 |
|
$token->{res_scheme}) |
686 |
if defined $token->{res_scheme}; |
if defined $token->{res_scheme}; |
687 |
$el->set_attribute_ns (SW09_NS, 'sw:resParameter', |
$el->set_attribute_ns (SW09_NS, ['sw', 'resParameter'], |
688 |
$token->{res_parameter}) |
$token->{res_parameter}) |
689 |
if defined $token->{res_parameter}; |
if defined $token->{res_parameter}; |
690 |
$el->text_content ($token->{content}) if defined $token->{content}; |
$el->text_content ($token->{content}) if defined $token->{content}; |
696 |
->{$oe->[-1]->{node}->manakai_local_name}; |
->{$oe->[-1]->{node}->manakai_local_name}; |
697 |
pop @$oe if $oe->[-1]->{node}->manakai_local_name eq 'dt'; |
pop @$oe if $oe->[-1]->{node}->manakai_local_name eq 'dt'; |
698 |
|
|
699 |
my $el = $doc->create_element_ns (HTML_NS, 'dt'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'dt']); |
700 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
701 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
702 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
746 |
->{$oe->[-1]->{node}->manakai_local_name} or |
->{$oe->[-1]->{node}->manakai_local_name} or |
747 |
$token->{depth} <= $oe->[-1]->{section_depth}; |
$token->{depth} <= $oe->[-1]->{section_depth}; |
748 |
if ($token->{depth} > $oe->[-1]->{section_depth} + 1) { |
if ($token->{depth} > $oe->[-1]->{section_depth} + 1) { |
749 |
my $el = $doc->create_element_ns (HTML_NS, 'section'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'section']); |
750 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
751 |
push @$oe, {node => $el, |
push @$oe, {node => $el, |
752 |
section_depth => $oe->[-1]->{section_depth} + 1, |
section_depth => $oe->[-1]->{section_depth} + 1, |
755 |
} |
} |
756 |
} # B |
} # B |
757 |
|
|
758 |
my $el = $doc->create_element_ns (HTML_NS, 'section'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'section']); |
759 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
760 |
push @$oe, {node => $el, |
push @$oe, {node => $el, |
761 |
section_depth => $oe->[-1]->{section_depth} + 1, |
section_depth => $oe->[-1]->{section_depth} + 1, |
762 |
quotation_depth => 0, list_depth => 0}; |
quotation_depth => 0, list_depth => 0}; |
763 |
|
|
764 |
my $el2 = $doc->create_element_ns (HTML_NS, 'h1'); |
my $el2 = $doc->create_element_ns (HTML_NS, [undef, 'h1']); |
765 |
$oe->[-1]->{node}->append_child ($el2); |
$oe->[-1]->{node}->append_child ($el2); |
766 |
push @$oe, {%{$oe->[-1]}, node => $el2}; |
push @$oe, {%{$oe->[-1]}, node => $el2}; |
767 |
|
|
772 |
($token->{tag_name} eq 'INS' or |
($token->{tag_name} eq 'INS' or |
773 |
$token->{tag_name} eq 'DEL')) { |
$token->{tag_name} eq 'DEL')) { |
774 |
my $el = $doc->create_element_ns |
my $el = $doc->create_element_ns |
775 |
(SW09_NS, ($token->{tag_name} eq 'INS' ? 'insert' : 'delete')); |
(SW09_NS, |
776 |
|
[undef, $token->{tag_name} eq 'INS' ? 'insert' : 'delete']); |
777 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
778 |
push @$oe, {node => $el, section_depth => 0, |
push @$oe, {node => $el, section_depth => 0, |
779 |
quotation_depth => 0, list_depth => 0}; |
quotation_depth => 0, list_depth => 0}; |
780 |
$el->set_attribute (class => $token->{classes}) |
$el->set_attribute_ns (undef, [undef, 'class'] => $token->{classes}) |
781 |
if defined $token->{classes}; |
if defined $token->{classes}; |
782 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
783 |
redo A; |
redo A; |
789 |
->{$oe->[-1]->{node}->manakai_local_name} or |
->{$oe->[-1]->{node}->manakai_local_name} or |
790 |
$token->{depth} <= $oe->[-1]->{quotation_depth}; |
$token->{depth} <= $oe->[-1]->{quotation_depth}; |
791 |
if ($token->{depth} > $oe->[-1]->{quotation_depth} + 1) { |
if ($token->{depth} > $oe->[-1]->{quotation_depth} + 1) { |
792 |
my $el = $doc->create_element_ns (HTML_NS, 'blockquote'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'blockquote']); |
793 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
794 |
push @$oe, {node => $el, section_depth => 0, |
push @$oe, {node => $el, section_depth => 0, |
795 |
quotation_depth => $oe->[-1]->{quotation_depth} + 1, |
quotation_depth => $oe->[-1]->{quotation_depth} + 1, |
798 |
} |
} |
799 |
} # B |
} # B |
800 |
|
|
801 |
my $el = $doc->create_element_ns (HTML_NS, 'blockquote'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'blockquote']); |
802 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
803 |
push @$oe, {node => $el, section_depth => 0, |
push @$oe, {node => $el, section_depth => 0, |
804 |
quotation_depth => $oe->[-1]->{quotation_depth} + 1, |
quotation_depth => $oe->[-1]->{quotation_depth} + 1, |
816 |
if ($oe->[-1]->{list_depth} < $depth) { |
if ($oe->[-1]->{list_depth} < $depth) { |
817 |
my $type = substr $token->{depth}, $oe->[-1]->{list_depth}, 1; |
my $type = substr $token->{depth}, $oe->[-1]->{list_depth}, 1; |
818 |
my $el = $doc->create_element_ns |
my $el = $doc->create_element_ns |
819 |
(HTML_NS, $type eq '-' ? 'ul' : 'ol'); |
(HTML_NS, [undef, $type eq '-' ? 'ul' : 'ol']); |
820 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
821 |
push @$oe, {%{$oe->[-1]}, node => $el, |
push @$oe, {%{$oe->[-1]}, node => $el, |
822 |
list_depth => $oe->[-1]->{list_depth} + 1}; |
list_depth => $oe->[-1]->{list_depth} + 1}; |
823 |
if ($oe->[-1]->{list_depth} < $depth) { |
if ($oe->[-1]->{list_depth} < $depth) { |
824 |
my $el = $doc->create_element_ns (HTML_NS, 'li'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'li']); |
825 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
826 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
827 |
} |
} |
829 |
} |
} |
830 |
} # B |
} # B |
831 |
|
|
832 |
my $el = $doc->create_element_ns (HTML_NS, 'li'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'li']); |
833 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
834 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
835 |
|
|
839 |
} elsif ($token->{type} == LABELED_LIST_START_TOKEN) { |
} elsif ($token->{type} == LABELED_LIST_START_TOKEN) { |
840 |
pop @$oe if $oe->[-1]->{node}->manakai_local_name eq 'dd'; |
pop @$oe if $oe->[-1]->{node}->manakai_local_name eq 'dd'; |
841 |
if ($oe->[-1]->{node}->manakai_local_name ne 'dl') { |
if ($oe->[-1]->{node}->manakai_local_name ne 'dl') { |
842 |
my $el = $doc->create_element_ns (HTML_NS, 'dl'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'dl']); |
843 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
844 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
845 |
} |
} |
846 |
|
|
847 |
my $el = $doc->create_element_ns (HTML_NS, 'dt'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'dt']); |
848 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
849 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
850 |
|
|
852 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
853 |
redo A; |
redo A; |
854 |
} elsif ($token->{type} == TABLE_ROW_START_TOKEN) { |
} elsif ($token->{type} == TABLE_ROW_START_TOKEN) { |
855 |
my $el = $doc->create_element_ns (HTML_NS, 'table'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'table']); |
856 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
857 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
858 |
|
|
859 |
$el = $doc->create_element_ns (HTML_NS, 'tbody'); |
$el = $doc->create_element_ns (HTML_NS, [undef, 'tbody']); |
860 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
861 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
862 |
|
|
863 |
$el = $doc->create_element_ns (HTML_NS, 'tr'); |
$el = $doc->create_element_ns (HTML_NS, [undef, 'tr']); |
864 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
865 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
866 |
|
|
870 |
} elsif (($token->{type} == BLOCK_START_TAG_TOKEN and |
} elsif (($token->{type} == BLOCK_START_TAG_TOKEN and |
871 |
$token->{tag_name} eq 'PRE') or |
$token->{tag_name} eq 'PRE') or |
872 |
$token->{type} == PREFORMATTED_START_TOKEN) { |
$token->{type} == PREFORMATTED_START_TOKEN) { |
873 |
my $el = $doc->create_element_ns (HTML_NS, 'pre'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'pre']); |
874 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
875 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
876 |
|
|
877 |
$el->set_attribute (class => $token->{classes}) |
$el->set_attribute_ns (undef, [undef, 'class'] => $token->{classes}) |
878 |
if defined $token->{classes}; |
if defined $token->{classes}; |
879 |
|
|
880 |
$im = IN_PARAGRAPH_IM; |
$im = IN_PARAGRAPH_IM; |
881 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
882 |
redo A; |
redo A; |
883 |
} elsif ($token->{type} == COMMENT_PARAGRAPH_START_TOKEN) { |
} elsif ($token->{type} == COMMENT_PARAGRAPH_START_TOKEN) { |
884 |
my $el = $doc->create_element_ns (SW10_NS, 'comment-p'); |
my $el = $doc->create_element_ns (SW10_NS, [undef, 'comment-p']); |
885 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
886 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
887 |
|
|
889 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
890 |
redo A; |
redo A; |
891 |
} elsif ($token->{type} == EDITORIAL_NOTE_START_TOKEN) { |
} elsif ($token->{type} == EDITORIAL_NOTE_START_TOKEN) { |
892 |
my $el = $doc->create_element_ns (SW10_NS, 'ed'); |
my $el = $doc->create_element_ns (SW10_NS, [undef, 'ed']); |
893 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
894 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
895 |
|
|
924 |
} elsif ($token->{type} == FORM_TOKEN) { |
} elsif ($token->{type} == FORM_TOKEN) { |
925 |
## There is an exact code clone. |
## There is an exact code clone. |
926 |
if ($token->{name} eq 'form') { |
if ($token->{name} eq 'form') { |
927 |
my $el = $doc->create_element_ns (SW09_NS, 'form'); |
my $el = $doc->create_element_ns (SW09_NS, [undef, 'form']); |
928 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
929 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
930 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
931 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
932 |
|
|
933 |
$el->set_attribute (id => $token->{id}) if defined $token->{id}; |
$el->set_attribute_ns (undef, [undef, 'id'] |
934 |
$el->set_attribute (input => shift @{$token->{parameters}}) |
=> $token->{id}) if defined $token->{id}; |
935 |
|
$el->set_attribute_ns (undef, [undef, 'input'] |
936 |
|
=> shift @{$token->{parameters}}) |
937 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
938 |
$el->set_attribute (template => shift @{$token->{parameters}}) |
$el->set_attribute_ns (undef, [undef, 'template'] |
939 |
|
=> shift @{$token->{parameters}}) |
940 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
941 |
$el->set_attribute (option => shift @{$token->{parameters}}) |
$el->set_attribute_ns (undef, [undef, 'option'] |
942 |
|
=> shift @{$token->{parameters}}) |
943 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
944 |
$el->set_attribute (parameter => join ':', @{$token->{parameters}}) |
$el->set_attribute_ns (undef, [undef, 'parameter'] |
945 |
|
=> join ':', @{$token->{parameters}}) |
946 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
947 |
|
|
948 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
949 |
redo A; |
redo A; |
950 |
} else { |
} else { |
951 |
my $el = $doc->create_element_ns (SW09_NS, 'form'); |
my $el = $doc->create_element_ns (SW09_NS, [undef, 'form']); |
952 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
953 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
954 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
955 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
956 |
|
|
957 |
$el->set_attribute (ref => $token->{name}); |
$el->set_attribute_ns (undef, [undef, 'ref'] => $token->{name}); |
958 |
$el->set_attribute (id => $token->{id}) if defined $token->{id}; |
$el->set_attribute_ns (undef, [undef, 'id'] |
959 |
$el->set_attribute (parameter => join ':', @{$token->{parameters}}) |
=> $token->{id}) if defined $token->{id}; |
960 |
|
$el->set_attribute_ns (undef, [undef, 'parameter'] |
961 |
|
=> join ':', @{$token->{parameters}}) |
962 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
963 |
|
|
964 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
968 |
$token->{local_name} eq 'replace') { |
$token->{local_name} eq 'replace') { |
969 |
## NOTE: There is an exact code clone. |
## NOTE: There is an exact code clone. |
970 |
my $el = $doc->create_element_ns |
my $el = $doc->create_element_ns |
971 |
($token->{namespace}, $token->{local_name}); |
($token->{namespace}, [undef, $token->{local_name}]); |
972 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
973 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
974 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
975 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
976 |
|
|
977 |
$el->set_attribute_ns (SW09_NS, 'sw:anchor', $token->{anchor}) |
$el->set_attribute_ns (SW09_NS, ['sw', 'anchor'], $token->{anchor}) |
978 |
if defined $token->{anchor}; |
if defined $token->{anchor}; |
979 |
$el->set_attribute (by => $token->{by}) if defined $token->{by}; |
$el->set_attribute_ns (undef, [undef, 'by'] |
980 |
$el->set_attribute_ns (SW09_NS, 'sw:resScheme', $token->{res_scheme}) |
=> $token->{by}) if defined $token->{by}; |
981 |
|
$el->set_attribute_ns (SW09_NS, ['sw', 'resScheme'], |
982 |
|
$token->{res_scheme}) |
983 |
if defined $token->{res_scheme}; |
if defined $token->{res_scheme}; |
984 |
$el->set_attribute_ns (SW09_NS, 'sw:resParameter', |
$el->set_attribute_ns (SW09_NS, ['sw', 'resParameter'], |
985 |
$token->{res_parameter}) |
$token->{res_parameter}) |
986 |
if defined $token->{res_parameter}; |
if defined $token->{res_parameter}; |
987 |
$el->text_content ($token->{content}) if defined $token->{content}; |
$el->text_content ($token->{content}) if defined $token->{content}; |
999 |
TABLE_COLSPAN_CELL_TOKEN => 1}->{$token->{type}}) { |
TABLE_COLSPAN_CELL_TOKEN => 1}->{$token->{type}}) { |
1000 |
## NOTE: Ignore the token. |
## NOTE: Ignore the token. |
1001 |
} else { |
} else { |
1002 |
my $el = $doc->create_element_ns (HTML_NS, 'p'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'p']); |
1003 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
1004 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
1005 |
|
|
1009 |
} |
} |
1010 |
} elsif ($im == IN_TABLE_ROW_IM) { |
} elsif ($im == IN_TABLE_ROW_IM) { |
1011 |
if ($token->{type} == TABLE_CELL_START_TOKEN) { |
if ($token->{type} == TABLE_CELL_START_TOKEN) { |
1012 |
my $el = $doc->create_element_ns (HTML_NS, 'td'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'td']); |
1013 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
1014 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
1015 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
1021 |
} elsif ($token->{type} == TABLE_COLSPAN_CELL_TOKEN) { |
} elsif ($token->{type} == TABLE_COLSPAN_CELL_TOKEN) { |
1022 |
my $lc = $oe->[-1]->{node}->last_child; |
my $lc = $oe->[-1]->{node}->last_child; |
1023 |
if ($lc and $lc->manakai_local_name eq 'td') { |
if ($lc and $lc->manakai_local_name eq 'td') { |
1024 |
$lc->set_attribute |
$lc->set_attribute_ns |
1025 |
(colspan => ($lc->get_attribute ('colspan') || 0) + 1); |
(undef, [undef, 'colspan'], |
1026 |
|
($lc->get_attribute_ns (undef, 'colspan') || 0) + 1); |
1027 |
} else { |
} else { |
1028 |
my $el = $doc->create_element_ns (SW10_NS, 'td'); |
my $el = $doc->create_element_ns (SW10_NS, [undef, 'td']); |
1029 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
1030 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
1031 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
1038 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
1039 |
redo A; |
redo A; |
1040 |
} elsif ($token->{type} == TABLE_ROW_START_TOKEN) { |
} elsif ($token->{type} == TABLE_ROW_START_TOKEN) { |
1041 |
my $el = $doc->create_element_ns (HTML_NS, 'tr'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'tr']); |
1042 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
1043 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
1044 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |