/[pub]/suikawiki/script/misc/plugins/SuikaWiki09.pm
Suika

Contents of /suikawiki/script/misc/plugins/SuikaWiki09.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.2.1 - (hide annotations) (download)
Sun May 16 23:53:45 2010 UTC (14 years, 11 months ago) by hero
Branch: helowiki-2005
Changes since 1.1: +83 -279 lines
current .pm

1 wakaba 1.1 use strict;
2     package SuikaWiki::Plugin::Registry;
3    
4    
5     our %Info;
6     $Info{q#SuikaWiki09#}->{Name} = q#SuikaWiki09#;
7 hero 1.1.2.1 $Info{q#SuikaWiki09#}->{q#Version#} = q#2004.0831.0328#;
8 wakaba 1.1 $Info{q#SuikaWiki09#}->{q#InterfaceVersion#} = q#2.9.1#;
9 hero 1.1.2.1 $Info{q#SuikaWiki09#}->{q#mkpluginVersion#} = q#2.1.19#;
10     $Info{q#SuikaWiki09#}->{q#module_name#} = q#SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE#;
11     $Info{q#SuikaWiki09#}->{q#Date.RCS#} = q#$Date: 2004/08/08 08:11:06 $#;
12 wakaba 1.1 $Info{q#SuikaWiki09#}->{RequiredPlugin} = [q#Edit#, q#WikiFormCore#, q#WikiLinking#, q#WikiStruct#];
13     $Info{q#SuikaWiki09#}->{Description} = [[q#SuikaWiki/0.9 and SuikaWiki/0.10 document formats#, q#en#, q##]];
14     $Info{q#SuikaWiki09#}->{License} = [[q#%%Perl%%#, q##, q##]];
15     $Info{q#SuikaWiki09#}->{Author} = [[[[q#Wakaba#, q#ja#, q#Latn#]], [[q#w@suika.fam.cx#]], [q##]]];
16 hero 1.1.2.1 package SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE;
17 wakaba 1.1
18    
19     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block Plugin/Use)"
20     use Message::Markup::XML::QName qw/NS_xml_URI/;
21     my $Reg_Form_Content_M = qr{
22     \#form
23     (?:
24     \( (\w+) \) ## id
25     )?
26     : ' ((?>[^\\']*)(?>(?>[^\\']+|\\.)*)) ' ## input
27     (?> : ' ((?>[^\\']*)(?>(?>[^\\']+|\\.)*)) ' ## template
28     (?> : ' ((?>[^\\']*)(?>(?>[^\\']+|\\.)*)) ' )? )? ## option
29     }x;
30     my $Reg_Embed_Content_M = qr{
31     \#([a-z-]+)
32     (?>
33     \( (\w+) \) ## id
34     )?
35     (?>
36     : ( \w+ (?> : \w+ )* ) ## parameter
37     )?
38     }x;
39     my $Reg_URI_Opaque = qr{
40     (?>[^<>"]*)
41     (?>
42     (?>
43     [^<>"]+
44     | "(?>[^"\\]*)(?>(?>[^"\\]+|\\.)*)"
45     )*
46     )
47     }x;
48     my ($WIKIRESOURCE, $WIKISTRUCT, $WIKIFORMCORE, $WIKILINKING);
49     #line 1 "(WikiPlugin module SuikaWiki09, chunk 1)"
50    
51     package SuikaWiki::Format::Definition::SuikaWiki::V0;
52    
53     our @ISA;
54     push @ISA, q#SuikaWiki::Format::Definition::Text::Plain#;
55    
56     package SuikaWiki::Format::Definition::SuikaWiki::V0_10;
57    
58     our @ISA;
59     push @ISA, q#SuikaWiki::Format::Definition::SuikaWiki::V0_9#;
60     $SuikaWiki::Format::Definition::Class{q#MAGIC:SuikaWiki/0.10\#\##} = 'SuikaWiki::Format::Definition::SuikaWiki::V0_10';
61     $SuikaWiki::Format::Definition::Class{q#IMT:text/x-suikawiki;version="0.10"\#\##} = 'SuikaWiki::Format::Definition::SuikaWiki::V0_10';
62    
63     package SuikaWiki::Format::Definition::SuikaWiki::V0_9;
64    
65     our @ISA;
66     push @ISA, q#SuikaWiki::Format::Definition::SuikaWiki::V0#;
67     $SuikaWiki::Format::Definition::Class{q#MAGIC:SuikaWiki/0.9\#\##} = 'SuikaWiki::Format::Definition::SuikaWiki::V0_9';
68     $SuikaWiki::Format::Definition::Class{q#IMT:text/x-suikawiki;version="0.9"\#\##} = 'SuikaWiki::Format::Definition::SuikaWiki::V0_9';
69    
70     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block Format[module-name()=SuikaWiki::Format::Definition::SuikaWiki::V0_9]/Use)"
71     use Message::Markup::XML::QName qw/NS_xml_URI/;
72     use Message::Util::Error;
73     #line 251 "(WikiPlugin module SuikaWiki09, chunk from ../../bin/mkplugin2.pl)"
74     our $Converter;
75     sub convert ($$;%) {
76     my ($self, $source, %opt) = @_;
77     my $t = SuikaWiki::Format::Definition->serialize_media_type (%opt);
78     my $converter = $Converter->{$t->{_}};
79     return ($converter->{$opt{return_type} or 'Main'} or
80     CORE::die "Buggy implementation: $t->{_}/@{[$opt{return_type} or 'Main']} not defined")
81     ->($self, $source, \%opt)
82     if $converter;
83     $self->SUPER::convert ($source, %opt);
84     }
85    
86     #line 1 "(WikiPlugin module SuikaWiki09, chunk 2)"
87     $Converter->{q#IMT:text/html\#\#f#} = {q#Type#, q#text/html#, q#serialized_type#, q#IMT:text/html\#\#f#, q#Type_param#, {}, q#IsFragment#, q#1#, q#Main#, sub {my ($self, $source, $opt) = @_;
88     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block //Converter/Main)"
89     $opt->{o}->{wiki} ||= $self->{wiki};
90 hero 1.1.2.1 my $xml = SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->get_xml_tree (text => $source, opt => $opt,
91 wakaba 1.1 wiki => $self->{wiki});
92 hero 1.1.2.1 SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->sw09_to_xhtml1 (source => $xml, parent => $opt->{-parent},
93 wakaba 1.1 o => $opt->{o}, page => $opt->{page});
94     if ($opt->{-with_annotation_input}) {
95     SuikaWiki::Plugin->module_package ('WikiFormCore')
96     ->make_content_form_in_html
97     ($opt->{-parent},
98     ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get
99     (name => 'SuikaWiki/0.9:form:footannotate:input',
100     o => $opt->{o}, wiki => $opt->{o}->{wiki}),
101     option => ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get
102     (name => 'SuikaWiki/0.9:form:footannotate:option',
103     o => $opt->{o}, wiki => $opt->{o}->{wiki}),
104     o => $opt->{o},
105     wiki => $opt->{o}->{wiki},
106     output => {
107     page => $opt->{page},
108     });
109     }
110     #line 1 "(WikiPlugin module SuikaWiki09, chunk 3)"
111     }};
112     $Converter->{q#IMT:application/x-suikawiki+xml;version="0.9"\#\##} = {q#Type#, q#application/x-suikawiki+xml#, q#serialized_type#, q#IMT:application/x-suikawiki+xml;version="0.9"\#\##, q#Type_param#, {q#version#, q#0.9#}, q#Main#, sub {my ($self, $source, $opt) = @_;
113     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block //Converter/Main)"
114 hero 1.1.2.1 my $xml = SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->get_xml_tree (text => $source, opt => $opt,
115 wakaba 1.1 wiki => $self->{wiki});
116     $opt->{-parent}->append_node ($xml);
117     #line 1 "(WikiPlugin module SuikaWiki09, chunk 4)"
118     }};
119     sub next_index_for_anchor {
120     my ($self, $source, %opt) = @_;
121     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block Format[module-name()=SuikaWiki::Format::Definition::SuikaWiki::V0_9]/NextIndex[Name=anchor])"
122 hero 1.1.2.1 my $xml = SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->get_xml_tree (text => $source, opt => \%opt,
123 wakaba 1.1 wiki => $self->{wiki});
124 hero 1.1.2.1 (SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->get_last_anchor_index ($xml)) + 1;
125 wakaba 1.1 #line 1 "(WikiPlugin module SuikaWiki09, chunk 5)"
126     }
127     sub wikiform {
128     my ($self, $source, %opt) = @_;
129     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block Format[module-name()=SuikaWiki::Format::Definition::SuikaWiki::V0_9]/WikiForm)"
130 hero 1.1.2.1 my $xml = SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->get_xml_tree (text => $source, opt => \%opt,
131 wakaba 1.1 wiki => $self->{wiki});
132     local $opt{o}->{var}->{sw09__anchor_index};
133     local $opt{o}->{var}->{sw09__document_tree} = $xml;
134     my $form;
135     if ($opt{o}->{form}->{output}->{id}) {
136 hero 1.1.2.1 $form = SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->get_element_by_id
137 wakaba 1.1 ($xml, $opt{o}->{form}->{output}->{id});
138     undef $form unless ref $form and
139     $form->namespace_uri eq q#urn:x-suika-fam-cx:markup:suikawiki:0:9:# and
140     $form->local_name eq 'form';
141     } else {
142 hero 1.1.2.1 $form = SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->get_nth_element
143 wakaba 1.1 ($xml, q#urn:x-suika-fam-cx:markup:suikawiki:0:9:# => 'form',
144     $opt{o}->{form}->{output}->{index});
145     }
146     my $ref;
147     if (ref $form) {
148     $ref = $form->get_attribute_value ('ref', default => 'form');
149     } else {
150     $ref = '#footannotate';
151     }
152     if ($ref eq 'form') {
153     $opt{option} ||= $form->get_attribute_value ('option');
154     } elsif ($ref eq 'comment') {
155     $opt{option} ||= ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get
156     (name => 'SuikaWiki/0.9:form:comment:option',
157     o => $opt{o}, wiki => $opt{o}->{wiki});
158     } elsif ($ref eq '#footannotate') {
159     $opt{option} ||= ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get
160     (name => 'SuikaWiki/0.9:form:footannotate:option',
161     o => $opt{o}, wiki => $opt{o}->{wiki});
162     } else {
163     }
164     ($WIKIFORMCORE ||= SuikaWiki::Plugin->module_package ('WikiFormCore'))->set_option ($opt{option} => $opt{o}) if $opt{option};
165     my @missing;
166     for (keys %{$opt{o}->{form}->{require}->{id}}) {
167     unless (length $opt{o}->{wiki}->{input}->parameter
168     (($WIKIFORMCORE ||= SuikaWiki::Plugin->module_package ('WikiFormCore'))->control_id ($opt{o}, local_id => $_,
169     local_id_prefix => 'wikiform__')
170     ->{local_id})) {
171     push @missing, $_;
172     }
173     }
174     if (@missing) {
175     return [{
176     type => 'required_param_missing',
177     missing_id => \@missing,
178     }];
179     }
180     my $result;
181     if ($ref eq 'form') {
182     $opt{template} ||= $form->get_attribute_value
183     ('template', default => '');
184     } elsif ($ref eq 'comment') {
185     $opt{template} ||= ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get
186     (name => 'SuikaWiki/0.9:form:comment:template',
187     o => $opt{o}, wiki => $opt{o}->{wiki});
188     } elsif ($ref eq '#footannotate') {
189     $opt{template} ||= ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get
190     (name => 'SuikaWiki/0.9:form:footannotate:template',
191     o => $opt{o}, wiki => $opt{o}->{wiki});
192     }
193     try {
194     $result = SuikaWiki::Plugin->text_formatter ('form_template')
195     ->replace ($opt{template}, param => $opt{o});
196     } catch Message::Util::Formatter::error with {
197     my $err = shift;
198     SuikaWiki::Plugin->module_package ('Error')
199     ->reporting_formatting_template_error
200     ($err, $err->{option}->{param}->{wiki});
201     throw SuikaWiki::View::Implementation::error -type => 'ERROR_REPORTED';
202     };
203     if (length $result) {
204     if ($ref eq '#footannotate') {
205     my $parent;
206     for (@{$xml->child_nodes}) {
207     if ($_->node_type eq '#element' and
208     $_->local_name eq 'document') {
209     for (@{$_->child_nodes}) {
210     if ($_->node_type eq '#element' and
211     $_->local_name eq 'body') {
212     $parent = $_;
213     last;
214     }
215     }
216     }
217     }
218     CORE::die "Buggy implementation: no body element".$xml
219     unless ref $parent;
220     $parent->append_new_node (type => '#element',
221     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
222     local_name => 'text')
223     ->append_text ($result);
224     } else {
225     my $parent = $form->parent_node;
226     CORE::die "Byggy implementation: No parent of form" unless ref $parent;
227     my $children = $parent->child_nodes;
228     $result .= "\x0A" unless substr ($result, -1) eq "\x0A";
229     $parent->append_new_node (type => '#element',
230     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
231     local_name => 'text')
232     ->append_text ($result);
233     my $node = pop @{$children};
234     my $form_str = overload::StrVal ($form);
235     my $i = 0;
236     for (@{$children}) {
237     last if overload::StrVal ($_) eq $form_str;
238     $i++;
239     }
240     if ($opt{o}->{form}->{output}->{reverse}) {
241     splice @{$children}, $i + 1, 0, $node;
242     } else {
243     splice @{$children}, $i, 0, $node;
244     }
245     }
246     } else {
247     }
248 hero 1.1.2.1 my $text = SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->xml_to_text ($xml, {%opt});
249 wakaba 1.1 my %fragment = (fragment => $opt{o}->{form}->{output}->{id}
250     || 'wikiform-'.$opt{o}->{form}->{output}->{index});
251     if (not $opt{o}->{form}->{output}->{reverse} and
252     $opt{o}->{var}->{sw09__anchor_index}) {
253     %fragment = (anchor_no => $opt{o}->{var}->{sw09__anchor_index});
254     }
255     my $action = [
256     {
257     type => 'write',
258     content => $text,
259     update_lastmodified => time,
260     },
261     {
262     type => 'ok',
263     %fragment,
264     },
265     ];
266     #line 1 "(WikiPlugin module SuikaWiki09, chunk 6)"
267     }
268     sub headsummary {
269     my ($self, $source, %opt) = @_;
270     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block Format[module-name()=SuikaWiki::Format::Definition::SuikaWiki::V0_9]/HeadSummary)"
271 hero 1.1.2.1 my $xml = SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->get_xml_tree (text => $source, opt => \%opt,
272 wakaba 1.1 wiki => $self->{wiki});
273     return $xml->inner_text;
274     #line 1 "(WikiPlugin module SuikaWiki09, chunk 7)"
275     }
276    
277 hero 1.1.2.1 package SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE;
278 wakaba 1.1
279     $SuikaWiki::Plugin::Rule{form_template}->{index} = {q#after#, sub {my ($f, $rule_name, $p, $o, %opt) = @_;
280    
281     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block FormattingRule[name()='[q#form-template#]/index']/After)"
282     if ($o->{var}->{sw09__anchor_index}) {
283     ++$o->{var}->{sw09__anchor_index};
284     } else {
285     $o->{var}->{sw09__anchor_index}
286 hero 1.1.2.1 = 1 + SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->get_last_anchor_index
287 wakaba 1.1 ($o->{var}->{sw09__document_tree});
288     }
289     $p->{-result} .= $o->{var}->{sw09__anchor_index};}, q#Parameter#, {}, q#Description#, [[q#Next anchor index number#, q#en#, q##]]}
290     #line 1 "(WikiPlugin module SuikaWiki09, chunk 8)"
291     ;
292    
293    
294     sub get_last_anchor_index {
295    
296     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block Function[Name='get_last_anchor_index']/Main)"
297     my (undef, $xml) = @_;
298     my $anchor = 0;
299     my $get_anchor_no;
300     $get_anchor_no = sub {
301     my $node = shift;
302     for my $child (@{$node->child_nodes}) {
303     my $nt = $child->node_type;
304     if ($nt eq '#element') {
305     if ($child->namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:# and
306     $child->local_name eq 'anchor-end') {
307     my $a = $child->get_attribute_value ('anchor', default => 0,
308     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#);
309     $anchor = 0+$a if $anchor < 0+$a;
310     } else {
311     $get_anchor_no->($child);
312     }
313     } elsif ($nt eq '#document' or $nt eq '#fragment') {
314     $get_anchor_no->($child);
315     }
316     }
317     };
318     $get_anchor_no->($xml);
319     $anchor;
320     }
321    
322     #line 1 "(WikiPlugin module SuikaWiki09, chunk 10)"
323    
324    
325    
326     sub get_xml_tree {
327    
328     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block Function[Name='get_xml_tree']/Main)"
329     my (undef, %opt) = @_;
330     if ($opt{opt}->{page}) {
331 hero 1.1.2.1 unless ($SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE::DBLoaded) {
332 wakaba 1.1 $opt{wiki}->{db}->_set_prop_db (sw09__xml_tree => {-db_open => sub {
333     require SuikaWiki::DB::Hash;
334     new SuikaWiki::DB::Hash;
335     }});
336 hero 1.1.2.1 $SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE::DBLoaded++;
337 wakaba 1.1 }
338     my $xml = new Message::Markup::XML::Node type => '#fragment';
339 hero 1.1.2.1 SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->text_to_xml (${$opt{text}}, {%{$opt{opt}}, -parent => $xml});
340 wakaba 1.1 $opt{wiki}->{db}->set (sw09__xml_tree => $opt{opt}->{page} => $xml);
341     $xml;
342     } else {
343     my $xml = new Message::Markup::XML::Node type => '#fragment';
344 hero 1.1.2.1 SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->text_to_xml (${$opt{text}}, {%{$opt{opt}}, -parent => $xml});
345 wakaba 1.1 $xml;
346     }
347     }
348    
349     #line 1 "(WikiPlugin module SuikaWiki09, chunk 11)"
350    
351    
352    
353     sub sw09_to_xhtml1 {
354    
355     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block Function[Name='sw09_to_xhtml1']/Main)"
356     my (undef, %opt) = @_;
357     my ($apply_template, $apply_template_children);
358     $apply_template_children = sub {
359     for (@{$_[0]->child_nodes}) {
360     $apply_template->($_ => $_[1]) unless $_->node_type eq '#attribute';
361     }
362     };
363     $apply_template = sub {
364     my ($source, $result) = @_;
365     my $ln = $source->local_name;
366     if ($source->node_type eq '#text') {
367     $result->append_text ($source->inner_text);
368     } elsif ({qw/code 1 samp 1 var 1 dfn 1 kbd 1 sub 1 sup 1
369 hero 1.1.2.1 cite 1/ ## SuikaWiki/0.10
370 wakaba 1.1 }->{$ln}) {
371     my $node = $result->append_new_node
372     (type => '#element',
373     namespace_uri => q#http://www.w3.org/1999/xhtml#,
374     local_name => $ln);
375     my $class = $source->get_attribute_value ('class', default => '');
376     $node->set_attribute (class => $class) if $class;
377     $apply_template_children->($source => $node);
378     } elsif ({qw/ins 1 del 1 insert 1 delete 1/}->{$ln}) {
379     my $node = $result->append_new_node
380     (type => '#element',
381     namespace_uri => q#http://www.w3.org/1999/xhtml#,
382     local_name => {qw/ins ins insert ins
383     delete del del del/}->{$ln});
384     my $class = $source->get_attribute_value ('class', default => '');
385     $node->set_attribute (class => $class) if $class;
386     $apply_template_children->($source => $node);
387     } elsif ({qw/table 1 tbody 1 tr 1 td 1 blockquote 1 ul 1 ol 1
388     li 1 pre 1 dl 1 dt 1 dd 1 em 1 strong 1/}->{$ln}) {
389     my $node = $result->append_new_node
390     (type => '#element',
391     namespace_uri => q#http://www.w3.org/1999/xhtml#,
392     local_name => $ln);
393     if ($ln eq 'td') {
394     my $colspan = $source->get_attribute_value ('colspan', default => 0);
395     $node->set_attribute (colspan => $colspan) if $colspan;
396     } elsif ($ln eq 'pre') {
397     $node->set_attribute (space => 'preserve',
398     namespace_uri => NS_xml_URI);
399     my $class = $source->get_attribute_value ('class', default => '');
400     $node->set_attribute (class => $class) if length $class;
401     }
402     $apply_template_children->($source => $node);
403     } elsif ($ln eq 'anchor') {
404     local $opt{o}->{var}->{sw09__anchor_content} = sub {
405     $apply_template_children->($source => shift);
406     };
407     SuikaWiki::Plugin->module_package ('WikiLinking')
408     ->to_wikipage_in_html ({
409     label => ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get_text
410     (name =>
411     'Link:SuikaWiki/0.9:toWikiPage:SourceLabel',
412     param => $opt{o},
413     wiki => $opt{o}->{wiki}),
414     } => {
415     base => $opt{o}->{wiki}->{var}->{page},
416     page_name => $opt{o}->{wiki}->name ($source->inner_text)
417     ->absolute (wiki => $opt{o}->{wiki},
418     nearest => 'content',
419     base => $opt{o}->{wiki}
420     ->{var}->{page}),
421     page_anchor_no => $source->get_attribute_value
422     ('anchor',
423     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#),
424     }, {
425     o => $opt{o},
426     parent => $result,
427     });
428     } elsif ($ln eq 'p') {
429     $apply_template_children->($source => $result->append_new_node
430     (type => '#element',
431     namespace_uri => q#http://www.w3.org/1999/xhtml#,
432     local_name => 'p'));
433     } elsif ($ln eq 'h') {
434     my $node;
435     if ($opt{o}->{var}->{ws__section_depth} > 6) {
436     $node = $result->append_new_node
437     (type => '#element',
438     namespace_uri => q#http://www.w3.org/1999/xhtml#,
439     local_name => 'div');
440     $node->set_attribute (class => 'heading h'.$opt{o}->{var}
441     ->{ws__section_depth});
442     } else {
443     $node = $result->append_new_node
444     (type => '#element',
445     namespace_uri => q#http://www.w3.org/1999/xhtml#,
446     local_name => 'h'.$opt{o}->{var}
447     ->{ws__section_depth});
448     }
449     $apply_template_children->($source => $node);
450     ($WIKISTRUCT ||= SuikaWiki::Plugin->module_package ('WikiStruct'))->set_section_id ($result, undef, $opt{o}->{wiki},
451     title => $source->inner_text);
452     } elsif ($ln eq 'ruby' or $ln eq 'rubyb') {
453     my @child;
454     for (@{$source->child_nodes}) {
455     if ({qw/rb 1 rt 1/}->{$_->local_name}) {
456     push @child, $_;
457     }
458     }
459     for ($result->append_new_node (type => '#element',
460     namespace_uri => q#http://www.w3.org/1999/xhtml#,
461     local_name => 'ruby')) {
462     if ($ln eq 'rubyb') {
463     my $class = join ' ',
464     'descriptive',
465     split /\s+/, $source->get_attribute_value
466     ('class', default => '');
467     $_->set_attribute (class => $class) if $class;
468     } else {
469     my $class = $source->get_attribute_value ('class', default => '');
470     $_->set_attribute (class => $class) if $class;
471     }
472     $apply_template_children->($child[0]
473     => $_->append_new_node (type => '#element',
474     namespace_uri => q#http://www.w3.org/1999/xhtml#,
475     local_name => 'rb'));
476     $_->append_new_node (type => '#element',
477     namespace_uri => q#http://www.w3.org/1999/xhtml#,
478     local_name => 'rp')
479     ->append_text ('(');
480     if ($child[1]) {
481     $apply_template_children->($child[1]
482     => $_->append_new_node (type => '#element',
483     namespace_uri => q#http://www.w3.org/1999/xhtml#,
484     local_name => 'rt'));
485     } else {
486     $_->append_new_node (type => '#element',
487     namespace_uri => q#http://www.w3.org/1999/xhtml#,
488     local_name => 'rt');
489     }
490     if ($child[2]) {
491     $_->append_new_node (type => '#element',
492     namespace_uri => q#http://www.w3.org/1999/xhtml#,
493     local_name => 'rp')
494     ->append_text ('/');
495     $apply_template_children->($child[2]
496     => $_->append_new_node (type => '#element',
497     namespace_uri => q#http://www.w3.org/1999/xhtml#,
498     local_name => 'rt'));
499     }
500     $_->append_new_node (type => '#element',
501     namespace_uri => q#http://www.w3.org/1999/xhtml#,
502     local_name => 'rp')
503     ->append_text (')');
504     }
505     } elsif ($ln eq 'abbr') {
506     my (@b);
507     for (@{$source->child_nodes}) {
508     push @b, $_ if {qw/rb 1 rt 1/}->{$_->local_name};
509     }
510     my $node = $result->append_new_node
511     (type => '#element',
512     namespace_uri => q#http://www.w3.org/1999/xhtml#,
513     local_name => 'abbr');
514     $node->set_attribute (title => $b[1]->inner_text) if $b[1];
515     $apply_template_children->($b[0] => $node);
516     } elsif ($ln eq 'q') {
517     my $node = $result->append_new_node
518     (type => '#element',
519     namespace_uri => q#http://www.w3.org/1999/xhtml#,
520     local_name => 'q');
521     $apply_template_children->($source => $node);
522     } elsif ($ln eq 'weak' or
523     $ln eq 'aa' ## SuikaWiki/0.10
524     ) {
525     my $node = $result->append_new_node
526     (type => '#element',
527     namespace_uri => q#http://www.w3.org/1999/xhtml#,
528     local_name => 'span');
529     my @class = split /\s+/,
530     $source->get_attribute_value ('class', default => '');
531     $node->set_attribute (class => join ' ', $ln, @class);
532     $apply_template_children->($source => $node);
533     } elsif ($ln eq 'src') { ## SuikaWiki/0.10
534     my $node = $result->append_new_node
535     (type => '#element',
536     namespace_uri => q#http://www.w3.org/1999/xhtml#,
537     local_name => 'cite');
538     my @class = split /\s+/,
539     $source->get_attribute_value ('class', default => '');
540     $node->set_attribute (class => join ' ', $ln, @class);
541     $node->append_text ("[");
542     $apply_template_children->($source => $node);
543     $node->append_text ("]");
544     } elsif ($ln eq 'key') { ## SuikaWiki/0.10
545     my $node = $result->append_new_node
546     (type => '#element',
547     namespace_uri => q#http://www.w3.org/1999/xhtml#,
548     local_name => 'kbd');
549     my @class = split /\s+/,
550     $source->get_attribute_value ('class', default => '');
551     $node->set_attribute (class => join ' ', $ln, @class);
552     $apply_template_children->($source => $node);
553     } elsif ({qw/section 1 bodytext 1/}->{$ln}) {
554     my $node = $result->append_new_node
555     (type => '#element',
556     namespace_uri => q#http://www.w3.org/1999/xhtml#,
557     local_name => 'div');
558     $node->set_attribute (class => $ln);
559     local $opt{o}->{var}->{ws__section_depth}
560     = $opt{o}->{var}->{ws__section_depth} + 1;
561     $apply_template_children->($source => $node);
562     } elsif ($ln eq 'anchor-end') {
563     my $node = $result->append_new_node
564     (type => '#element',
565     namespace_uri => q#http://www.w3.org/1999/xhtml#,
566     local_name => 'a');
567     $node->set_attribute (id => 'anchor-'.$source->get_attribute_value
568     ('anchor', default => '0',
569     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#));
570     $node->set_attribute (name => 'anchor-'.$source->get_attribute_value
571     ('anchor', default => '0',
572     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#))
573     if $opt{o}->{wiki}->{var}->{client}->{downgrade}->{html_no_id};
574     $node->set_attribute (class => 'anchor');
575     $node->append_text ($source->inner_text);
576     } elsif ($ln eq 'anchor-internal') {
577     my $node = $result->append_new_node
578     (type => '#element',
579     namespace_uri => q#http://www.w3.org/1999/xhtml#,
580     local_name => 'a');
581     $node->set_attribute (href => '#anchor-'.$source->get_attribute_value
582     ('anchor',
583     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#, default => '0'));
584     $node->set_attribute (class => 'wiki-anchor');
585     $node->append_text ($source->inner_text);
586     } elsif ($ln eq 'anchor-external') {
587     local $opt{o}->{var}->{sw09__anchor_content} = sub {
588     $apply_template_children->($source => shift);
589     };
590     ($WIKILINKING ||= SuikaWiki::Plugin->module_package ('WikiLinking'))
591     ->to_resource_in_html (
592     {
593     label => ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))
594     ->get_text (name =>
595     'Link:SuikaWiki/0.9:toResource:SourceLabel',
596     param => $opt{o},
597     wiki => $opt{o}->{wiki}),
598     }, {
599     resource_scheme =>
600     $source->get_attribute_value ('resScheme',
601     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
602     default => 'URI'),
603     resource_parameter =>
604     $source->get_attribute_value ('resParameter',
605     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
606     default => ''),
607     }, {
608     o => $opt{o},
609     parent => $result,
610     });
611     } elsif ($ln eq 'form') {
612     my $ref = $source->get_attribute_value ('ref', default => 'form');
613     if ($ref eq 'form') {
614     ($WIKIFORMCORE ||= SuikaWiki::Plugin->module_package ('WikiFormCore'))->make_content_form_in_html
615     ($result,
616     $source->get_attribute_value
617     ('input', default => ''),
618     option => $source->get_attribute_value
619     ('option'),
620     name => $source->get_attribute_value ('id'),
621     o => $opt{o},
622     wiki => $opt{o}->{wiki},
623     output => {
624     page => $opt{page},
625     });
626     } elsif ($ref eq 'comment') {
627     ($WIKIFORMCORE ||= SuikaWiki::Plugin->module_package ('WikiFormCore'))->make_content_form_in_html
628     ($result,
629     ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get
630     (name => 'SuikaWiki/0.9:form:comment:input',
631     o => $opt{o}, wiki => $opt{o}->{wiki}),
632     option => ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get
633     (name => 'SuikaWiki/0.9:form:comment:option',
634     o => $opt{o}, wiki => $opt{o}->{wiki}),
635     name => $source->get_attribute_value ('id'),
636     o => $opt{o},
637     wiki => $opt{o}->{wiki},
638     output => {
639     page => $opt{page},
640     });
641     } else {
642     ($WIKIFORMCORE ||= SuikaWiki::Plugin->module_package ('WikiFormCore'))->make_content_form_in_html
643     ($result,
644     '',
645     option => '',
646     o => $opt{o},
647     wiki => $opt{o}->{wiki},
648     output => {
649     page => $opt{page},
650     });
651     }
652     } elsif ($ln eq 'dr') {
653     $apply_template_children->($source => $result);
654     } elsif ($ln eq 'document') {
655     my $body;
656     for (@{$source->child_nodes}) {
657     $body = $_ and last if $_->local_name eq 'body';
658     }
659     my $body_block = $result->append_new_node
660     (type => '#element',
661     namespace_uri => q#http://www.w3.org/1999/xhtml#,
662     local_name => 'div');
663     $body_block->set_attribute (class => 'block SuikaWiki-0-9');
664     $apply_template_children->($body => $body_block);
665     } else {
666     my $node = $result->append_new_node
667     (type => '#element',
668     namespace_uri => q#http://www.w3.org/1999/xhtml#,
669     local_name => 'span');
670     $node->set_attribute (class => 'warn');
671     for ($node->append_new_node
672     (type => '#element',
673     namespace_uri => q#http://www.w3.org/1999/xhtml#,
674     local_name => 'ins')
675     ->append_new_node
676     (type => '#element',
677     namespace_uri => q#http://www.w3.org/1999/xhtml#,
678     local_name => 'code')) {
679     $_->set_attribute (class => 'XML element');
680     $_->append_text ("<".$source->namespace_uri.">:$ln");
681     }
682     $apply_template_children->($source => $node);
683     }
684     };
685     $apply_template_children->($opt{source} => $opt{parent});
686     }
687    
688     #line 1 "(WikiPlugin module SuikaWiki09, chunk 12)"
689    
690    
691    
692     sub xml_to_text {
693    
694     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block Function[Name='xml_to_text']/Main)"
695     my (undef, $src, $opt) = @_;
696     my %is_block = (
697     qw/p 1 blockquote 1 pre 1 ul 1 ol 1 dl 1 section 1 h 1
698     bodytext 1 document 1 head 1 body 1 table 1 text 1 form 1
699 hero 1.1.2.1 insert 1 delete 1/
700 wakaba 1.1 );
701     my %x2t;
702     %x2t = (
703     anchor => sub {
704     my $source = shift;
705     my $result = '[['
706     . $x2t{'#inline'}->($source, no_newline => 1)
707     . ']';
708     my $anchor = $source->get_attribute_value
709     ('anchor',
710     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
711     default => '');
712     if (length $anchor) {
713     $result .= '>>'.(0+$anchor);
714     } else {
715     $anchor = $source->get_attribute_value
716     ('resScheme',
717     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#);
718     if ($anchor) {
719     my $param = $source->get_attribute_value
720     ('resParameter',
721     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#);
722     if ($anchor eq 'URI' and $param =~ /^[0-9A-Za-z_+.%-]+:/) {
723     $result .= '<' . $param . '>';
724     } else {
725     $result .= '<' . $anchor . ':' . $param . '>';
726     }
727     }
728     }
729     $result . ']';
730     },
731     li => sub {
732     my $source = shift;
733     my $result = ({qw/ul - ol =/}->{$opt->{o}->{var}->{sw09__list_type}}
734     x $opt->{o}->{var}->{sw09__list_depth})
735     . ' ' . $x2t{'#flow'}->($source);
736     $result;
737     },
738     dt => sub {
739     ':' . $x2t{'#inline'}->(return, no_newline => 1) . ':';
740     },
741     h => sub {
742     ("*" x ($opt->{o}->{var}->{ws__section_depth} - 1))
743     . " "
744     . $x2t{'#inline'}->(shift, no_newline => 1);
745     },
746     'anchor-end' => sub {
747     return shift->inner_text;
748     },
749     'anchor-internal' => sub {
750     return shift->inner_text;
751     },
752     'anchor-external' => sub {
753     return '<'.shift->inner_text.'>';
754     },
755     form => sub {
756     my $source = shift;
757     my $ref = $source->get_attribute_value ('ref', default => 'form');
758     my $result = '[[#'.$ref;
759     my $name = $source->get_attribute_value ('id');
760     $name =~ s/([()\\])/\\$1/g;
761     $result .= '(' . $name . ')' if $name;
762     if ($ref eq 'form') {
763     $result .= ":'";
764     my $input = $source->get_attribute_value ('input', default => '');
765     $input =~ s/(['\\])/\\$1/g;
766     $result .= $input . "':'";
767     my $template = $source->get_attribute_value ('template', default => '');
768     $template =~ s/(['\\])/\\$1/g;
769     $result .= $template . "'";
770     my $option = $source->get_attribute_value ('option');
771     if ($option) {
772     $option =~ s/(['\\])/\\$1/g;
773     $result .= ":'" . $option . "'";
774     }
775     } else {
776     my $param = $source->get_attribute_value ('parameter');
777     if ($param) {
778     $result .= ':' . $param;
779     }
780     }
781     $result .= ']]';
782     },
783     pre => sub {
784     my $source = shift;
785     my $result = '[PRE';
786     my $class = $source->get_attribute_value ('class');
787     if ($class) {
788     $class =~ s/([\\()])/\\$1/g;
789     $result .= '(' . $class . ')';
790     }
791     $result .= "[\x0A"
792     . $x2t{'#inline'}->($source);
793     $result .= "\x0A" unless substr ($result, -1) eq "\x0A";
794     $result .= "]PRE]\x0A";
795     },
796     insert => sub {
797     my $source = shift;
798     my $result = '[INS';
799     my $class = $source->get_attribute_value ('class');
800     if ($class) {
801     $class =~ s/([\\()])/\\$1/g;
802     $result .= '(' . $class . ')';
803     }
804     local $opt->{o}->{var}->{sw09__list_depth} = 0;
805     $result .= "[\x0A"
806     . $x2t{'#block'}->($source);
807     $result .= "\x0A" unless substr ($result, -1) eq "\x0A";
808     $result .= "]INS]\x0A";
809     },
810     delete => sub {
811     my $source = shift;
812     my $result = '[DEL';
813     my $class = $source->get_attribute_value ('class');
814     if ($class) {
815     $class =~ s/([\\()])/\\$1/g;
816     $result .= '(' . $class . ')';
817     }
818     local $opt->{o}->{var}->{sw09__list_depth} = 0;
819     $result .= "[\x0A"
820     . $x2t{'#block'}->($source);
821     $result .= "\x0A" unless substr ($result, -1) eq "\x0A";
822     $result .= "]DEL]\x0A";
823     },
824     document => sub {
825     my $source = shift;
826     my $result = '';
827     for (@{$source->child_nodes}) {
828     $result .= ($x2t{$_->local_name} or $x2t{'#undef'})->($_)
829     if $_->node_type eq '#element';
830     }
831     $result;
832     },
833     head => sub {
834     my $source = shift;
835     my $result = '';
836     for (@{$source->child_nodes}) {
837     if ($_->node_type eq '#element' and
838     $_->local_name eq 'parameter') {
839     $result .= ' '.$x2t{parameter}->($_);
840     }
841     }
842     $result . "\x0A";
843     },
844     parameter => sub {
845     my $source = shift;
846     my $result = $source->get_attribute_value ('name', default => '')
847     . '="';
848     my @v;
849     for (@{$source->child_nodes}) {
850     push @v, $x2t{value}->($_) if $_->node_type eq '#element' and
851     $_->local_name eq 'value';
852     }
853     $result .= join ',', @v;
854     $result . '"';
855     },
856     value => sub {
857     my $value = $x2t{'#inline'}->(shift, no_newline => 1);
858     $value =~ s/(["\\])/\\$1/g;
859     $value =~ tr/\x0A\x0D/ /;
860     $value;
861     },
862     section => sub {
863     local $opt->{o}->{var}->{ws__section_depth}
864     = $opt->{o}->{var}->{ws__section_depth} + 1;
865     $x2t{'#block'}->(shift);
866     },
867     body => sub {
868     local $opt->{o}->{var}->{ws__section_depth} = 1;
869     $x2t{'#block'}->(shift);
870     },
871     text => sub {
872     my ($source, %opt) = @_;
873     my $result .= '';
874     for (@{$source->child_nodes}) {
875     if ($_->node_type eq '#text') {
876     $result .= $_->inner_text;
877     } elsif ($_->node_type eq '#element') {
878     $result .= ($x2t{$_->local_name} or $x2t{'#undef'})->($_);
879     }
880     }
881     $result;
882     },
883     dr => sub {
884     my $result = $x2t{'#list'}->(shift);
885     if ($result) {
886     $result . "\x0A";
887     } else {
888     "::\x0A";
889     }
890     },
891     dt => sub {
892     ':' . $x2t{'#inline'}->(shift, no_newline => 1) . ':';
893     },
894     dd => sub {
895     $x2t{'#inline'}->(shift);
896     },
897     tr => sub {
898     my $result = $x2t{'#list'}->(shift);
899     if ($result) {
900     substr ($result, 1) . "\x0A";
901     } else {
902     "',\x0A";
903     }
904     },
905     td => sub {
906     my $source = shift;
907     my $result = $x2t{'#inline'}->($source, no_newline => 1);
908     if ($result =~ /[,"\\]/ or $result =~ /==/) {
909     $result =~ s/(["\\])/\\$1/g;
910     $result = '"' . $result . '"';
911     }
912     my $colspan = $source->get_attribute_value ('colspan', default => 1);
913     $result .= ("\t,==" x ($colspan - 1)) if $colspan > 1;
914     "\t," . $result;
915     },
916     em => sub {
917     "''" . $x2t{'#inline'}->($_, no_newline => 1) . "''";
918     },
919     strong => => sub {
920     "'''" . $x2t{'#inline'}->($_, no_newline => 1) . "'''";
921     },
922     rb => sub {
923     $x2t{'#inline'}->(shift, no_newline => 1);
924     },
925     rt => sub {
926 hero 1.1.2.1 '] [' . $x2t{'#inline'}->(shift, no_newline => 1);
927 wakaba 1.1 },
928     replace => sub {
929     '__&&' . shift->get_attribute_value ('by', default => '') . '&&__';
930     },
931     bodytext => sub {
932     my ($source, %opt) = @_;
933     local $opt->{o}->{var}->{sw09__bq_depth}
934     = $opt->{o}->{var}->{sw09__bq_depth} + 1;
935     my @result;
936     for (@{$source->child_nodes}) {
937     if ($_->node_type eq '#element') {
938     my $ln = $_->local_name;
939     push @result, [($x2t{$ln} or $x2t{'#undef'})->($_),
940     $ln];
941     }
942     }
943     my $result = '';
944     my $prev = '';
945     for (@result) {
946     my $s = $_->[0];
947 hero 1.1.2.1 if ($_->[1] eq 'p') {
948 wakaba 1.1 $result .= "\x0A" if length $result and
949     substr ($result, -1) ne "\x0A";
950     $result .= ('>' x $opt->{o}->{var}->{sw09__bq_depth}) . ' ';
951     } elsif ($_->[1] eq 'form' or $_->[1] eq 'replace') {
952     $result .= "\x0A" if length $result and
953     substr ($result, -1) ne "\x0A";
954     $result .= ('>' x $opt->{o}->{var}->{sw09__bq_depth})."\x0A";
955     } elsif ($_->[1] eq 'blockquote' or $_->[1] eq 'text') {
956     $result .= "\x0A" if length $result and
957     substr ($result, -1) ne "\x0A";
958     } else {
959     unless ($prev eq 'text') {
960     $result .= "\x0A" if length $result and
961     substr ($result, -1) ne "\x0A";
962     }
963     $result .= ('>' x $opt->{o}->{var}->{sw09__bq_depth})."\x0A";
964     }
965     $result .= $s;
966     $prev = $_->[1];
967     }
968     $result;
969     },
970     image => sub {
971     my ($source, %opt) = @_;
972     return "\x0A__IMAGE__\x0A" . $source->inner_text . "\x0A";
973     },
974     '#block' => sub {
975     my ($source, %opt) = @_;
976     my @result;
977     for (@{$source->child_nodes}) {
978     if ($_->node_type eq '#element') {
979     my $ln = $_->local_name;
980     push @result, [($x2t{$ln} or $x2t{'#undef'})->($_),
981     $ln];
982     }
983     }
984     my $result = '';
985     my $prev = '';
986     for (@result) {
987     my $s = $_->[0];
988     if ($_->[1] eq 'form') {
989     $result .= "\x0A" if length $result and
990     substr ($result, -1) ne "\x0A";
991     $result .= "\x0A";
992     } elsif ($_->[1] eq 'replace') {
993     $result .= "\x0A" if length $result and
994     substr ($result, -1) ne "\x0A";
995     } elsif ($_->[1] eq 'text') {
996     $result .= "\x0A" if length $result and
997     substr ($result, -1) ne "\x0A";
998 hero 1.1.2.1 $result .= "\x0A" if $prev eq 'p';
999 wakaba 1.1 } else {
1000     if ($prev ne 'text' and $prev ne 'replace') {
1001     $result .= "\x0A" if length $result and
1002     substr ($result, -1) ne "\x0A";
1003     $result .= "\x0A";
1004     }
1005     }
1006     $result .= $s;
1007     $prev = $_->[1];
1008     }
1009     $result;
1010     },
1011     '#flow' => sub {
1012     my ($source, %opt) = @_;
1013     my @result;
1014     for (@{$source->child_nodes}) {
1015     if ($_->node_type eq '#element') {
1016     my $ln = $_->local_name;
1017     if ($is_block{$ln}) {
1018     push @result, [($x2t{$ln} or $x2t{'#undef'})->($_),
1019     $ln];
1020     } else {
1021     if (@result and ($result[$#result]->[1] eq '#inline')) {
1022     $result[$#result]->[0]
1023     .= ($x2t{$ln} or $x2t{'#undef'})->($_);
1024     } else {
1025     push @result, [($x2t{$ln} or $x2t{'#undef'})->($_),
1026     '#inline'];
1027     }
1028     }
1029     } elsif ($_->node_type eq '#text') {
1030     if (@result and ($result[$#result]->[1] eq '#inline')) {
1031     $result[$#result]->[0] .= $_->inner_text;
1032     } else {
1033     push @result, [$_->inner_text, '#inline'];
1034     }
1035     }
1036     }
1037     my $result = '';
1038     my $prev = '';
1039     for (@result) {
1040     my $s = $_->[0];
1041     if ($_->[1] eq '#inline') {
1042     if ($prev ne 'text' and $prev ne 'form' and $prev ne 'replace') {
1043     $result .= "\x0A" if length $result and
1044     substr ($result, -1) ne "\x0A";
1045     }
1046     $s =~ s/\x0D\x0A/\x0A/g;
1047     $s =~ s/\x0D/\x0A/g;
1048     $s =~ s/\x0A\x0A+/\x0A/g;
1049     $s =~ s/\x0A/\x20/g if $opt{no_newline};
1050     } elsif ($_->[1] eq 'form' or $_->[1] eq 'replace') {
1051     if ($prev ne '#inline') {
1052     $result .= "\x0A" if length $result and
1053     substr ($result, -1) ne "\x0A";
1054     }
1055     } elsif ($_->[1] eq 'text') {
1056     $result .= "\x0A" if length $result and
1057     substr ($result, -1) ne "\x0A";
1058     } else {
1059     unless ($prev eq 'text') {
1060     $result .= "\x0A" if length $result and
1061     substr ($result, -1) ne "\x0A";
1062     }
1063     }
1064     $result .= $s;
1065     $prev = $_->[1];
1066     }
1067     $result;
1068     },
1069     '#inline' => sub {
1070     my ($source, %opt) = @_;
1071     my $result .= '';
1072     for (@{$source->child_nodes}) {
1073     if ($_->node_type eq '#text') {
1074     $result .= $_->inner_text;
1075     } elsif ($_->node_type eq '#element') {
1076     $result .= ($x2t{$_->local_name} or $x2t{'#undef'})->($_);
1077     }
1078     }
1079     $result =~ s/\x0D\x0A/\x0A/g;
1080     $result =~ s/\x0D/\x0A/g;
1081     $result =~ s/\x0A\x0A+/\x0A/g;
1082     $result =~ s/\x0A/\x20/g if $opt{no_newline};
1083     $result;
1084     },
1085     '#list' => sub {
1086     my ($source, %opt) = @_;
1087     my $result .= '';
1088     for (@{$source->child_nodes}) {
1089     if ($_->node_type eq '#element') {
1090     $result .= ($x2t{$_->local_name} or $x2t{'#undef'})->($_);
1091     }
1092     }
1093     $result;
1094     },
1095     '#undef' => sub {
1096     my $source = shift;
1097     "<".$source->namespace_uri.">:".$source->local_name
1098     . $x2t{'#inline'}->($source);
1099     },
1100     );
1101     for (qw/blockquote dl tbody table/) {
1102     $x2t{$_} = sub { $x2t{'#list'}->(shift) };
1103     }
1104     for (qw/p dd/) {
1105     $x2t{$_} = sub { $x2t{'#flow'}->(shift) };
1106     }
1107     for my $type (qw/ul ol/) {
1108     $x2t{$type} = sub {
1109     my $source = shift;
1110     local $opt->{o}->{var}->{sw09__list_type} = $type;
1111     local $opt->{o}->{var}->{sw09__list_depth}
1112     = $opt->{o}->{var}->{sw09__list_depth} + 1;
1113     my @result;
1114     for (@{$source->child_nodes}) {
1115     push @result, $x2t{$_->local_name}->($_)
1116     if $_->node_type eq '#element';
1117     }
1118     my $result = '';
1119     for (@result) {
1120     $result .= "\x0A" unless substr ($result, -1) eq "\x0A";
1121     $result .= $_;
1122     }
1123     substr ($result, 1);
1124     };
1125     }
1126     for my $type (qw/code samp var dfn kbd sub sup weak q ruby rubyb
1127 hero 1.1.2.1 abbr ins del aa src cite key/) {
1128 wakaba 1.1 $x2t{$type} = sub {
1129     my $source = shift;
1130     my $result = '['.uc $type;
1131     my $class = $source->get_attribute_value ('class', default => '');
1132     if ($class) {
1133     $class =~ s/([()\\])/\\$1/g;
1134     $result .= '(' . $class . ')';
1135     }
1136     $result .= '['
1137     . $x2t{'#inline'}->($source, no_newline => 1)
1138     . ']';
1139     my $anchor = $source->get_attribute_value
1140     ('anchor',
1141     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
1142     default => '');
1143     if (length $anchor) {
1144     $result .= '>>'.(0+$anchor);
1145     } else {
1146     $anchor = $source->get_attribute_value
1147     ('resScheme',
1148     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#);
1149     if ($anchor) {
1150     my $param = $source->get_attribute_value
1151     ('resParameter',
1152     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#);
1153     if ($anchor eq 'URI' and $param =~ /^[0-9A-Za-z_+.%-]+:/) {
1154     $result .= '<' . $param . '>';
1155     } else {
1156     $result .= '<' . $anchor . ':' . $param . '>';
1157     }
1158     }
1159     }
1160     $result .= ']';
1161     $result;
1162     };
1163     }
1164     $x2t{'#list'}->($src);
1165     }
1166    
1167     #line 1 "(WikiPlugin module SuikaWiki09, chunk 13)"
1168    
1169    
1170    
1171     sub get_nth_element {
1172    
1173     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block Function[Name='get_nth_element']/Main)"
1174     my (undef, $node, $ns => $ln, $n) = @_;
1175     return $n if $n < 1;
1176     if ($node->node_type eq '#element' and
1177     $node->namespace_uri eq $ns and
1178     $node->local_name eq $ln) {
1179     return $node unless --$n;
1180     }
1181     for (@{$node->child_nodes}) {
1182     if ($_->node_type eq '#element') {
1183     if ($_->namespace_uri eq $ns and
1184     $_->local_name eq $ln) {
1185     return $_ unless --$n;
1186     } else {
1187 hero 1.1.2.1 $n = SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->get_nth_element ($_, $ns => $ln, $n);
1188 wakaba 1.1 return $n if ref $n;
1189     }
1190     } elsif ($_->node_type eq '#fragment' or $_->node_type eq '#document') {
1191 hero 1.1.2.1 $n = SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->get_nth_element ($_, $ns => $ln, $n);
1192 wakaba 1.1 return $n if ref $n;
1193     }
1194     }
1195     return $n;
1196     }
1197    
1198     #line 1 "(WikiPlugin module SuikaWiki09, chunk 14)"
1199    
1200    
1201    
1202     sub get_element_by_id {
1203    
1204     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block Function[Name='get_element_by_id']/Main)"
1205     my (undef, $node, $id) = @_;
1206     return $node if $node->node_type eq '#element'
1207     and $node->get_attribute_value ('id', default_value => '')
1208     eq $id;
1209     for (@{$node->child_nodes}) {
1210     if ({'#element'=>1, '#fragment'=>1, '#document'=>1}->{$_->node_type}) {
1211 hero 1.1.2.1 my $r = SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->get_element_by_id ($_, $id);
1212 wakaba 1.1 return $r if $r;
1213     }
1214     }
1215     }
1216    
1217     #line 1 "(WikiPlugin module SuikaWiki09, chunk 15)"
1218    
1219    
1220    
1221     sub text_to_xml {
1222    
1223     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block Function[Name='text_to_xml']/Main)"
1224     my (undef, $source, $opt) = @_;
1225     $source =~ s/\x0D\x0A/\x0A/g;
1226     $source =~ tr/\x0D/\x0A/;
1227     $source .= "\x0A";
1228     my $root = $opt->{-parent}
1229     ->append_new_node (type => '#element',
1230     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
1231     local_name => 'document');
1232     my $head = $root->append_new_node (type => '#element',
1233 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1234 wakaba 1.1 local_name => 'head');
1235     $root->append_text ("\x0A");
1236     my $body = $root->append_new_node (type => '#element',
1237 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1238 wakaba 1.1 local_name => 'body');
1239     $root->append_text ("\x0A");
1240     if ($source =~ s#^\#\?(SuikaWiki(?:Image)?)/0\.9\b((?>.*))\s*##) {
1241     my $type = $1;
1242     my $param = $2;
1243     $root->set_attribute (Name => $type, namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#);
1244     $root->set_attribute (Version => '0.9', namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#);
1245     while ($param =~ /\G\s+([a-z-]+)="((?>[^"\\]*)(?>(?>[^"\\]+|\\.)*))"/g) {
1246     my ($name, $value) = ($1, $2);
1247     $value =~ s/\\(.)/$1/g;
1248     for ($head->append_new_node (type => '#element',
1249     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
1250     local_name => 'parameter')) {
1251     $_->set_attribute (name => $name);
1252     for my $value (split /,/, $value) {
1253     $_->append_new_node (type => '#element',
1254     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
1255     local_name => 'value')
1256     ->append_text ($value);
1257     }
1258     }
1259     $head->append_text ("\x0A");
1260     }
1261     if ($type eq 'SuikaWikiImage') {
1262     $source =~ s/\x0A__IMAGE__\x0A(.*)$//s;
1263     if (my $image = $1) {
1264     $image =~ s/^\s+//;
1265     $image =~ s/\s+$//;
1266     $root->append_new_node
1267     (type => '#element',
1268     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
1269     local_name => 'image')
1270     ->append_text ($image);
1271     $root->append_text ("\x0A");
1272     }
1273     }
1274     } else {
1275     }
1276 hero 1.1.2.1 SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->block_text_to_xml (\$source => $body, opt => $opt);
1277 wakaba 1.1 }
1278    
1279     #line 1 "(WikiPlugin module SuikaWiki09, chunk 16)"
1280    
1281    
1282    
1283     sub block_text_to_xml {
1284    
1285     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block Function[Name='block_text_to_xml']/Main)"
1286     my (undef, $source, $current, %opt) = @_;
1287     my %depth = %{$opt{depth} || {}};
1288     my $back_to_section = sub {
1289     my $cur_type = $current->local_name;
1290     while (not (
1291     $cur_type eq 'section'
1292     or $cur_type eq 'body'
1293     or $cur_type eq 'bodytext'
1294     or $cur_type eq 'insert'
1295     or $cur_type eq 'delete'
1296     )
1297     ) {
1298     $current = $current->parent_node;
1299     $cur_type = $current->local_name;
1300     }
1301     delete $depth{list};
1302     };
1303     my $back_to_real_section = sub {
1304     my $cur_type = $current->local_name;
1305     while (not (
1306     $cur_type eq 'section'
1307     or $cur_type eq 'body'
1308     or $cur_type eq 'insert'
1309     or $cur_type eq 'delete'
1310     )
1311     ) {
1312     $current = $current->parent_node;
1313     $cur_type = $current->local_name;
1314     }
1315     delete $depth{bq};
1316     delete $depth{list};
1317     };
1318     while ($$source =~ /\G([^\x0A]*)\x0A/gc) {
1319     my $line = $1;
1320     if ($line eq '') {
1321     $back_to_real_section->();
1322     } elsif ($line =~ s/^([-=]+)\s*//) {
1323     my $list_type = substr ($1, -1) eq '-' ? 'ul' : 'ol';
1324     my $depth = length $1;
1325     my $parent_type = $current->parent_node->local_name;
1326     if ($parent_type eq 'ul' or $parent_type eq 'ol') {
1327     if ($depth{list} == $depth) {
1328     if ($parent_type eq $list_type) {
1329     $current = $current->parent_node;
1330     } else {
1331     $current = $current->parent_node
1332     ->parent_node
1333     ->append_new_node
1334     (type => '#element',
1335 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1336 wakaba 1.1 local_name => $list_type);
1337     }
1338     } elsif ($depth < $depth{list}) {
1339     for ($depth+1..$depth{list}) {
1340     $current = $current->parent_node->parent_node;
1341     }
1342     $current = $current->parent_node;
1343     if ($current->local_name ne $list_type) {
1344     $current = $current->parent_node
1345     ->append_new_node
1346     (type => '#element',
1347 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1348 wakaba 1.1 local_name => $list_type);
1349     }
1350     $depth{list} = $depth;
1351     } else { # $depth{list} < $depth
1352     $current = $current->append_new_node
1353     (type => '#element',
1354 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1355 wakaba 1.1 local_name => $list_type);
1356     $depth{list}++;
1357     }
1358     } else {
1359     $current = $current->append_new_node (type => '#element',
1360 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1361 wakaba 1.1 local_name => $list_type);
1362     $depth{list} = 1;
1363     }
1364     $current->append_text ("\x0A".(" " x $depth{list}));
1365     $current = $current->append_new_node (type => '#element',
1366 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1367 wakaba 1.1 local_name => 'li');
1368 hero 1.1.2.1 SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->inline_text_to_xml (\$line => $current, %opt);
1369 wakaba 1.1 } elsif ($line =~ s/^(\*+)\s*//) {
1370     my $depth = length $1;
1371     $back_to_real_section->();
1372     if ($depth <= $depth{section}) {
1373     for ($depth..$depth{section}) {
1374     $back_to_real_section->();
1375     $current = $current->parent_node;
1376     }
1377     $depth{section} = $depth;
1378     } else { # $depth{section} < $depth
1379     for ($depth{section}+2..$depth) {
1380     $current = $current->append_new_node
1381     (type => '#element',
1382 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1383 wakaba 1.1 local_name => 'section');
1384     }
1385     $depth{section} = $depth;
1386     }
1387     $current = $current->append_new_node
1388     (type => '#element',
1389 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1390 wakaba 1.1 local_name => 'section');
1391 hero 1.1.2.1 SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->inline_text_to_xml (\$line =>
1392 wakaba 1.1 $current->append_new_node (type => '#element',
1393 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1394 wakaba 1.1 local_name => 'h'), %opt,
1395     );
1396     } elsif ($line =~ s/^(?!>>[0-9])(>+)\s*//) {
1397     my $depth = length $1;
1398     if ($depth <= $depth{bq}) {
1399     for ($depth+1..$depth{bq}) {
1400     $back_to_section->();
1401     $current = $current->parent_node->parent_node;
1402     }
1403     $back_to_section->();
1404     $current->append_text ("\x0A");
1405     $depth{bq} = $depth;
1406     } else { # $depth{bq} < $depth
1407     $back_to_section->();
1408     for ($depth{bq}+1..$depth) {
1409     $current = $current->append_new_node
1410     (type => '#element',
1411 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1412 wakaba 1.1 local_name => 'blockquote')
1413     ->append_new_node
1414     (type => '#element',
1415     namespace_uri => q#urn:x-suika-fam-cx:markup:ietf:html:3:draft:00:#,
1416     local_name => 'bodytext');
1417     $current->append_text ("\x0A");
1418     }
1419     $depth{bq} = $depth;
1420     }
1421     if (length $line) {
1422     $current = $current->append_new_node
1423     (type => '#element',
1424 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1425 wakaba 1.1 local_name => 'p');
1426 hero 1.1.2.1 SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->inline_text_to_xml (\$line => $current, %opt);
1427 wakaba 1.1 }
1428     } elsif ($line =~ s/^(?>:\s*)([^:]+?)\s*:\s*//) {
1429     my $parent_type = $current->local_name;
1430     if ($parent_type eq 'dd') {
1431     $current = $current->parent_node->parent_node;
1432     $current->append_text ("\x0A");
1433     } else { #if ($parent_type ne 'dl') {
1434     $current = $current->append_new_node (type => '#element',
1435 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1436 wakaba 1.1 local_name => 'dl');
1437     }
1438     $current = $current->append_new_node
1439     (type => '#element',
1440     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
1441     local_name => 'dr');
1442 hero 1.1.2.1 SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->inline_text_to_xml (\"$1" =>
1443 wakaba 1.1 $current->append_new_node (type => '#element',
1444 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1445 wakaba 1.1 local_name => 'dt'), %opt,
1446     );
1447     $current->append_text ("\x0A");
1448     $current = $current->append_new_node (type => '#element',
1449 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1450 wakaba 1.1 local_name => 'dd');
1451 hero 1.1.2.1 SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->inline_text_to_xml (\$line => $current, %opt);
1452 wakaba 1.1 } elsif ($line =~ /^\[(INS|DEL)(?>(\([^()\\]*\))?)\[\s*$/) {
1453     $current->append_text ("\x0A");
1454     my $mod = $current->append_new_node
1455     (type => '#element',
1456     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
1457     local_name => {qw/INS insert DEL delete/}->{$1});
1458     $mod->set_attribute (class => $2) if $2;
1459 hero 1.1.2.1 SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->block_text_to_xml ($source => $mod, %opt,
1460 wakaba 1.1 'return_by_'.$1 => 1,
1461     depth => \%depth);
1462     } elsif ($line =~ /^\](INS|DEL)\]\s*$/) {
1463     if ($opt{'return_by_'.$1}) {
1464     return;
1465     } else {
1466     }
1467     } elsif ($line =~ /^\[PRE(?>(?>\(((?>[^()\\]*)(?>(?>[^()\\]+|\\.)*))\))?)\[\s*$/) {
1468     $current->append_text ("\x0A");
1469     my $pre = $current->append_new_node (type => '#element',
1470     namespace_uri => q#http://www.w3.org/1999/xhtml#,
1471     local_name => 'pre');
1472     $pre->set_attribute (class => $1) if $1;
1473     $pre->set_attribute (space => 'preserve', namespace_uri => NS_xml_URI);
1474     my $f = 1;
1475     while ($$source =~ /\G([^\x0A]*)\x0A/gc) {
1476     my $line = $1;
1477     if ($line =~ /^\]PRE\]\s*$/) {
1478     undef $pre;
1479     last;
1480     } else {
1481     $f ? undef $f : $pre->append_text ("\x0A");
1482 hero 1.1.2.1 SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->inline_text_to_xml (\$line => $pre, %opt);
1483 wakaba 1.1 }
1484     }
1485     if (ref $pre) {
1486     }
1487     } elsif ($line =~ /^\s/) {
1488     $current->append_text ("\x0A");
1489     my $pre = $current->append_new_node (type => '#element',
1490     namespace_uri => q#http://www.w3.org/1999/xhtml#,
1491     local_name => 'pre');
1492     $pre->set_attribute (space => 'preserve', namespace_uri => NS_xml_URI);
1493 hero 1.1.2.1 SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->inline_text_to_xml (\$line => $pre, %opt);
1494 wakaba 1.1 while ($$source =~ /\G([^\x0A]*)\x0A/gc) {
1495     my $line = $1;
1496     if (length $line == 0) {
1497     pos ($$source) -= 1;
1498     last;
1499     } elsif ($opt{return_by_INS} and $line =~ /^\]INS\]\s*$/) {
1500     return;
1501     } elsif ($opt{return_by_DEL} and $line =~ /^\]DEL\]\s*$/) {
1502     return;
1503     } else {
1504     $pre->append_text ("\x0A");
1505 hero 1.1.2.1 SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->inline_text_to_xml (\$line => $pre, %opt);
1506 wakaba 1.1 }
1507     }
1508     } elsif ($line =~ /^,/) {
1509     $current->append_text ("\x0A");
1510     my $tbody = $current->append_new_node (type => '#element',
1511 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1512 wakaba 1.1 local_name => 'table')
1513     ->append_new_node (type => '#element',
1514 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1515 wakaba 1.1 local_name => 'tbody');
1516 hero 1.1.2.1 SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->tablerow_text_to_xml (\$line => $tbody, %opt);
1517 wakaba 1.1 while ($$source =~ /\G(,[^\x0A]*)\x0A/gc) {
1518 hero 1.1.2.1 SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->tablerow_text_to_xml (\"$1" => $tbody, %opt);
1519 wakaba 1.1 }
1520     } else {
1521     my $current_type = $current->local_name;
1522     if ($current_type eq 'section'
1523     or $current_type eq 'body'
1524     or $current_type eq 'bodytext'
1525     or $current_type eq 'insert'
1526     or $current_type eq 'delete') {
1527     $current->append_text ("\x0A");
1528     if ($line =~ s/^__&&([^&]+)&&__//) {
1529     $current->append_new_node (type => '#element',
1530     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
1531     local_name => 'replace')
1532     ->set_attribute (by => $1);
1533     } elsif ($line =~ s/^\[\[$Reg_Form_Content_M\]\]//o) {
1534     for ($current->append_new_node (type => '#element',
1535     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
1536     local_name => 'form')) {
1537     $_->set_attribute (id => $1) if $1;
1538     my ($i, $t, $o) = ($2, $3 || '', $4 || '');
1539     s/\\(.)/$1/g for ($i, $t, $o);
1540     $_->set_attribute (input => $i);
1541     $_->set_attribute (template => $t);
1542     $_->set_attribute (option => $o);
1543     }
1544     } elsif ($line =~ s/^\[\[$Reg_Embed_Content_M\]\]//o) {
1545     for ($current->append_new_node (type => '#element',
1546     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
1547     local_name => 'form')) {
1548     $_->set_attribute (ref => $1);
1549     $_->set_attribute (id => $2) if $2;
1550     $_->set_attribute (parameter => $3) if defined $3;
1551     }
1552     }
1553     if (length $line) {
1554     $current = $current->append_new_node
1555     (type => '#element',
1556 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1557 wakaba 1.1 local_name => 'p');
1558 hero 1.1.2.1 SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->inline_text_to_xml (\$line => $current, %opt);
1559 wakaba 1.1 }
1560     } else {
1561     $current->append_text ("\x0A"); # replacement of prev.line's \n
1562 hero 1.1.2.1 SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->inline_text_to_xml (\$line => $current, %opt);
1563 wakaba 1.1 }
1564     }
1565     }
1566     if ($opt{return_by_INS} or $opt{return_by_DEL}) {
1567     }
1568     }
1569    
1570     #line 1 "(WikiPlugin module SuikaWiki09, chunk 17)"
1571    
1572    
1573    
1574     sub tablerow_text_to_xml {
1575    
1576     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block Function[Name='tablerow_text_to_xml']/Main)"
1577     my (undef, $source => $current, %opt) = @_;
1578     $current->append_text ("\x0A");
1579     $current = $current->append_new_node (type => '#element',
1580 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1581 wakaba 1.1 local_name => 'tr');
1582     my $prev_cell;
1583     while ($$source =~ /\G,\s*/gc) {
1584     $$source =~ /\G([^,"][^,]*|"(?>[^"\\]*)(?>(?>[^"\\]+|\\.)*)"\s*)/gc;
1585     my $cell = $1;
1586     if ($cell =~ s/^"//) {
1587     $cell =~ s/"\s*$//g;
1588     $cell =~ s/\\(.)/$1/g;
1589     } else {
1590     $cell =~ s/\s+$//g;
1591     if ($cell eq '==') {
1592     if (ref $prev_cell) {
1593     $prev_cell->set_attribute (colspan =>
1594     $prev_cell->get_attribute_value ('colspan', default => 1)
1595     + 1);
1596     next;
1597     } else {
1598     }
1599     }
1600     }
1601     $prev_cell = $current->append_new_node
1602     (type => '#element',
1603 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1604 wakaba 1.1 local_name => 'td');
1605 hero 1.1.2.1 SuikaWiki::Plugin::plugin::SuikaWiki091040731032806TprE->inline_text_to_xml (\$cell => $prev_cell, %opt);
1606 wakaba 1.1 }
1607     }
1608    
1609     #line 1 "(WikiPlugin module SuikaWiki09, chunk 18)"
1610    
1611    
1612    
1613     sub inline_text_to_xml {
1614    
1615     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block Function[Name='inline_text_to_xml']/Main)"
1616     my (undef, $source => $current, %opt) = @_;
1617     my $ElementDef = {
1618 hero 1.1.2.1 ABBR => {ln => 'abbr', ns_uri => q#http://www.w3.org/2002/06/xhtml2#},
1619     CODE => {ln => 'code', ns_uri => q#http://www.w3.org/2002/06/xhtml2#},
1620 wakaba 1.1 DEL => {ln => 'del', ns_uri => q#http://www.w3.org/1999/xhtml#},
1621 hero 1.1.2.1 DFN => {ln => 'dfn', ns_uri => q#http://www.w3.org/2002/06/xhtml2#},
1622 wakaba 1.1 INS => {ln => 'ins', ns_uri => q#http://www.w3.org/1999/xhtml#},
1623 hero 1.1.2.1 KBD => {ln => 'kbd', ns_uri => q#http://www.w3.org/2002/06/xhtml2#},
1624 wakaba 1.1 Q => {ln => 'q', ns_uri => q#http://www.w3.org/1999/xhtml#},
1625 hero 1.1.2.1 RUBY => {ln => 'ruby', ns_uri => q#http://www.w3.org/2002/06/xhtml2#},
1626 wakaba 1.1 RUBYB => {ln => 'rubyb', ns_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#},
1627 hero 1.1.2.1 SAMP => {ln => 'samp', ns_uri => q#http://www.w3.org/2002/06/xhtml2#},
1628     SUB => {ln => 'sub', ns_uri => q#http://www.w3.org/2002/06/xhtml2#},
1629     SUP => {ln => 'sup', ns_uri => q#http://www.w3.org/2002/06/xhtml2#},
1630     VAR => {ln => 'var', ns_uri => q#http://www.w3.org/2002/06/xhtml2#},
1631 wakaba 1.1 WEAK => {ln => 'weak', ns_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#},
1632 hero 1.1.2.1 AA => {ln => 'aa', ns_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:10:#}, ## SuikaWiki/0.10
1633     CITE => {ln => 'cite', ns_uri => q#http://www.w3.org/2002/06/xhtml2#}, ## SuikaWiki/0.10
1634 wakaba 1.1 KEY => {ln => 'key', ns_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:10:#}, ## SuikaWiki/0.10
1635     SRC => {ln => 'src', ns_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:10:#}, ## SuikaWiki/0.10
1636     anchor => {ln => 'anchor', ns_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#, has_fragment_no => 1},
1637     del => {has_cite => 1},
1638     ins => {has_cite => 1},
1639     q => {has_cite => 1},
1640 hero 1.1.2.1 rb => {ln => 'rb', ns_uri => q#http://www.w3.org/2002/06/xhtml2#, is_nested => 1},
1641     rt => {ln => 'rt', ns_uri => q#http://www.w3.org/2002/06/xhtml2#, is_nested => 1},
1642 wakaba 1.1 };
1643     if ($$source =~ /\G\[([0-9]+)\]/gc) {
1644     for ($current->append_new_node (type => '#element',
1645     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
1646     local_name => 'anchor-end')) {
1647     $_->set_attribute (anchor => 0+$1,
1648     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#);
1649     $_->append_text ('['.$1.']');
1650     }
1651     }
1652     my $depth = 0;
1653     while (pos $$source < length $$source) {
1654     if ($$source =~ /\G\[\[(?=\#)/gc) {
1655     my $form = $current->append_new_node (type => '#element',
1656     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
1657     local_name => 'form');
1658     if ($$source =~ /\G$Reg_Form_Content_M\]\]/ogc) {
1659     $form->set_attribute (id => $1) if $1;
1660     my ($i, $t, $o) = ($2, $3, $4);
1661     s/\\(.)/$1/g for ($i, $t, $o);
1662     $form->set_attribute (input => $i);
1663     $form->set_attribute (template => $t);
1664     $form->set_attribute (option => $o);
1665     } elsif ($$source =~ /\G$Reg_Embed_Content_M\]\]/ogc) {
1666     $form->set_attribute (ref => $1);
1667     $form->set_attribute (id => $2) if $2;
1668     $form->set_attribute (parameter => $3) if defined $3;
1669     } else {
1670     SuikaWiki::Plugin->module_package('Error')->report_error_simple ($opt{opt}->{o}->{wiki}, InvalidForm => substr ($$source, pos ($$source)));
1671     }
1672 hero 1.1.2.1 } elsif ($$source =~ /\G\[(?>([A-Z]+)(?>\(((?>[^()\\]*)(?>(?>[^()\\]+|\\.)*))\))?)?\[/gc) {
1673 wakaba 1.1 my $type = $1 || 'anchor';
1674     my $param = $2;
1675     my $def = $ElementDef->{ $type };
1676     unless ($def) {
1677     $def = $ElementDef->{CODE};
1678     }
1679     $current = $current->append_new_node (type => '#element',
1680     namespace_uri => $def->{ns_uri},
1681     local_name => $def->{ln});
1682     $current->set_attribute (class => $param) if $param;
1683     if ($type eq 'RUBY' or $type eq 'RUBYB'
1684     or $type eq 'ABBR') {
1685     $current = $current->append_new_node
1686     (type => '#element',
1687     namespace_uri => $ElementDef->{rb}->{ns_uri},
1688     local_name => $ElementDef->{rb}->{ln});
1689     }
1690     $depth++;
1691     } elsif ($$source =~ /\G\](?> <([0-9A-Za-z_+.%-]+):($Reg_URI_Opaque)>
1692     | >>([0-9]+) )?
1693     \]/gcox) {
1694     my ($scheme, $opaque, $anchor) = ($1, $2, $3);
1695     unless ($depth) {
1696     $current->append_text (substr ($$source, $-[0], $+[0]-$-[0]));
1697     next;
1698     }
1699     my $def = $ElementDef->{$current->local_name} || {};
1700     if (defined $anchor) {
1701     $current->set_attribute (anchor => $anchor + 0,
1702     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#);
1703     } elsif (defined $scheme) {
1704     if ($scheme =~ /[A-Z]/) {
1705     $current->set_attribute (resScheme => $scheme,
1706     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#);
1707     $current->set_attribute (resParameter => $opaque,
1708     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#);
1709     } else {
1710     $current->set_attribute (resScheme => 'URI',
1711     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#);
1712     $current->set_attribute (resParameter => "$scheme:$opaque",
1713     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#);
1714     }
1715     }
1716     $current = $current->parent_node;
1717     $current = $current->parent_node if $def->{is_nested};
1718     $depth--;
1719 hero 1.1.2.1 } elsif ($$source =~ /\G\]\s*\[/gc) {
1720 wakaba 1.1 if ($current->local_name eq 'rb' or $current->local_name eq 'rt') {
1721     $current = $current->parent_node
1722     ->append_new_node
1723     (type => '#element',
1724     namespace_uri => $ElementDef->{rt}->{ns_uri},
1725     local_name => $ElementDef->{rt}->{ln});
1726     } else {
1727     $current->append_text (substr ($$source, $-[0], $+[0]-$-[0]-1));
1728     pos ($$source)--;
1729     }
1730     } elsif ($$source =~ /\G'''?/gc) {
1731     my $type = $+[0] - $-[0] == 3 ? 'strong' : 'em';
1732     if ($current->local_name eq $type) {
1733     $current = $current->parent_node;
1734     } else {
1735     $current = $current->append_new_node
1736     (type => '#element',
1737 hero 1.1.2.1 namespace_uri => q#http://www.w3.org/2002/06/xhtml2#,
1738 wakaba 1.1 local_name => $type);
1739     }
1740     } elsif ($$source =~ /\G<([0-9A-Za-z_+.%-]+):($Reg_URI_Opaque)>/gco) {
1741     my ($scheme, $data) = ($1, $2);
1742     my $link = $current->append_new_node
1743     (type => '#element',
1744     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
1745     local_name => 'anchor-external');
1746     if (substr ($scheme, 0, 1) =~ /[A-Z]/) {
1747     $link->set_attribute (resScheme => $scheme,
1748     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#);
1749     $link->set_attribute (resParameter => $data,
1750     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#);
1751     } else { # URI Reference
1752     $link->set_attribute (resScheme => 'URI',
1753     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#);
1754     $link->set_attribute (resParameter => $scheme.':'.$data,
1755     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#);
1756     }
1757     $link->append_text ($scheme.':'.$data);
1758     } elsif ($$source =~ /\G__&&/gc) {
1759     if ($$source =~ /\G([^&]+)&&__/gc) {
1760     $current->append_new_node
1761     (type => '#element',
1762     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
1763     local_name => 'replace')
1764     ->set_attribute (by => $1);
1765     } else {
1766     $current->append_text ('__&&');
1767     }
1768     } elsif ($$source =~ /\G((?>
1769     [^'\[\]<>_]+
1770     | ' (?!')
1771     | \[ (?!\[|[A-Z]+(?>\([^()\\]*
1772 hero 1.1.2.1 (?>[^()\\]+|\\.)*\))?\[)
1773 wakaba 1.1 | \] (?! \]
1774     | >>[0-9]+\]
1775     | <[0-9A-Za-z_+.%-]+:$Reg_URI_Opaque>\]
1776 hero 1.1.2.1 | \s*\[ )
1777 wakaba 1.1 | < (?![0-9A-Za-z_+.%-]+:$Reg_URI_Opaque>)
1778     | > (?!>[0-9])
1779     | _ (?!_&&)
1780     )+)/oxgc) {
1781     $current->append_text ($1);
1782     } elsif ($$source =~ /\G>>([0-9]+)/gc) {
1783     for ($current->append_new_node (type => '#element',
1784     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#,
1785     local_name => 'anchor-internal')) {
1786     $_->set_attribute (anchor => 0+$1,
1787     namespace_uri => q#urn:x-suika-fam-cx:markup:suikawiki:0:9:#);
1788     $_->append_text ('>>'.$1);
1789     }
1790     } else {
1791     CORE::die "Implementation buggy: ", substr ($$source, pos $$source);
1792     }
1793     }
1794     }
1795    
1796     #line 1 "(WikiPlugin module SuikaWiki09, chunk 19)"
1797    
1798    
1799     {my $def = {q#Parameter#, {}, q#Description#, [[q#Output content of the anchor element#, q#en#, q##]], q#main#, sub {my ($f, $rule_name, $p, $o, %opt) = @_;
1800    
1801     #line 1 "(WikiPlugin module source SuikaWiki09.wp2, block FormattingRule[name()='[q#page-link#, q#link-to-resource#]/sw09__link_anchor_content']/Formatting)"
1802     if ($o->{var}->{sw09__anchor_content}) {
1803     $o->{var}->{sw09__anchor_content}->($p->{-parent});
1804     } else {
1805     ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->append_tree
1806     (name => 'Link:SuikaWiki/0.9:link-anchor-content:InvalidContext',
1807     param => $o,
1808     -parent => $p->{-parent},
1809     wiki => $o->{wiki});
1810     }}}
1811     #line 1 "(WikiPlugin module SuikaWiki09, chunk 20)"
1812     ;
1813     $SuikaWiki::Plugin::Rule{page_link}->{sw09__link_anchor_content} = $def;
1814     $SuikaWiki::Plugin::Rule{link_to_resource}->{sw09__link_anchor_content} = $def;
1815     };
1816    
1817     package SuikaWiki::Plugin::Resource;
1818    
1819     our $BaseResource;
1820     $BaseResource->{q#en#}->{q##}->{q#Link:SuikaWiki/0.9:link-anchor-content:InvalidContext#} = q#%percent;sw09--link-anchor-content; cannot be used in this context.#;
1821     $BaseResource->{q#en#}->{q##}->{q#Link:SuikaWiki/0.9:toResource:SourceLabel#} = q#%select_link_resource_scheme ( URI => {<%link-to-it( label=>{%link-resource-parameters;}p, );>}, IW => {%iw--source-label (default => {<%link-to-it ( label => {%link-resource-scheme;:%link-resource-parameters;}p, );});}, MAIL => {<%link-to-it( label => {%link-resource-parameters;}p, description => {%res (name=>{Link:MailAddress=});<%link-resource-parameters;>}p, );>}, otherwise => {<%link-to-it( label => {%sw09--link-anchor-content;}p, description => {%res (name=>{Link:URIReference=});<%uri-reference;>}p, );>}, );#;
1822     $BaseResource->{q#und#}->{q##}->{q#Link:SuikaWiki/0.9:toWikiPage:SourceLabel#} = q#%link-to-it( label=>{%sw09--link-anchor-content;%if-linked-wikipage-exist( true=>{%if-link-has-dest-anchor-no(true=>{>>%link-dest-anchor-no;});}, false=>{%res(name=>{Link:toWikiPage:NotExist:Mark});} );}p, description=>{%page-name(absolute);; %if-linked-wikipage-exist( true=>{%page-headline;}, false=>{(%res(name=>{Link:toWikiPage:NotExist:Description});)}, );}p, class=>{%if-linked-wikipage-exist(false=>{not-exist});}p, );#;
1823     $BaseResource->{q#und#}->{q##}->{q#SuikaWiki/0.9:form:comment:input#} = q#%line (content => {%textarea (id=>msg,size=>20,lines=>3);}p); %line (content => { (%text (description => {%res (name => {Form:Description:HumanName});}p, id => name, size => 6); [%text (description => {%res (name => {Form:Description:MailAddress});}p, id => mail, size => 5);] %check (default, id => record-date, label => {%res (name => {Form:Label:LogDate});}p, description => {%res (name => {Form:Description:LogDate});}p);) %submit (label => {%res (name => {Form:Label:Add});}p, description => {%res (name => {Form:Description:Add});}p); %we--update-lastmodified-datetime; }p);#;
1824     $BaseResource->{q#und#}->{q##}->{q#SuikaWiki/0.9:form:comment:template#} = q#%n ;[%index;]%n ;%text(source=>msg);%n;(%name;%text(source=>mail,prefix=>" [",suffix=>"]");%iif(source=>record-date,true=>" [WEAK[%date;]]");)%n;#;
1825     $BaseResource->{q#und#}->{q##}->{q#SuikaWiki/0.9:form:comment:option#} = q#%require (msg);#;
1826     $BaseResource->{q#und#}->{q##}->{q#SuikaWiki/0.9:form:footannotate:input#} = q#%line (content => {%textarea (id=>msg,size=>20,lines=>3);}p); %line (content => { (%text (description => {%res (name => {Form:Description:HumanName});}p, id => name, size => 6); [%text (description => {%res (name => {Form:Description:MailAddress});}p, id => mail, size => 5);] %check (default, id => record-date, label => {%res (name => {Form:Label:LogDate});}p, description => {%res (name => {Form:Description:LogDate});}p);) %submit (label => {%res (name => {Form:Label:Add});}p, description => {%res (name => {Form:Description:Add});}p); %we--update-lastmodified-datetime; }p);#;
1827     $BaseResource->{q#und#}->{q##}->{q#SuikaWiki/0.9:form:footannotate:template#} = q#%n ;[%index;]%n ;%text(source=>msg);%n ;(%name;%text(source=>mail,prefix=>" [",suffix=>"]");%iif(source=>record-date,true=>" [WEAK[%date;]]");)%n;#;
1828     $BaseResource->{q#und#}->{q##}->{q#SuikaWiki/0.9:form:footannotate:option#} = q#%require (msg);#;
1829     $BaseResource->{q#en#}->{q##}->{q#WikiFormat:MediaType:Description:IMT:text/x-suikawiki;version="0.9"\#\##} = q#SuikaWiki/0.9 (text format), as used in SuikaWiki 2#;
1830     $BaseResource->{q#en#}->{q##}->{q#WikiFormat:MediaType:Description:IMT:text/x-suikawiki;version="0.10"\#\##} = q#SuikaWiki/0.10 (text format)#;
1831     $BaseResource->{q#en#}->{q##}->{q#WikiFormat:MediaType:Label:IMT:text/x-suikawiki;version="0.9"\#\##} = q#SuikaWiki/0.9 (text)#;
1832     $BaseResource->{q#en#}->{q##}->{q#WikiFormat:MediaType:Label:IMT:text/x-suikawiki;version="0.10"\#\##} = q#SuikaWiki/0.10 (text)#;
1833     $BaseResource->{q#en#}->{q##}->{q#WikiFormat:MediaType:Description:MAGIC:SuikaWiki/0.9\#\##} = q#SuikaWiki/0.9 (text format), as used in SuikaWiki 2#;
1834     $BaseResource->{q#en#}->{q##}->{q#WikiFormat:MediaType:Description:MAGIC:SuikaWiki/0.10\#\##} = q#SuikaWiki/0.10 (text format)#;
1835     $BaseResource->{q#en#}->{q##}->{q#WikiFormat:MediaType:Label:MAGIC:SuikaWiki/0.9\#\##} = q#SuikaWiki/0.9 (text format)#;
1836     $BaseResource->{q#en#}->{q##}->{q#WikiFormat:MediaType:Label:MAGIC:SuikaWiki/0.10\#\##} = q#SuikaWiki/0.10 (text)#;
1837     package SuikaWiki::Plugin::Registry;
1838    
1839     $Info{q#SuikaWiki09#}->{provide} = {q#rule#, {q#link_to_resource#, [q#sw09__link_anchor_content#], q#form_template#, [q#index#], q#page_link#, [q#sw09__link_anchor_content#]}};
1840    
1841     1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24