92 |
my $tokenize_text = sub { |
my $tokenize_text = sub { |
93 |
my $s = shift; # ref |
my $s = shift; # ref |
94 |
|
|
95 |
|
my $nest_level = 0; |
96 |
|
|
97 |
if ($$s =~ s/^\[([0-9]+)\]//) { |
if ($$s =~ s/^\[([0-9]+)\]//) { |
98 |
push @nt, {type => ELEMENT_TOKEN, |
push @nt, {type => ELEMENT_TOKEN, |
99 |
local_name => 'anchor-end', namespace => SW09_NS, |
local_name => 'anchor-end', namespace => SW09_NS, |
119 |
push @param, $n; |
push @param, $n; |
120 |
$column++ if $$s =~ s/\A\\\z//; |
$column++ if $$s =~ s/\A\\\z//; |
121 |
$column++ if $$s =~ s/^'//; |
$column++ if $$s =~ s/^'//; |
122 |
} elsif ($$s =~ s/^([^':][^:]*)//) { |
} elsif ($$s =~ s/^([^':\]][^:\]]*)//) { |
123 |
$column += 1 + $+[0] - $-[0]; |
$column += 1 + $+[0] - $-[0]; |
124 |
push @param, $1; |
push @param, $1; |
125 |
} |
} |
130 |
} elsif ($$s =~ s/^\[\[//) { |
} elsif ($$s =~ s/^\[\[//) { |
131 |
push @nt, {type => INLINE_START_TAG_TOKEN}; |
push @nt, {type => INLINE_START_TAG_TOKEN}; |
132 |
$column += 2; |
$column += 2; |
133 |
} elsif ($$s =~ s/^\[([A-Z]+)(?>\(([^()\\]*)\))?(?>\@[0-9A-Za-z-]*)?\[//) { |
$nest_level++; |
134 |
|
} elsif ($$s =~ s/^\[([A-Z]+)(?>\(([^()\\]*)\))?(?>\@([0-9A-Za-z-]*))?\[//) { |
135 |
push @nt, {type => INLINE_START_TAG_TOKEN, |
push @nt, {type => INLINE_START_TAG_TOKEN, |
136 |
tag_name => $1, classes => $2, language => $3, |
tag_name => $1, classes => $2, language => $3, |
137 |
line => $line, column => $column}; |
line => $line, column => $column}; |
138 |
$column += $+[0] - $-[0]; |
$column += $+[0] - $-[0]; |
139 |
|
$nest_level++; |
140 |
} elsif ($$s =~ s/^\]\]//) { |
} elsif ($$s =~ s/^\]\]//) { |
141 |
push @nt, {type => INLINE_END_TAG_TOKEN, |
push @nt, {type => INLINE_END_TAG_TOKEN, |
142 |
line => $line, column => $column}; |
line => $line, column => $column}; |
143 |
$column += 2; |
$column += 2; |
144 |
|
$nest_level-- if $nest_level > 0; |
145 |
} elsif ($$s =~ s/^(\]?)<([0-9A-Za-z%+._-]+)://) { |
} elsif ($$s =~ s/^(\]?)<([0-9A-Za-z%+._-]+)://) { |
146 |
my $t = {type => $1 ? INLINE_END_TAG_TOKEN : ELEMENT_TOKEN, |
my $t = {type => $1 ? INLINE_END_TAG_TOKEN : ELEMENT_TOKEN, |
147 |
res_scheme => $2, res_parameter => '', |
res_scheme => $2, res_parameter => '', |
156 |
$t->{res_parameter} .= $1; |
$t->{res_parameter} .= $1; |
157 |
$column += $+[0] - $-[0]; |
$column += $+[0] - $-[0]; |
158 |
$column++ if $$s =~ s/\A\\\z//; |
$column++ if $$s =~ s/\A\\\z//; |
159 |
$column++ if $$s =~ s/^"//; |
$t->{res_parameter} .= '"' and $column++ if $$s =~ s/^"//; |
160 |
} else { |
} else { |
161 |
last; |
last; |
162 |
} |
} |
172 |
|
|
173 |
if ($t->{type} == INLINE_END_TAG_TOKEN) { |
if ($t->{type} == INLINE_END_TAG_TOKEN) { |
174 |
$column++ if $$s =~ s/^\]//; |
$column++ if $$s =~ s/^\]//; |
175 |
|
$nest_level-- if $nest_level > 0; |
176 |
} else { |
} else { |
177 |
$t->{local_name} = 'anchor-external'; |
$t->{local_name} = 'anchor-external'; |
178 |
$t->{namespace} = SW09_NS; |
$t->{namespace} = SW09_NS; |
183 |
anchor => $1, |
anchor => $1, |
184 |
line => $line, column => $column}; |
line => $line, column => $column}; |
185 |
$column += $+[0] - $-[0]; |
$column += $+[0] - $-[0]; |
186 |
} elsif ($$s =~ s/^\][\x09\x20]*(?>\@([0-9a-zA-Z-]*))?\[//) { |
$nest_level-- if $nest_level > 0; |
187 |
|
} elsif ($nest_level > 0 and |
188 |
|
$$s =~ s/^\][\x09\x20]*(?>\@([0-9a-zA-Z-]*))?\[//) { |
189 |
push @nt, {type => INLINE_MIDDLE_TAG_TOKEN, |
push @nt, {type => INLINE_MIDDLE_TAG_TOKEN, |
190 |
language => $1, |
language => $1, |
191 |
line => $line, column => $column}; |
line => $line, column => $column}; |
192 |
$column += $+[0] - $-[0]; |
$column += $+[0] - $-[0]; |
193 |
} elsif ($$s =~ s/\^''('?)//) { |
} elsif ($$s =~ s/^''('?)//) { |
194 |
push @nt, {type => $1 ? STRONG_TOKEN : EMPHASIS_TOKEN, |
push @nt, {type => $1 ? STRONG_TOKEN : EMPHASIS_TOKEN, |
195 |
line => $line, column => $column}; |
line => $line, column => $column}; |
196 |
$column += $+[0] - $-[0]; |
$column += $+[0] - $-[0]; |
197 |
} elsif ($$s =~ s/^>>([0-9]+)//) { |
} elsif ($$s =~ s/^>>([0-9]+)//) { |
198 |
push @nt, {type => ELEMENT_TOKEN, |
push @nt, {type => ELEMENT_TOKEN, |
199 |
local_name => 'anchor-internal', namespace => SW09_NS, |
local_name => 'anchor-internal', namespace => SW09_NS, |
200 |
anchor => $1, |
anchor => $1, content => '>>' . $1, |
201 |
line => $line, column => $column}; |
line => $line, column => $column}; |
202 |
$column += $+[0] - $-[0]; |
$column += $+[0] - $-[0]; |
203 |
} elsif ($$s =~ s/^__&&//) { |
} elsif ($$s =~ s/^__&&//) { |
433 |
my $image = $doc->create_element_ns (SW09_NS, [undef, 'image']); |
my $image = $doc->create_element_ns (SW09_NS, [undef, 'image']); |
434 |
$image->set_user_data (manakai_source_line => $line); |
$image->set_user_data (manakai_source_line => $line); |
435 |
$image->set_user_data (manakai_source_column => 1); |
$image->set_user_data (manakai_source_column => 1); |
436 |
$image->text_content (join "\x0A", $s, @s); |
$image->text_content (join "\x0A", @s); |
437 |
($line, $column) = ($line + @s, 1); |
($line, $column) = ($line + @s, 1); |
438 |
@s = (); |
@s = (); |
439 |
$doc->document_element->append_child ($image); |
$doc->document_element->append_child ($image); |
544 |
Q => [HTML_NS, 'q'], |
Q => [HTML_NS, 'q'], |
545 |
QN => [SW10_NS, 'qn'], |
QN => [SW10_NS, 'qn'], |
546 |
RUBY => [HTML_NS, 'ruby'], |
RUBY => [HTML_NS, 'ruby'], |
547 |
RUBYB => [HTML_NS, 'rubyb'], |
RUBYB => [SW09_NS, 'rubyb'], |
548 |
SAMP => [HTML_NS, 'samp'], |
SAMP => [HTML_NS, 'samp'], |
549 |
SPAN => [HTML_NS, 'span'], |
SPAN => [HTML_NS, 'span'], |
550 |
SRC => [SW10_NS, 'src'], |
SRC => [SW10_NS, 'src'], |
597 |
|
|
598 |
if ({%$structural_elements, |
if ({%$structural_elements, |
599 |
strong => 1, em => 1}->{$oe->[-1]->{node}->manakai_local_name}) { |
strong => 1, em => 1}->{$oe->[-1]->{node}->manakai_local_name}) { |
600 |
my $el = $doc->create_element_ns |
unless (defined $token->{res_scheme} or defined $token->{anchor}) { |
601 |
(SW09_NS, |
$oe->[-1]->{node}->manakai_append_text (']]'); |
602 |
[undef, defined $token->{res_scheme} |
push @$oe, $oe->[-1]; |
603 |
? 'anchor-external' : 'anchor-internal']); |
} else { |
604 |
$oe->[-1]->{node}->append_child ($el); |
my $el = $doc->create_element_ns |
605 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
(SW09_NS, |
606 |
$el->set_user_data (manakai_source_line => $token->{line}); |
[undef, defined $token->{res_scheme} |
607 |
$el->set_user_data (manakai_source_column => $token->{column}); |
? 'anchor-external' : 'anchor-internal']); |
608 |
$el->text_content (']]'); |
$oe->[-1]->{node}->append_child ($el); |
609 |
|
push @$oe, {%{$oe->[-1]}, node => $el}; |
610 |
|
$el->set_user_data (manakai_source_line => $token->{line}); |
611 |
|
$el->set_user_data (manakai_source_column => $token->{column}); |
612 |
|
$el->text_content (']]'); |
613 |
|
} |
614 |
} |
} |
615 |
|
|
616 |
$oe->[-1]->{node}->set_attribute_ns (SW09_NS, ['sw', 'anchor'], |
$oe->[-1]->{node}->set_attribute_ns (SW09_NS, ['sw', 'anchor'], |
628 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
629 |
redo A; |
redo A; |
630 |
} elsif ($token->{type} == STRONG_TOKEN) { |
} elsif ($token->{type} == STRONG_TOKEN) { |
631 |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'strong']); |
if ($oe->[-1]->{node}->manakai_local_name eq 'strong') { |
632 |
$oe->[-1]->{node}->append_child ($el); |
pop @$oe; |
633 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
} else { |
634 |
$el->set_user_data (manakai_source_line => $token->{line}); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'strong']); |
635 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$oe->[-1]->{node}->append_child ($el); |
636 |
|
push @$oe, {%{$oe->[-1]}, node => $el}; |
637 |
|
$el->set_user_data (manakai_source_line => $token->{line}); |
638 |
|
$el->set_user_data (manakai_source_column => $token->{column}); |
639 |
|
} |
640 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
641 |
redo A; |
redo A; |
642 |
} elsif ($token->{type} == EMPHASIS_TOKEN) { |
} elsif ($token->{type} == EMPHASIS_TOKEN) { |
643 |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'em']); |
if ($oe->[-1]->{node}->manakai_local_name eq 'em') { |
644 |
$oe->[-1]->{node}->append_child ($el); |
pop @$oe; |
645 |
push @$oe, {%{$oe->[-1]}, node => $el}; |
} else { |
646 |
$el->set_user_data (manakai_source_line => $token->{line}); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'em']); |
647 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$oe->[-1]->{node}->append_child ($el); |
648 |
|
push @$oe, {%{$oe->[-1]}, node => $el}; |
649 |
|
$el->set_user_data (manakai_source_line => $token->{line}); |
650 |
|
$el->set_user_data (manakai_source_column => $token->{column}); |
651 |
|
} |
652 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
653 |
redo A; |
redo A; |
654 |
} elsif ($token->{type} == FORM_TOKEN) { |
} elsif ($token->{type} == FORM_TOKEN) { |
656 |
if ($token->{name} eq 'form') { |
if ($token->{name} eq 'form') { |
657 |
my $el = $doc->create_element_ns (SW09_NS, [undef, 'form']); |
my $el = $doc->create_element_ns (SW09_NS, [undef, 'form']); |
658 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
|
push @$oe, {%{$oe->[-1]}, node => $el}; |
|
659 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
660 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
661 |
|
|
663 |
=> $token->{id}) if defined $token->{id}; |
=> $token->{id}) if defined $token->{id}; |
664 |
$el->set_attribute_ns (undef, [undef, 'input'] |
$el->set_attribute_ns (undef, [undef, 'input'] |
665 |
=> shift @{$token->{parameters}}) |
=> shift @{$token->{parameters}}) |
666 |
if @{$token->{parameter}}; |
if @{$token->{parameters}}; |
667 |
$el->set_attribute_ns (undef, [undef, 'template'] |
$el->set_attribute_ns (undef, [undef, 'template'] |
668 |
=> shift @{$token->{parameters}}) |
=> shift @{$token->{parameters}}) |
669 |
if @{$token->{parameter}}; |
if @{$token->{parameters}}; |
670 |
$el->set_attribute_ns (undef, [undef, 'option'] |
$el->set_attribute_ns (undef, [undef, 'option'] |
671 |
=> shift @{$token->{parameters}}) |
=> shift @{$token->{parameters}}) |
672 |
if @{$token->{parameter}}; |
if @{$token->{parameters}}; |
673 |
$el->set_attribute_ns (undef, [undef, 'parameter'] |
$el->set_attribute_ns (undef, [undef, 'parameter'] |
674 |
=> join ':', @{$token->{parameters}}) |
=> join ':', @{$token->{parameters}}) |
675 |
if @{$token->{parameter}}; |
if @{$token->{parameters}}; |
676 |
|
|
677 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
678 |
redo A; |
redo A; |
679 |
} else { |
} else { |
680 |
my $el = $doc->create_element_ns (SW09_NS, [undef, 'form']); |
my $el = $doc->create_element_ns (SW09_NS, [undef, 'form']); |
681 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
|
push @$oe, {%{$oe->[-1]}, node => $el}; |
|
682 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
683 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
684 |
|
|
945 |
if ($token->{name} eq 'form') { |
if ($token->{name} eq 'form') { |
946 |
my $el = $doc->create_element_ns (SW09_NS, [undef, 'form']); |
my $el = $doc->create_element_ns (SW09_NS, [undef, 'form']); |
947 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
|
push @$oe, {%{$oe->[-1]}, node => $el}; |
|
948 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
949 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
950 |
|
|
952 |
=> $token->{id}) if defined $token->{id}; |
=> $token->{id}) if defined $token->{id}; |
953 |
$el->set_attribute_ns (undef, [undef, 'input'] |
$el->set_attribute_ns (undef, [undef, 'input'] |
954 |
=> shift @{$token->{parameters}}) |
=> shift @{$token->{parameters}}) |
955 |
if @{$token->{parameter}}; |
if @{$token->{parameters}}; |
956 |
$el->set_attribute_ns (undef, [undef, 'template'] |
$el->set_attribute_ns (undef, [undef, 'template'] |
957 |
=> shift @{$token->{parameters}}) |
=> shift @{$token->{parameters}}) |
958 |
if @{$token->{parameter}}; |
if @{$token->{parameters}}; |
959 |
$el->set_attribute_ns (undef, [undef, 'option'] |
$el->set_attribute_ns (undef, [undef, 'option'] |
960 |
=> shift @{$token->{parameters}}) |
=> shift @{$token->{parameters}}) |
961 |
if @{$token->{parameter}}; |
if @{$token->{parameters}}; |
962 |
$el->set_attribute_ns (undef, [undef, 'parameter'] |
$el->set_attribute_ns (undef, [undef, 'parameter'] |
963 |
=> join ':', @{$token->{parameters}}) |
=> join ':', @{$token->{parameters}}) |
964 |
if @{$token->{parameter}}; |
if @{$token->{parameters}}; |
965 |
|
|
966 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
967 |
redo A; |
redo A; |
968 |
} else { |
} else { |
969 |
my $el = $doc->create_element_ns (SW09_NS, [undef, 'form']); |
my $el = $doc->create_element_ns (SW09_NS, [undef, 'form']); |
970 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
|
push @$oe, {%{$oe->[-1]}, node => $el}; |
|
971 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
972 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
973 |
|
|
976 |
=> $token->{id}) if defined $token->{id}; |
=> $token->{id}) if defined $token->{id}; |
977 |
$el->set_attribute_ns (undef, [undef, 'parameter'] |
$el->set_attribute_ns (undef, [undef, 'parameter'] |
978 |
=> join ':', @{$token->{parameters}}) |
=> join ':', @{$token->{parameters}}) |
979 |
if @{$token->{parameter}}; |
if @{$token->{parameters}}; |
980 |
|
|
981 |
$token = $get_next_token->(); |
$token = $get_next_token->(); |
982 |
redo A; |
redo A; |
987 |
my $el = $doc->create_element_ns |
my $el = $doc->create_element_ns |
988 |
($token->{namespace}, [undef, $token->{local_name}]); |
($token->{namespace}, [undef, $token->{local_name}]); |
989 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |
|
push @$oe, {%{$oe->[-1]}, node => $el}; |
|
990 |
$el->set_user_data (manakai_source_line => $token->{line}); |
$el->set_user_data (manakai_source_line => $token->{line}); |
991 |
$el->set_user_data (manakai_source_column => $token->{column}); |
$el->set_user_data (manakai_source_column => $token->{column}); |
992 |
|
|
1044 |
if ($lc and $lc->manakai_local_name eq 'td') { |
if ($lc and $lc->manakai_local_name eq 'td') { |
1045 |
$lc->set_attribute_ns |
$lc->set_attribute_ns |
1046 |
(undef, [undef, 'colspan'], |
(undef, [undef, 'colspan'], |
1047 |
($lc->get_attribute_ns (undef, 'colspan') || 0) + 1); |
($lc->get_attribute_ns (undef, 'colspan') || 1) + 1); |
1048 |
} else { |
} else { |
1049 |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'td']); |
my $el = $doc->create_element_ns (HTML_NS, [undef, 'td']); |
1050 |
$oe->[-1]->{node}->append_child ($el); |
$oe->[-1]->{node}->append_child ($el); |