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 |
} |
} |
205 |
line => $line, column => $column}; |
line => $line, column => $column}; |
206 |
$column += 4; |
$column += 4; |
207 |
} |
} |
208 |
} elsif ($$s =~ s/^([^<>\['_]+)//) { |
} elsif ($$s =~ s/^([^<>\[\]'_]+)//) { |
209 |
push @nt, {type => CHARACTER_TOKEN, data => $1, |
push @nt, {type => CHARACTER_TOKEN, data => $1, |
210 |
line => $line, column => $column}; |
line => $line, column => $column}; |
211 |
$column += $+[0] - $-[0]; |
$column += $+[0] - $-[0]; |
258 |
} |
} |
259 |
} |
} |
260 |
return shift @nt; |
return shift @nt; |
261 |
} elsif ($s =~ s/^(\*+)\s*//) { |
} elsif ($s =~ s/^(\*+)[\x09\x20]*//) { |
262 |
push @nt, {type => HEADING_START_TOKEN, depth => length $1, |
push @nt, {type => HEADING_START_TOKEN, depth => length $1, |
263 |
line => $line, column => $column}; |
line => $line, column => $column}; |
264 |
$column += $+[0] - $-[0]; |
$column += $+[0] - $-[0]; |
267 |
line => $line, column => $column}; |
line => $line, column => $column}; |
268 |
undef $continuous_line; |
undef $continuous_line; |
269 |
return shift @nt; |
return shift @nt; |
270 |
} elsif ($s =~ s/^([-=]+)\s*//) { |
} elsif ($s =~ s/^([-=]+)[\x09\x20]*//) { |
271 |
push @nt, {type => LIST_START_TOKEN, depth => $1, |
push @nt, {type => LIST_START_TOKEN, depth => $1, |
272 |
line => $line, column => $column}; |
line => $line, column => $column}; |
273 |
$column += $+[0] - $-[0]; |
$column += $+[0] - $-[0]; |
288 |
$name =~ s/\A[\x09\x20]*//; |
$name =~ s/\A[\x09\x20]*//; |
289 |
$column += 1 + $+[0] - $-[0]; |
$column += 1 + $+[0] - $-[0]; |
290 |
$name =~ s/[\x09\x20]+\z//; |
$name =~ s/[\x09\x20]+\z//; |
291 |
$tokenize_text->(\$s); |
$tokenize_text->(\$name); |
292 |
$column = $real_column; |
$column = $real_column; |
293 |
push @nt, {type => LABELED_LIST_MIDDLE_TOKEN, |
push @nt, {type => LABELED_LIST_MIDDLE_TOKEN, |
294 |
line => $line, column => $column}; |
line => $line, column => $column}; |
305 |
if $continuous_line; |
if $continuous_line; |
306 |
$s = '>>' . $s; |
$s = '>>' . $s; |
307 |
$tokenize_text->(\$s); |
$tokenize_text->(\$s); |
308 |
|
$continuous_line = 1; |
309 |
} else { |
} else { |
310 |
push @nt, {type => QUOTATION_START_TOKEN, depth => $depth, |
push @nt, {type => QUOTATION_START_TOKEN, depth => $depth, |
311 |
line => $line, column => $column}; |
line => $line, column => $column}; |
315 |
push @nt, {type => EDITORIAL_NOTE_START_TOKEN, |
push @nt, {type => EDITORIAL_NOTE_START_TOKEN, |
316 |
line => $line, column => $column}; |
line => $line, column => $column}; |
317 |
$column += $+[0] - $-[0]; |
$column += $+[0] - $-[0]; |
318 |
|
$continuous_line = 1; |
319 |
} elsif ($s =~ s/^;;[\x09\x20]*//) { |
} elsif ($s =~ s/^;;[\x09\x20]*//) { |
320 |
push @nt, {type => COMMENT_PARAGRAPH_START_TOKEN, |
push @nt, {type => COMMENT_PARAGRAPH_START_TOKEN, |
321 |
line => $line, column => $column}; |
line => $line, column => $column}; |
322 |
$column += $+[0] - $-[0]; |
$column += $+[0] - $-[0]; |
323 |
|
$continuous_line = 1; |
324 |
|
} elsif (length $s) { |
325 |
|
$continuous_line = 1; |
326 |
|
} else { |
327 |
|
$continuous_line = 0; |
328 |
} |
} |
329 |
$tokenize_text->(\$s); |
$tokenize_text->(\$s); |
330 |
} |
} |
|
$continuous_line = 1; |
|
331 |
return shift @nt; |
return shift @nt; |
332 |
} elsif ($s =~ /\A\[(INS|DEL)(?>\(([^()\\]*)\))?\[[\x09\x20]*\z/) { |
} elsif ($s =~ /\A\[(INS|DEL)(?>\(([^()\\]*)\))?\[[\x09\x20]*\z/) { |
333 |
undef $continuous_line; |
undef $continuous_line; |
368 |
line => $line, column => $column}; |
line => $line, column => $column}; |
369 |
$column += $+[0] - $-[0]; |
$column += $+[0] - $-[0]; |
370 |
$tokenize_text->(\$s); |
$tokenize_text->(\$s); |
371 |
undef $continuous_line; |
$continuous_line = 1; |
372 |
return shift @nt; |
return shift @nt; |
373 |
} elsif ($s =~ /\A\](INS|DEL)\][\x09\x20]*\z/) { |
} elsif ($s =~ /\A\](INS|DEL)\][\x09\x20]*\z/) { |
374 |
$continuous_line = 1; |
$continuous_line = 1; |
422 |
undef $continuous_line; |
undef $continuous_line; |
423 |
return shift @nt; |
return shift @nt; |
424 |
} elsif ($s eq '__IMAGE__') { |
} elsif ($s eq '__IMAGE__') { |
425 |
my $image = $doc->create_element_ns (SW09_NS, 'image'); |
my $image = $doc->create_element_ns (SW09_NS, [undef, 'image']); |
426 |
$image->set_user_data (manakai_source_line => $line); |
$image->set_user_data (manakai_source_line => $line); |
427 |
$image->set_user_data (manakai_source_column => 1); |
$image->set_user_data (manakai_source_column => 1); |
428 |
$image->text_content (join "\x0A", $s, @s); |
$image->text_content (join "\x0A", $s, @s); |
438 |
$continuous_line = 1; |
$continuous_line = 1; |
439 |
return shift @nt; |
return shift @nt; |
440 |
} |
} |
441 |
}; # $get_next_token_body |
}; # $get_next_token |
442 |
|
|
443 |
## NOTE: The "initial" mode. |
## NOTE: The "initial" mode. |
444 |
if (@s and $s[0] =~ /^#\?/) { |
if (@s and $s[0] =~ s/^#\?//) { |
445 |
## NOTE: "Parse a magic line". |
## NOTE: "Parse a magic line". |
446 |
|
|
447 |
my $s = shift @s; |
my $s = shift @s; |
449 |
$column += $+[0] - $-[0]; |
$column += $+[0] - $-[0]; |
450 |
my ($name, $version) = split m#/#, $1, 2; |
my ($name, $version) = split m#/#, $1, 2; |
451 |
my $el = $doc->document_element; |
my $el = $doc->document_element; |
452 |
$el->set_attribute_ns (SW09_NS, 'sw:Name' => $name); |
$el->set_attribute_ns (SW09_NS, ['sw', 'Name'] => $name); |
453 |
$el->set_attribute_ns (SW09_NS, 'sw:Version' => $version) |
$el->set_attribute_ns (SW09_NS, ['sw', 'Version'] => $version) |
454 |
if defined $version; |
if defined $version; |
455 |
} |
} |
456 |
|
|
|
my $head = $doc->first_child; |
|
457 |
while (length $s) { |
while (length $s) { |
458 |
$column += $+[0] - $-[0] if $s =~ s/^[\x09\x20]+//; |
$column += $+[0] - $-[0] and next if $s =~ s/^[\x09\x20]+//; |
459 |
my $name = ''; |
my $name = ''; |
460 |
if ($s =~ s/^([^=]*)=//) { |
if ($s =~ s/^([^=]*)=//) { |
461 |
$name = $1; |
$name = $1; |
462 |
$column += length $name + 1; |
$column += length $name + 1; |
463 |
} |
} |
464 |
my $param = $doc->create_element_ns (SW09_NS, 'parameter'); |
my $param = $doc->create_element_ns (SW09_NS, [undef, 'parameter']); |
465 |
$param->set_attribute (name => $name); |
$param->set_attribute_ns (undef, [undef, 'name'] => $name); |
466 |
$param->set_user_data (manakai_source_line => $line); |
$param->set_user_data (manakai_source_line => $line); |
467 |
$param->set_user_data (manakai_source_column => $column); |
$param->set_user_data (manakai_source_column => $column); |
468 |
$head->append_child ($param); |
$head_el->append_child ($param); |
469 |
|
|
470 |
$column++ if $s =~ s/^"//; |
$column++ if $s =~ s/^"//; |
471 |
if ($s =~ s/^([^"]+)//) { |
if ($s =~ s/^([^"]*)//) { |
472 |
my $values = $1; |
my $values = $1; |
473 |
$column += length $values; |
$column += length $values; |
474 |
$values =~ tr/\\//d; |
$values =~ tr/\\//d; |
475 |
for (split /,/, $values, -1) { |
my @values = split /,/, $values, -1; |
476 |
my $value = $doc->create_element_ns (SW09_NS, 'value'); |
push @values, '' unless length $values; |
477 |
|
for (@values) { |
478 |
|
my $value = $doc->create_element_ns (SW09_NS, [undef, 'value']); |
479 |
$value->text_content ($_); |
$value->text_content ($_); |
480 |
$value->set_user_data (manakai_source_line => $line); |
$value->set_user_data (manakai_source_line => $line); |
481 |
$value->set_user_data (manakai_source_column => $column); |
$value->set_user_data (manakai_source_column => $column); |
491 |
|
|
492 |
## NOTE: Switched to the "body" mode. |
## NOTE: Switched to the "body" mode. |
493 |
|
|
494 |
my $oe = [{node => $doc->document_element->last_child, |
my $oe = [{node => $body_el, |
495 |
section_depth => 0, |
section_depth => 0, |
496 |
quotation_depth => 0, |
quotation_depth => 0, |
497 |
list_depth => 0}]; |
list_depth => 0}]; |
503 |
}; |
}; |
504 |
|
|
505 |
my $im = IN_SECTION_IM; |
my $im = IN_SECTION_IM; |
506 |
$get_next_token->(); |
$token = $get_next_token->(); |
507 |
|
|
508 |
A: { |
A: { |
509 |
if ($im == IN_PARAGRAPH_IM) { |
if ($im == IN_PARAGRAPH_IM) { |
510 |
if ($token->{type} == CHARACTER_TOKEN) { |
if ($token->{type} == CHARACTER_TOKEN) { |
511 |
$oe->[-1]->{node}->manakai_append_text ($token->{data}); |
$oe->[-1]->{node}->manakai_append_text ($token->{data}); |
512 |
$get_next_token->(); |
$token = $get_next_token->(); |
513 |
redo A; |
redo A; |
514 |
} elsif ($token->{type} == INLINE_START_TAG_TOKEN) { |
} elsif ($token->{type} == INLINE_START_TAG_TOKEN) { |
515 |
if (not defined $token->{tag_name}) { |
if (not defined $token->{tag_name}) { |
516 |
my $el = $doc->create_element_ns (SW09_NS, 'anchor'); |
my $el = $doc->create_element_ns (SW09_NS, [undef, 'anchor']); |
517 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
518 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
519 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
520 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
521 |
|
|
522 |
$get_next_token->(); |
$token = $get_next_token->(); |
523 |
redo A; |
redo A; |
524 |
} else { |
} else { |
525 |
my $type = { |
my $type = { |
546 |
VAR => [HTML_NS, 'var'], |
VAR => [HTML_NS, 'var'], |
547 |
WEAK => [SW09_NS, 'weak'], |
WEAK => [SW09_NS, 'weak'], |
548 |
}->{$token->{tag_name}} || [SW10_NS, $token->{tag_name}]; |
}->{$token->{tag_name}} || [SW10_NS, $token->{tag_name}]; |
549 |
my $el = $doc->create_element_ns (SW10_NS, 'td'); |
my $el = $doc->create_element_ns ($type->[0], [undef, $type->[1]]); |
550 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
551 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
552 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
553 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
554 |
|
|
555 |
$el->set_attribute (class => $token->{classes}) |
$el->set_attribute_ns (undef, [undef, 'class'] => $token->{classes}) |
556 |
if defined $token->{classes}; |
if defined $token->{classes}; |
557 |
$el->set_attribute_ns (XML_NS, 'xml:lang' => $token->{language}) |
$el->set_attribute_ns (XML_NS, ['xml', 'lang'] => $token->{language}) |
558 |
if defined $token->{language}; |
if defined $token->{language}; |
559 |
|
|
560 |
$get_next_token->(); |
$token = $get_next_token->(); |
561 |
redo A; |
redo A; |
562 |
} |
} |
563 |
} elsif ($token->{type} == INLINE_MIDDLE_TAG_TOKEN) { |
} elsif ($token->{type} == INLINE_MIDDLE_TAG_TOKEN) { |
564 |
my ($ns, $ln, $pop) = @{{ |
my ($ns, $ln, $pop) = @{{ |
565 |
rt => [SW10_NS, 'attrvalue', 1], |
rt => [HTML_NS, 'rt', 1], |
566 |
title => [SW10_NS, 'attrvalue', 1], |
title => [SW10_NS, 'attrvalue', 1], |
567 |
nsuri => [SW10_NS, 'attrvalue', 1], |
nsuri => [SW10_NS, 'attrvalue', 1], |
568 |
qn => [SW10_NS, 'nsuri'], |
qn => [SW10_NS, 'nsuri'], |
571 |
}->{$oe->[-1]->{node}->manakai_local_name} || [SW10_NS, 'title']}; |
}->{$oe->[-1]->{node}->manakai_local_name} || [SW10_NS, 'title']}; |
572 |
pop @$oe if $pop; |
pop @$oe if $pop; |
573 |
|
|
574 |
my $el = $doc->create_element_ns ($ns, $ln); |
my $el = $doc->create_element_ns ($ns, [undef, $ln]); |
575 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
576 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
577 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
578 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
579 |
|
|
580 |
$el->set_attribute_ns (XML_NS, 'xml:lang' => $token->{language}) |
$el->set_attribute_ns (XML_NS, ['xml', 'lang'] => $token->{language}) |
581 |
if defined $token->{language}; |
if defined $token->{language}; |
582 |
|
|
583 |
$get_next_token->(); |
$token = $get_next_token->(); |
584 |
redo A; |
redo A; |
585 |
} elsif ($token->{type} == INLINE_END_TAG_TOKEN) { |
} elsif ($token->{type} == INLINE_END_TAG_TOKEN) { |
586 |
pop @$oe if { |
pop @$oe if { |
591 |
strong => 1, em => 1}->{$oe->[-1]->{node}->manakai_local_name}) { |
strong => 1, em => 1}->{$oe->[-1]->{node}->manakai_local_name}) { |
592 |
my $el = $doc->create_element_ns |
my $el = $doc->create_element_ns |
593 |
(SW09_NS, |
(SW09_NS, |
594 |
defined $token->{res_scheme} |
[undef, defined $token->{res_scheme} |
595 |
? 'anchor-external' : 'anchor-internal'); |
? 'anchor-external' : 'anchor-internal']); |
596 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
597 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
598 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
600 |
$el->text_content (']]'); |
$el->text_content (']]'); |
601 |
} |
} |
602 |
|
|
603 |
$oe->[-1]->{node}->set_attribute_ns (SW09_NS, 'sw:anchor', |
$oe->[-1]->{node}->set_attribute_ns (SW09_NS, ['sw', 'anchor'], |
604 |
$token->{anchor}) |
$token->{anchor}) |
605 |
if defined $token->{anchor}; |
if defined $token->{anchor}; |
606 |
$oe->[-1]->{node}->set_attribute_ns (SW09_NS, 'sw:resScheme', |
$oe->[-1]->{node}->set_attribute_ns (SW09_NS, ['sw', 'resScheme'], |
607 |
$token->{res_scheme}) |
$token->{res_scheme}) |
608 |
if defined $token->{res_scheme}; |
if defined $token->{res_scheme}; |
609 |
$oe->[-1]->{node}->set_attribute_ns (SW09_NS, 'sw:resParameter', |
$oe->[-1]->{node}->set_attribute_ns (SW09_NS, ['sw', 'resParameter'], |
610 |
$token->{res_parameter}) |
$token->{res_parameter}) |
611 |
if defined $token->{res_parameter}; |
if defined $token->{res_parameter}; |
612 |
|
|
613 |
pop @$oe; |
pop @$oe; |
614 |
|
|
615 |
$get_next_token->(); |
$token = $get_next_token->(); |
616 |
redo A; |
redo A; |
617 |
} elsif ($token->{type} == STRONG_TOKEN) { |
} elsif ($token->{type} == STRONG_TOKEN) { |
618 |
my $el = $doc->create_element_ns (HTML_NS, 'strong'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'strong']); |
619 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
620 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
621 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
622 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
623 |
|
|
624 |
$get_next_token->(); |
$token = $get_next_token->(); |
625 |
redo A; |
redo A; |
626 |
} elsif ($token->{type} == EMPHASIS_TOKEN) { |
} elsif ($token->{type} == EMPHASIS_TOKEN) { |
627 |
my $el = $doc->create_element_ns (HTML_NS, 'em'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'em']); |
628 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
629 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
630 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
631 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
632 |
|
|
633 |
$get_next_token->(); |
$token = $get_next_token->(); |
634 |
redo A; |
redo A; |
635 |
} elsif ($token->{type} == FORM_TOKEN) { |
} elsif ($token->{type} == FORM_TOKEN) { |
636 |
## There is an exact code clone. |
## There is an exact code clone. |
637 |
if ($token->{name} eq 'form') { |
if ($token->{name} eq 'form') { |
638 |
my $el = $doc->create_element_ns (SW09_NS, 'form'); |
my $el = $doc->create_element_ns (SW09_NS, [undef, 'form']); |
639 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
640 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
641 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
642 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
643 |
|
|
644 |
$el->set_attribute (id => $token->{id}) if defined $token->{id}; |
$el->set_attribute_ns (undef, [undef, 'id'] |
645 |
$el->set_attribute (input => shift @{$token->{parameters}}) |
=> $token->{id}) if defined $token->{id}; |
646 |
|
$el->set_attribute_ns (undef, [undef, 'input'] |
647 |
|
=> shift @{$token->{parameters}}) |
648 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
649 |
$el->set_attribute (template => shift @{$token->{parameters}}) |
$el->set_attribute_ns (undef, [undef, 'template'] |
650 |
|
=> shift @{$token->{parameters}}) |
651 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
652 |
$el->set_attribute (option => shift @{$token->{parameters}}) |
$el->set_attribute_ns (undef, [undef, 'option'] |
653 |
|
=> shift @{$token->{parameters}}) |
654 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
655 |
$el->set_attribute (parameter => join ':', @{$token->{parameters}}) |
$el->set_attribute_ns (undef, [undef, 'parameter'] |
656 |
|
=> join ':', @{$token->{parameters}}) |
657 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
658 |
|
|
659 |
$get_next_token->(); |
$token = $get_next_token->(); |
660 |
redo A; |
redo A; |
661 |
} else { |
} else { |
662 |
my $el = $doc->create_element_ns (SW09_NS, 'form'); |
my $el = $doc->create_element_ns (SW09_NS, [undef, 'form']); |
663 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
664 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
665 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
666 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
667 |
|
|
668 |
$el->set_attribute (ref => $token->{name}); |
$el->set_attribute_ns (undef, [undef, 'ref'] |
669 |
$el->set_attribute (id => $token->{id}) if defined $token->{id}; |
=> $token->{name}); |
670 |
$el->set_attribute (parameter => join ':', @{$token->{parameters}}) |
$el->set_attribute_ns (undef, [undef, 'id'] |
671 |
if @{$token->{parameter}}; |
=> $token->{id}) if defined $token->{id}; |
672 |
|
$el->set_attribute_ns (undef, [undef, 'parameter'] |
673 |
|
=> join ':', @{$token->{parameters}}) |
674 |
|
if @{$token->{parameters}}; |
675 |
|
|
676 |
$get_next_token->(); |
$token = $get_next_token->(); |
677 |
redo A; |
redo A; |
678 |
} |
} |
679 |
} elsif ($token->{type} == ELEMENT_TOKEN) { |
} elsif ($token->{type} == ELEMENT_TOKEN) { |
680 |
## NOTE: There is an exact code clone. |
## NOTE: There is an exact code clone. |
681 |
my $el = $doc->create_element_ns |
my $el = $doc->create_element_ns |
682 |
($token->{namespace}, $token->{local_name}); |
($token->{namespace}, [undef, $token->{local_name}]); |
683 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
|
push @$oe, {%{$oe->[-1]}, node => $el}; |
|
684 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
685 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
686 |
|
|
687 |
$el->set_attribute_ns (SW09_NS, 'sw:anchor', $token->{anchor}) |
$el->set_attribute_ns (SW09_NS, ['sw', 'anchor'], $token->{anchor}) |
688 |
if defined $token->{anchor}; |
if defined $token->{anchor}; |
689 |
$el->set_attribute (by => $token->{by}) if defined $token->{by}; |
$el->set_attribute_ns (undef, [undef, 'by'] |
690 |
$el->set_attribute_ns (SW09_NS, 'sw:resScheme', $token->{res_scheme}) |
=> $token->{by}) if defined $token->{by}; |
691 |
|
$el->set_attribute_ns (SW09_NS, ['sw', 'resScheme'], |
692 |
|
$token->{res_scheme}) |
693 |
if defined $token->{res_scheme}; |
if defined $token->{res_scheme}; |
694 |
$el->set_attribute_ns (SW09_NS, 'sw:resParameter', |
$el->set_attribute_ns (SW09_NS, ['sw', 'resParameter'], |
695 |
$token->{res_parameter}) |
$token->{res_parameter}) |
696 |
if defined $token->{res_parameter}; |
if defined $token->{res_parameter}; |
697 |
$el->text_content ($token->{content}) if defined $token->{content}; |
$el->text_content ($token->{content}) if defined $token->{content}; |
698 |
|
|
699 |
$get_next_token->(); |
$token = $get_next_token->(); |
700 |
redo A; |
redo A; |
701 |
} elsif ($token->{type} == LABELED_LIST_MIDDLE_TOKEN) { |
} elsif ($token->{type} == LABELED_LIST_MIDDLE_TOKEN) { |
702 |
pop @$oe while not $structural_elements |
pop @$oe while not $structural_elements |
703 |
->{$oe->[-1]->{node}->manakai_local_name}; |
->{$oe->[-1]->{node}->manakai_local_name}; |
704 |
pop @$oe if $oe->[-1]->{node}->manakai_local_name eq 'dt'; |
pop @$oe if $oe->[-1]->{node}->manakai_local_name eq 'dt'; |
705 |
|
|
706 |
my $el = $doc->create_element_ns (HTML_NS, 'dt'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'dd']); |
707 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
708 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
709 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
710 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
711 |
|
|
712 |
$get_next_token->(); |
$token = $get_next_token->(); |
713 |
redo A; |
redo A; |
714 |
} elsif ($token->{type} == HEADING_END_TOKEN) { |
} elsif ($token->{type} == HEADING_END_TOKEN) { |
715 |
pop @$oe while not $structural_elements |
pop @$oe while not $structural_elements |
717 |
pop @$oe if $oe->[-1]->{node}->manakai_local_name eq 'h1'; |
pop @$oe if $oe->[-1]->{node}->manakai_local_name eq 'h1'; |
718 |
|
|
719 |
$im = IN_SECTION_IM; |
$im = IN_SECTION_IM; |
720 |
$get_next_token->(); |
$token = $get_next_token->(); |
721 |
redo A; |
redo A; |
722 |
} elsif ($token->{type} == TABLE_CELL_END_TOKEN) { |
} elsif ($token->{type} == TABLE_CELL_END_TOKEN) { |
723 |
pop @$oe while not $structural_elements |
pop @$oe while not $structural_elements |
725 |
pop @$oe if $oe->[-1]->{node}->manakai_local_name eq 'td'; |
pop @$oe if $oe->[-1]->{node}->manakai_local_name eq 'td'; |
726 |
|
|
727 |
$im = IN_TABLE_ROW_IM; |
$im = IN_TABLE_ROW_IM; |
728 |
$get_next_token->(); |
$token = $get_next_token->(); |
729 |
redo A; |
redo A; |
730 |
} elsif (($token->{type} == BLOCK_END_TAG_TOKEN and |
} elsif (($token->{type} == BLOCK_END_TAG_TOKEN and |
731 |
$token->{tag_name} eq 'PRE') or |
$token->{tag_name} eq 'PRE') or |
735 |
pop @$oe if $oe->[-1]->{node}->manakai_local_name eq 'pre'; |
pop @$oe if $oe->[-1]->{node}->manakai_local_name eq 'pre'; |
736 |
|
|
737 |
$im = IN_SECTION_IM; |
$im = IN_SECTION_IM; |
738 |
$get_next_token->(); |
$token = $get_next_token->(); |
739 |
redo A; |
redo A; |
740 |
} else { |
} else { |
741 |
pop @$oe while not $structural_elements |
pop @$oe while not $structural_elements |
742 |
->{$oe->[-1]->{node}->manakai_local_name}; |
->{$oe->[-1]->{node}->manakai_local_name}; |
743 |
|
|
744 |
$im = IN_SECTION_IM; |
$im = IN_SECTION_IM; |
745 |
$get_next_token->(); |
## Reconsume. |
746 |
redo A; |
redo A; |
747 |
} |
} |
748 |
} elsif ($im == IN_SECTION_IM) { |
} elsif ($im == IN_SECTION_IM) { |
749 |
if ($token->{type} == HEADING_START_TOKEN) { |
if ($token->{type} == HEADING_START_TOKEN) { |
750 |
B: { |
B: { |
751 |
pop @$oe and redo B |
pop @$oe and redo B |
752 |
if {body => 1, section => 1, insert => 1, delete => 1} |
if not {body => 1, section => 1, insert => 1, delete => 1} |
753 |
->{$oe->[-1]->{node}->manakai_local_name} or |
->{$oe->[-1]->{node}->manakai_local_name} or |
754 |
$token->{depth} <= $oe->[-1]->{section_depth}; |
$token->{depth} <= $oe->[-1]->{section_depth}; |
755 |
if ($token->{depth} > $oe->[-1]->{section_depth} + 1) { |
if ($token->{depth} > $oe->[-1]->{section_depth} + 1) { |
756 |
my $el = $doc->create_element_ns (HTML_NS, 'section'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'section']); |
757 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
758 |
push @$oe, {node => $el, |
push @$oe, {node => $el, |
759 |
section_depth => $oe->[-1]->{section_depth} + 1, |
section_depth => $oe->[-1]->{section_depth} + 1, |
762 |
} |
} |
763 |
} # B |
} # B |
764 |
|
|
765 |
my $el = $doc->create_element_ns (HTML_NS, 'section'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'section']); |
766 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
767 |
push @$oe, {node => $el, |
push @$oe, {node => $el, |
768 |
section_depth => $oe->[-1]->{section_depth} + 1, |
section_depth => $oe->[-1]->{section_depth} + 1, |
769 |
quotation_depth => 0, list_depth => 0}; |
quotation_depth => 0, list_depth => 0}; |
770 |
|
|
771 |
my $el2 = $doc->create_element_ns (HTML_NS, 'h1'); |
my $el2 = $doc->create_element_ns (HTML_NS, [undef, 'h1']); |
772 |
$oe->[-1]->{node}->append_child ($el2); |
$oe->[-1]->{node}->append_child ($el2); |
773 |
push @$oe, {%{$oe->[-1]}, node => $el2}; |
push @$oe, {%{$oe->[-1]}, node => $el2}; |
774 |
|
|
775 |
$im = IN_PARAGRAPH_IM; |
$im = IN_PARAGRAPH_IM; |
776 |
$get_next_token->(); |
$token = $get_next_token->(); |
777 |
redo A; |
redo A; |
778 |
} elsif ($token->{type} == BLOCK_START_TAG_TOKEN and |
} elsif ($token->{type} == BLOCK_START_TAG_TOKEN and |
779 |
($token->{tag_name} eq 'INS' or |
($token->{tag_name} eq 'INS' or |
780 |
$token->{tag_name} eq 'DEL')) { |
$token->{tag_name} eq 'DEL')) { |
781 |
my $el = $doc->create_element_ns |
my $el = $doc->create_element_ns |
782 |
(SW09_NS, ($token->{tag_name} eq 'INS' ? 'insert' : 'delete')); |
(SW09_NS, |
783 |
|
[undef, $token->{tag_name} eq 'INS' ? 'insert' : 'delete']); |
784 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
785 |
push @$oe, {node => $el, section_depth => 0, |
push @$oe, {node => $el, section_depth => 0, |
786 |
quotation_depth => 0, list_depth => 0}; |
quotation_depth => 0, list_depth => 0}; |
787 |
$el->set_attribute (class => $token->{classes}) |
$el->set_attribute_ns (undef, [undef, 'class'] => $token->{classes}) |
788 |
if defined $token->{classes}; |
if defined $token->{classes}; |
789 |
$get_next_token->(); |
$token = $get_next_token->(); |
790 |
redo A; |
redo A; |
791 |
} elsif ($token->{type} == QUOTATION_START_TOKEN) { |
} elsif ($token->{type} == QUOTATION_START_TOKEN) { |
792 |
B: { |
B: { |
793 |
pop @$oe and redo B |
pop @$oe and redo B |
794 |
if {body => 1, section => 1, insert => 1, delete => 1, |
if not {body => 1, section => 1, insert => 1, delete => 1, |
795 |
blockquote => 1} |
blockquote => 1} |
796 |
->{$oe->[-1]->{node}->manakai_local_name} or |
->{$oe->[-1]->{node}->manakai_local_name} or |
797 |
$token->{depth} <= $oe->[-1]->{quotation_depth}; |
$token->{depth} < $oe->[-1]->{quotation_depth}; |
798 |
if ($token->{depth} > $oe->[-1]->{quotation_depth} + 1) { |
if ($token->{depth} > $oe->[-1]->{quotation_depth}) { |
799 |
my $el = $doc->create_element_ns (HTML_NS, 'blockquote'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'blockquote']); |
800 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
801 |
push @$oe, {node => $el, section_depth => 0, |
push @$oe, {node => $el, section_depth => 0, |
802 |
quotation_depth => $oe->[-1]->{quotation_depth} + 1, |
quotation_depth => $oe->[-1]->{quotation_depth} + 1, |
805 |
} |
} |
806 |
} # B |
} # B |
807 |
|
|
808 |
my $el = $doc->create_element_ns (HTML_NS, 'blockquote'); |
$token = $get_next_token->(); |
|
$oe->[-1]->{node}->append_child ($el); |
|
|
push @$oe, {node => $el, section_depth => 0, |
|
|
quotation_depth => $oe->[-1]->{quotation_depth} + 1, |
|
|
list_depth => 0}; |
|
|
|
|
|
$get_next_token->(); |
|
809 |
redo A; |
redo A; |
810 |
} elsif ($token->{type} == LIST_START_TOKEN) { |
} elsif ($token->{type} == LIST_START_TOKEN) { |
811 |
my $depth = length $token->{depth}; |
my $depth = length $token->{depth}; |
812 |
|
my $list_type = substr ($token->{depth}, -1, 1) eq '-' ? 'ul' : 'ol'; |
813 |
B: { |
B: { |
814 |
pop @$oe and redo B if $oe->[-1]->{list_depth} > $depth; |
pop @$oe and redo B if $oe->[-1]->{list_depth} > $depth; |
815 |
|
pop @$oe and redo B if $oe->[-1]->{list_depth} == $depth and |
816 |
|
$list_type ne $oe->[-1]->{node}->manakai_local_name; |
817 |
if ($oe->[-1]->{list_depth} < $depth) { |
if ($oe->[-1]->{list_depth} < $depth) { |
818 |
my $type = substr $token->{depth}, $oe->[-1]->{list_depth}; |
my $type = substr $token->{depth}, $oe->[-1]->{list_depth}, 1; |
819 |
my $el = $doc->create_element_ns |
my $el = $doc->create_element_ns |
820 |
(HTML_NS, $type eq '-' ? 'ul' : 'ol'); |
(HTML_NS, [undef, $type eq '-' ? 'ul' : 'ol']); |
821 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
822 |
push @$oe, {%{$oe->[-1]}, node => $el, |
push @$oe, {%{$oe->[-1]}, node => $el, |
823 |
list_depth => $oe->[-1]->{list_depth} + 1}; |
list_depth => $oe->[-1]->{list_depth} + 1}; |
824 |
if ($oe->[-1]->{list_depth} < $depth) { |
if ($oe->[-1]->{list_depth} < $depth) { |
825 |
my $el = $doc->create_element_ns (HTML_NS, 'li'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'li']); |
826 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
827 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
828 |
} |
} |
829 |
redo B; |
redo B; |
830 |
} |
} |
831 |
} # B |
} # B |
|
|
|
|
pop @$oe if $oe->[-1]->{list_depth} == $depth and |
|
|
not {ul => 1, ol => 1}->{$oe->[-1]->{node}->manakai_local_name}; |
|
832 |
|
|
833 |
my $el = $doc->create_element_ns (HTML_NS, 'li'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'li']); |
834 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
835 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
836 |
|
|
837 |
$im = IN_PARAGRAPH_IM; |
$im = IN_PARAGRAPH_IM; |
838 |
$get_next_token->(); |
$token = $get_next_token->(); |
839 |
redo A; |
redo A; |
840 |
} elsif ($token->{type} == LABELED_LIST_START_TOKEN) { |
} elsif ($token->{type} == LABELED_LIST_START_TOKEN) { |
841 |
pop @$oe if $oe->[-1]->{node}->manakai_local_name eq 'dd'; |
pop @$oe if $oe->[-1]->{node}->manakai_local_name eq 'dd'; |
842 |
if ($oe->[-1]->{node}->manakai_local_name ne 'dl') { |
if ($oe->[-1]->{node}->manakai_local_name ne 'dl') { |
843 |
my $el = $doc->create_element_ns (HTML_NS, 'dl'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'dl']); |
844 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
845 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
846 |
} |
} |
847 |
|
|
848 |
my $el = $doc->create_element_ns (HTML_NS, 'dt'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'dt']); |
849 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
850 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
851 |
|
|
852 |
$im = IN_PARAGRAPH_IM; |
$im = IN_PARAGRAPH_IM; |
853 |
$get_next_token->(); |
$token = $get_next_token->(); |
854 |
redo A; |
redo A; |
855 |
} elsif ($token->{type} == TABLE_ROW_START_TOKEN) { |
} elsif ($token->{type} == TABLE_ROW_START_TOKEN) { |
856 |
my $el = $doc->create_element_ns (HTML_NS, 'table'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'table']); |
857 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
858 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
859 |
|
|
860 |
$el = $doc->create_element_ns (HTML_NS, 'tbody'); |
$el = $doc->create_element_ns (HTML_NS, [undef, 'tbody']); |
861 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
862 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
863 |
|
|
864 |
$el = $doc->create_element_ns (HTML_NS, 'tr'); |
$el = $doc->create_element_ns (HTML_NS, [undef, 'tr']); |
865 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
866 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
867 |
|
|
868 |
$im = IN_TABLE_ROW_IM; |
$im = IN_TABLE_ROW_IM; |
869 |
$get_next_token->(); |
$token = $get_next_token->(); |
870 |
redo A; |
redo A; |
871 |
} elsif (($token->{type} == BLOCK_START_TAG_TOKEN and |
} elsif (($token->{type} == BLOCK_START_TAG_TOKEN and |
872 |
$token->{tag_name} eq 'PRE') or |
$token->{tag_name} eq 'PRE') or |
873 |
$token->{type} == PREFORMATTED_START_TOKEN) { |
$token->{type} == PREFORMATTED_START_TOKEN) { |
874 |
my $el = $doc->create_element_ns (HTML_NS, 'pre'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'pre']); |
875 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
876 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
877 |
|
|
878 |
$el->set_attribute (class => $token->{classes}) |
$el->set_attribute_ns (undef, [undef, 'class'] => $token->{classes}) |
879 |
if defined $token->{classes}; |
if defined $token->{classes}; |
880 |
|
|
881 |
$im = IN_PARAGRAPH_IM; |
$im = IN_PARAGRAPH_IM; |
882 |
$get_next_token->(); |
$token = $get_next_token->(); |
883 |
redo A; |
redo A; |
884 |
} elsif ($token->{type} == COMMENT_PARAGRAPH_START_TOKEN) { |
} elsif ($token->{type} == COMMENT_PARAGRAPH_START_TOKEN) { |
885 |
my $el = $doc->create_element_ns (SW10_NS, 'comment-p'); |
my $el = $doc->create_element_ns (SW10_NS, [undef, 'comment-p']); |
886 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
887 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
888 |
|
|
889 |
$im = IN_PARAGRAPH_IM; |
$im = IN_PARAGRAPH_IM; |
890 |
$get_next_token->(); |
$token = $get_next_token->(); |
891 |
redo A; |
redo A; |
892 |
} elsif ($token->{type} == EDITORIAL_NOTE_START_TOKEN) { |
} elsif ($token->{type} == EDITORIAL_NOTE_START_TOKEN) { |
893 |
my $el = $doc->create_element_ns (SW10_NS, 'ed'); |
my $el = $doc->create_element_ns (SW10_NS, [undef, 'ed']); |
894 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
895 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
896 |
|
|
897 |
$im = IN_PARAGRAPH_IM; |
$im = IN_PARAGRAPH_IM; |
898 |
$get_next_token->(); |
$token = $get_next_token->(); |
899 |
redo A; |
redo A; |
900 |
} elsif ($token->{type} == EMPTY_LINE_TOKEN) { |
} elsif ($token->{type} == EMPTY_LINE_TOKEN) { |
901 |
pop @$oe while {body => 1, section => 1, insert => 1, delete => 1} |
pop @$oe while not {body => 1, section => 1, insert => 1, delete => 1} |
902 |
->{$oe->[-1]->{node}->manakai_local_name}; |
->{$oe->[-1]->{node}->manakai_local_name}; |
903 |
$get_next_token->(); |
$token = $get_next_token->(); |
904 |
redo A; |
redo A; |
905 |
} elsif ($token->{type} == BLOCK_END_TAG_TOKEN) { |
} elsif ($token->{type} == BLOCK_END_TAG_TOKEN) { |
906 |
if ($token->{type} eq 'INS') { |
if ($token->{tag_name} eq 'INS') { |
907 |
for (reverse 1..$#$oe) { |
for (reverse 1..$#$oe) { |
908 |
if ($oe->[$_]->{node}->manakai_local_name eq 'insert') { |
if ($oe->[$_]->{node}->manakai_local_name eq 'insert') { |
909 |
splice @$oe, $_; |
splice @$oe, $_; |
910 |
last; |
last; |
911 |
} |
} |
912 |
} |
} |
913 |
} elsif ($token->{type} eq 'DEL') { |
} elsif ($token->{tag_name} eq 'DEL') { |
914 |
for (reverse 1..$#$oe) { |
for (reverse 1..$#$oe) { |
915 |
if ($oe->[$_]->{node}->manakai_local_name eq 'delete') { |
if ($oe->[$_]->{node}->manakai_local_name eq 'delete') { |
916 |
splice @$oe, $_; |
splice @$oe, $_; |
920 |
} else { |
} else { |
921 |
## NOTE: Ignore the token. |
## NOTE: Ignore the token. |
922 |
} |
} |
923 |
|
undef $continuous_line; |
924 |
|
$token = $get_next_token->(); |
925 |
|
redo A; |
926 |
} elsif ($token->{type} == FORM_TOKEN) { |
} elsif ($token->{type} == FORM_TOKEN) { |
927 |
## There is an exact code clone. |
## There is an exact code clone. |
928 |
if ($token->{name} eq 'form') { |
if ($token->{name} eq 'form') { |
929 |
my $el = $doc->create_element_ns (SW09_NS, 'form'); |
my $el = $doc->create_element_ns (SW09_NS, [undef, 'form']); |
930 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
931 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
932 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
933 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
934 |
|
|
935 |
$el->set_attribute (id => $token->{id}) if defined $token->{id}; |
$el->set_attribute_ns (undef, [undef, 'id'] |
936 |
$el->set_attribute (input => shift @{$token->{parameters}}) |
=> $token->{id}) if defined $token->{id}; |
937 |
|
$el->set_attribute_ns (undef, [undef, 'input'] |
938 |
|
=> shift @{$token->{parameters}}) |
939 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
940 |
$el->set_attribute (template => shift @{$token->{parameters}}) |
$el->set_attribute_ns (undef, [undef, 'template'] |
941 |
|
=> shift @{$token->{parameters}}) |
942 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
943 |
$el->set_attribute (option => shift @{$token->{parameters}}) |
$el->set_attribute_ns (undef, [undef, 'option'] |
944 |
|
=> shift @{$token->{parameters}}) |
945 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
946 |
$el->set_attribute (parameter => join ':', @{$token->{parameters}}) |
$el->set_attribute_ns (undef, [undef, 'parameter'] |
947 |
|
=> join ':', @{$token->{parameters}}) |
948 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
949 |
|
|
950 |
$get_next_token->(); |
$token = $get_next_token->(); |
951 |
redo A; |
redo A; |
952 |
} else { |
} else { |
953 |
my $el = $doc->create_element_ns (SW09_NS, 'form'); |
my $el = $doc->create_element_ns (SW09_NS, [undef, 'form']); |
954 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
955 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
956 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
957 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
958 |
|
|
959 |
$el->set_attribute (ref => $token->{name}); |
$el->set_attribute_ns (undef, [undef, 'ref'] => $token->{name}); |
960 |
$el->set_attribute (id => $token->{id}) if defined $token->{id}; |
$el->set_attribute_ns (undef, [undef, 'id'] |
961 |
$el->set_attribute (parameter => join ':', @{$token->{parameters}}) |
=> $token->{id}) if defined $token->{id}; |
962 |
|
$el->set_attribute_ns (undef, [undef, 'parameter'] |
963 |
|
=> join ':', @{$token->{parameters}}) |
964 |
if @{$token->{parameter}}; |
if @{$token->{parameter}}; |
965 |
|
|
966 |
$get_next_token->(); |
$token = $get_next_token->(); |
967 |
redo A; |
redo A; |
968 |
} |
} |
969 |
} elsif ($token->{type} == ELEMENT_TOKEN and |
} elsif ($token->{type} == ELEMENT_TOKEN and |
970 |
$token->{local_name} eq 'replace') { |
$token->{local_name} eq 'replace') { |
971 |
## NOTE: There is an exact code clone. |
## NOTE: There is an exact code clone. |
972 |
my $el = $doc->create_element_ns |
my $el = $doc->create_element_ns |
973 |
($token->{namespace}, $token->{local_name}); |
($token->{namespace}, [undef, $token->{local_name}]); |
974 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
975 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
976 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
977 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
978 |
|
|
979 |
$el->set_attribute_ns (SW09_NS, 'sw:anchor', $token->{anchor}) |
$el->set_attribute_ns (SW09_NS, ['sw', 'anchor'], $token->{anchor}) |
980 |
if defined $token->{anchor}; |
if defined $token->{anchor}; |
981 |
$el->set_attribute (by => $token->{by}) if defined $token->{by}; |
$el->set_attribute_ns (undef, [undef, 'by'] |
982 |
$el->set_attribute_ns (SW09_NS, 'sw:resScheme', $token->{res_scheme}) |
=> $token->{by}) if defined $token->{by}; |
983 |
|
$el->set_attribute_ns (SW09_NS, ['sw', 'resScheme'], |
984 |
|
$token->{res_scheme}) |
985 |
if defined $token->{res_scheme}; |
if defined $token->{res_scheme}; |
986 |
$el->set_attribute_ns (SW09_NS, 'sw:resParameter', |
$el->set_attribute_ns (SW09_NS, ['sw', 'resParameter'], |
987 |
$token->{res_parameter}) |
$token->{res_parameter}) |
988 |
if defined $token->{res_parameter}; |
if defined $token->{res_parameter}; |
989 |
$el->text_content ($token->{content}) if defined $token->{content}; |
$el->text_content ($token->{content}) if defined $token->{content}; |
990 |
|
|
991 |
$get_next_token->(); |
$token = $get_next_token->(); |
992 |
redo A; |
redo A; |
993 |
} elsif ($token->{type} == END_OF_FILE_TOKEN) { |
} elsif ($token->{type} == END_OF_FILE_TOKEN) { |
994 |
return; |
return; |
1001 |
TABLE_COLSPAN_CELL_TOKEN => 1}->{$token->{type}}) { |
TABLE_COLSPAN_CELL_TOKEN => 1}->{$token->{type}}) { |
1002 |
## NOTE: Ignore the token. |
## NOTE: Ignore the token. |
1003 |
} else { |
} else { |
1004 |
my $el = $doc->create_element_ns (HTML_NS, 'p'); |
unless ({dd => 1, |
1005 |
$oe->[-1]->{node}->append_child ($el); |
li => 1, |
1006 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
'comment-p' => 1, |
1007 |
|
ed => 1}->{$oe->[-1]->{node}->manakai_local_name}) { |
1008 |
|
my $el = $doc->create_element_ns (HTML_NS, [undef, 'p']); |
1009 |
|
$oe->[-1]->{node}->append_child ($el); |
1010 |
|
push @$oe, {%{$oe->[-1]}, node => $el}; |
1011 |
|
} |
1012 |
|
|
1013 |
$im = IN_PARAGRAPH_IM; |
$im = IN_PARAGRAPH_IM; |
1014 |
## Reprocess. |
## Reprocess. |
1015 |
redo A; |
redo A; |
1016 |
} |
} |
1017 |
} elsif ($im == IN_TABLE_ROW_IM) { |
} elsif ($im == IN_TABLE_ROW_IM) { |
1018 |
if ($token->{type} == TABLE_CELL_START_TOKEN) { |
if ($token->{type} == TABLE_CELL_START_TOKEN) { |
1019 |
my $el = $doc->create_element_ns (HTML_NS, 'td'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'td']); |
1020 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
1021 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
1022 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
1023 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
1024 |
|
|
1025 |
$im = IN_PARAGRAPH_IM; |
$im = IN_PARAGRAPH_IM; |
1026 |
$get_next_token->(); |
$token = $get_next_token->(); |
1027 |
redo A; |
redo A; |
1028 |
} elsif ($token->{type} == TABLE_COLSPAN_CELL_TOKEN) { |
} elsif ($token->{type} == TABLE_COLSPAN_CELL_TOKEN) { |
1029 |
my $lc = $oe->[-1]->{node}->last_child; |
my $lc = $oe->[-1]->{node}->last_child; |
1030 |
if ($lc and $lc->manakai_local_name eq 'td') { |
if ($lc and $lc->manakai_local_name eq 'td') { |
1031 |
$lc->set_attribute |
$lc->set_attribute_ns |
1032 |
(colspan => ($lc->get_attribute ('colspan') || 0) + 1); |
(undef, [undef, 'colspan'], |
1033 |
|
($lc->get_attribute_ns (undef, 'colspan') || 0) + 1); |
1034 |
} else { |
} else { |
1035 |
my $el = $doc->create_element_ns (SW10_NS, 'td'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'td']); |
1036 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
1037 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
1038 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
1039 |
} |
} |
1040 |
|
|
1041 |
$get_next_token->(); |
$token = $get_next_token->(); |
1042 |
redo A; |
redo A; |
1043 |
} elsif ($token->{type} == TABLE_ROW_END_TOKEN) { |
} elsif ($token->{type} == TABLE_ROW_END_TOKEN) { |
1044 |
pop @$oe if $oe->[-1]->{node}->manakai_local_name eq 'tr'; |
pop @$oe if $oe->[-1]->{node}->manakai_local_name eq 'tr'; |
1045 |
$get_next_token->(); |
$token = $get_next_token->(); |
1046 |
redo A; |
redo A; |
1047 |
} elsif ($token->{type} == TABLE_ROW_START_TOKEN) { |
} elsif ($token->{type} == TABLE_ROW_START_TOKEN) { |
1048 |
my $el = $doc->create_element_ns (HTML_NS, 'tr'); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'tr']); |
1049 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
1050 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
push @$oe, {%{$oe->[-1]}, node => $el}; |
1051 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
1052 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
1053 |
|
|
1054 |
$get_next_token->(); |
$token = $get_next_token->(); |
1055 |
redo A; |
redo A; |
1056 |
} else { |
} else { |
1057 |
$im = IN_SECTION_IM; |
$im = IN_SECTION_IM; |