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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (hide annotations) (download)
Wed Feb 18 07:22:11 2004 UTC (20 years, 8 months ago) by wakaba
Branch: MAIN
Changes since 1.7: +7 -2 lines
WikiDB error reporting bug fixed

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24