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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by wakaba, Sat Dec 13 04:53:59 2003 UTC revision 1.19 by wakaba, Sun Feb 6 12:58:27 2005 UTC
# Line 3  Line 3 
3  Plugin:  Plugin:
4    @Name: SuikaWiki09    @Name: SuikaWiki09
5    @Description:    @Description:
6      @@@: SuikaWiki/0.9 document format      @@@: SuikaWiki/0.9 and SuikaWiki/0.10 document formats
7      @@lang:en      @@lang:en
8    @License: %%GPL%%    @License: %%Perl%%
9    @Author:    @Author:
10      @@Name:      @@Name:
11        @@@@: Wakaba        @@@@: Wakaba
12        @@@lang:ja        @@@lang:ja
13        @@@script:Latn        @@@script:Latn
14      @@Mail[list]: w@suika.fam.cx      @@Mail[list]: w@suika.fam.cx
15    @Date.RCS: $Date$    @Date.RCS:
16        $Date$
17    @RequiredPlugin[list]:    @RequiredPlugin[list]:
18        Edit
19        WikiFormCore
20      WikiLinking      WikiLinking
21        WikiStruct
22    @Use:    @Use:
23      use Message::Markup::XML::QName qw/NS_xml_URI/;      use Message::Markup::XML::QName qw/NS_xml_URI/;
24      my $Reg_Form_Content_M = qr{      my $Reg_Form_Content_M = qr{
# Line 23  Plugin: Line 27  Plugin:
27   \               \( (\w+) \)                                 ## id   \               \( (\w+) \)                                 ## id
28   \             )?   \             )?
29   \             : ' ((?>[^\\']*)(?>(?>[^\\']+|\\.)*)) '       ## input   \             : ' ((?>[^\\']*)(?>(?>[^\\']+|\\.)*)) '       ## input
30   \         (?: : ' ((?>[^\\']*)(?>(?>[^\\']+|\\.)*)) '       ## template   \         (?> : ' ((?>[^\\']*)(?>(?>[^\\']+|\\.)*)) '       ## template
31   \         (?: : ' ((?>[^\\']*)(?>(?>[^\\']+|\\.)*)) ' )? )? ## option   \         (?> : ' ((?>[^\\']*)(?>(?>[^\\']+|\\.)*)) ' )? )? ## option
32      }x;      }x;
33      my $Reg_Embed_Content_M = qr{      my $Reg_Embed_Content_M = qr{
34   \     \#([a-z-]+)   \     \#([a-z-]+)
# Line 45  Plugin: Line 49  Plugin:
49   \     )   \     )
50      }x;      }x;
51    
52        my ($WIKIRESOURCE, $WIKISTRUCT, $WIKIFORMCORE, $WIKILINKING);
53    
54  PluginConst:  PluginConst:
55      @NS_AA:
56        http://pc5.2ch.net/test/read.cgi/hp/1096723178/aavocab#
57    @NS_SW09:    @NS_SW09:
58      urn:x-suika-fam-cx:markup:suikawiki:0:9:      urn:x-suika-fam-cx:markup:suikawiki:0:9:
59      @NS_SW010:
60        urn:x-suika-fam-cx:markup:suikawiki:0:10:
61    @NS_HTML3:    @NS_HTML3:
62      urn:x-suika-fam-cx:markup:ietf:html:3:draft:00:      urn:x-suika-fam-cx:markup:ietf:html:3:draft:00:
63    @NS_XHTML1:    @NS_XHTML1:
64      http://www.w3.org/1999/xhtml      http://www.w3.org/1999/xhtml
65    @NS_XHTML2:    @NS_XHTML2:
66      http://www.w3.org/2002/06/xhtml2      http://www.w3.org/2002/06/xhtml2
67      @WIKIFORMCORE:
68        {($WIKIFORMCORE ||= SuikaWiki::Plugin->module_package ('WikiFormCore'))}
69      @WIKILINKING:
70        {($WIKILINKING ||= SuikaWiki::Plugin->module_package ('WikiLinking'))}
71      @WIKIRESOURCE:
72        {($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))}
73      @WIKISTRUCT:
74        {($WIKISTRUCT ||= SuikaWiki::Plugin->module_package ('WikiStruct'))}
75    
76    
77    
78  Format:  Format:
79    @ModuleName:    @ModuleName:
# Line 66  Format: Line 86  Format:
86    
87  Format:  Format:
88    @Name: SuikaWiki    @Name: SuikaWiki
89      @Version: 0.10
90      @Type:
91        @@@: text/x-suikawiki
92        @@version: 0.10
93      @ModuleName:
94        SuikaWiki::V0_10
95      @Inherit[list]:
96        SuikaWiki::V0_9
97      @Description:
98        @@@: SuikaWiki/0.10 document format (SuikaWiki/0.9 with minor additions)
99        @@lang: en
100    
101    Format:
102      @Name: SuikaWiki
103    @Version: 0.9    @Version: 0.9
104    @Type:    @Type:
105      @@@: text/x-suikawiki      @@@: text/x-suikawiki
# Line 80  Format: Line 114  Format:
114        
115    @Use:    @Use:
116      use Message::Markup::XML::QName qw/NS_xml_URI/;      use Message::Markup::XML::QName qw/NS_xml_URI/;
117        use Message::Util::Error;
118    
119    @Converter:    @Converter:
120      @@Type: text/html      @@Type: text/html
# Line 88  Format: Line 123  Format:
123        @@@@: Converting SuikaWiki/0.9 to Hypertext Markup Language fragment        @@@@: Converting SuikaWiki/0.9 to Hypertext Markup Language fragment
124        @@@lang:en        @@@lang:en
125      @@Main:      @@Main:
126  #      __FUNCPACK__->to_html ($source, %$opt);        $opt->{o}->{wiki} ||= $self->{wiki};
127          
128      ## Text format -> XML format      ## Text format -> XML format
129        my $xml = new Message::Markup::XML::Node type => '#fragment';        my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => $opt,
130        __FUNCPACK__->text_to_xml ($source, {%$opt, -parent => $xml});                                              wiki => $self->{wiki});
131    
132        ## SuikaWiki/0.9 -> XHTML 1
133          __FUNCPACK__->sw09_to_xhtml1 (source => $xml, parent => $opt->{-parent},
134                                        o => $opt->{o}, page => $opt->{page});
135    
136          if ($opt->{-with_annotation_input}) {
137            SuikaWiki::Plugin->module_package ('WikiFormCore')
138                             ->make_content_form_in_html
139                                 ($opt->{-parent},
140                                  $WIKIRESOURCE->get
141                                    (name => 'SuikaWiki/0.9:form:footannotate:input',
142                                     o => $opt->{o}, wiki => $opt->{o}->{wiki}),
143                                  option => $WIKIRESOURCE->get
144                                    (name => 'SuikaWiki/0.9:form:footannotate:option',
145                                     o => $opt->{o}, wiki => $opt->{o}->{wiki}),
146                                  o => $opt->{o},
147                                  wiki => $opt->{o}->{wiki},
148                                  output => {
149                                    page => $opt->{page},
150                                  });
151          }
152    
153    
154      @Converter:
155        @@Type:
156          @@@@: application/x-suikawiki+xml
157          @@@version: 0.9
158        @@Description:
159          @@@@: Converting SuikaWiki/0.9 text format to XML format
160          @@@lang: en
161        @@Main:
162          my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => $opt,
163                                                wiki => $self->{wiki});
164    ## TODO: Make a clone
165          $opt->{-parent}->append_node ($xml);
166    
167      @NextIndex:
168        @@Name: anchor
169        @@Main:
170          my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => \%opt,
171                                                wiki => $self->{wiki});
172          (__FUNCPACK__->get_last_anchor_index ($xml)) + 1;
173      
174      @WikiForm:
175        @@Main:
176          ## Text format -> XML format
177          my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => \%opt,
178                                                wiki => $self->{wiki});
179          local $opt{o}->{var}->{sw09__anchor_index};
180          local $opt{o}->{var}->{sw09__document_tree} = $xml;
181    
182          my $form;
183          if ($opt{o}->{form}->{output}->{id}) {
184            $form = __FUNCPACK__->get_element_by_id
185                      ($xml, $opt{o}->{form}->{output}->{id});
186            undef $form unless ref $form and
187                               $form->namespace_uri eq $NS_SW09 and
188                               $form->local_name eq 'form';
189          } else {
190            $form = __FUNCPACK__->get_nth_element
191                      ($xml, $NS_SW09 => 'form',
192                       $opt{o}->{form}->{output}->{index});
193          }
194          
195          my $ref;
196          if (ref $form) {
197            $ref = $form->get_attribute_value ('ref', default => 'form');
198          } else {
199            $ref = '#footannotate';
200          }
201          
202          
203          ## WikiForm Option
204          if ($ref eq 'form') {
205            $opt{option} ||= $form->get_attribute_value ('option');
206          } elsif ($ref eq 'comment') {
207            $opt{option} ||= $WIKIRESOURCE->get
208                               (name => 'SuikaWiki/0.9:form:comment:option',
209                                o => $opt{o}, wiki => $opt{o}->{wiki});
210          } elsif ($ref eq '#footannotate') {
211            $opt{option} ||= $WIKIRESOURCE->get
212                               (name => 'SuikaWiki/0.9:form:footannotate:option',
213                                o => $opt{o}, wiki => $opt{o}->{wiki});
214          } else {
215    ## TODO:
216          }
217          $WIKIFORMCORE->set_option ($opt{option} => $opt{o}) if $opt{option};
218    
219          my @missing;
220          for (keys %{$opt{o}->{form}->{require}->{id}}) {
221            unless (length $opt{o}->{wiki}->{input}->parameter
222                         ($WIKIFORMCORE->control_id ($opt{o}, local_id => $_,
223                                                     local_id_prefix => 'wikiform__')
224                                       ->{local_id})) {
225              push @missing, $_;
226            }
227          }
228          if (@missing) {
229            return [{
230              type => 'required_param_missing',
231              missing_id => \@missing,
232            }];
233          }
234                
235          ## Replace Output Template
236          my $result;
237          if ($ref eq 'form') {
238            $opt{template} ||= $form->get_attribute_value
239                                        ('template', default => '');
240          } elsif ($ref eq 'comment') {
241            $opt{template} ||= $WIKIRESOURCE->get
242                                 (name => 'SuikaWiki/0.9:form:comment:template',
243                                  o => $opt{o}, wiki => $opt{o}->{wiki});
244          } elsif ($ref eq '#footannotate') {
245            $opt{template} ||= $WIKIRESOURCE->get
246                                 (name => 'SuikaWiki/0.9:form:footannotate:template',
247                                  o => $opt{o}, wiki => $opt{o}->{wiki});
248          }
249          try {
250            $result = SuikaWiki::Plugin->text_formatter ('form_template')
251                             ->replace ($opt{template}, param => $opt{o});
252          } catch Message::Util::Formatter::error with {
253            my $err = shift;
254            SuikaWiki::Plugin->module_package ('Error')
255                             ->reporting_formatting_template_error
256                                 ($err, $err->{option}->{param}->{wiki});
257    ##TODO:
258            throw SuikaWiki::View::Implementation::error -type => 'ERROR_REPORTED';
259          };      
260    
261          ## Insert
262          if (length $result) {
263            if ($ref eq '#footannotate') {
264              my $parent;
265              for (@{$xml->child_nodes}) {
266                if ($_->node_type eq '#element' and
267                    $_->local_name eq 'document') {
268                  for (@{$_->child_nodes}) {
269                    if ($_->node_type eq '#element' and
270                        $_->local_name eq 'body') {
271                      $parent = $_;
272                      last;
273                    }
274                  }
275                }
276              }
277              CORE::die "Buggy implementation: no body element".$xml
278                        unless ref $parent;
279              
280              $parent->append_new_node (type => '#element',
281                                        namespace_uri => $NS_SW09,
282                                        local_name => 'text')
283                     ->append_text ($result);
284            } else {
285              my $parent = $form->parent_node;
286              CORE::die "Byggy implementation: No parent of form" unless ref $parent;
287              my $children = $parent->child_nodes;
288              
289              $result .= "\x0A" unless substr ($result, -1) eq "\x0A";
290              $parent->append_new_node (type => '#element',
291                                        namespace_uri => $NS_SW09,
292                                        local_name => 'text')
293                     ->append_text ($result);
294              my $node = pop @{$children};
295              my $form_str = overload::StrVal ($form);
296              my $i = 0;
297              for (@{$children}) {
298                last if overload::StrVal ($_) eq $form_str;
299                $i++;
300              }
301              if ($opt{o}->{form}->{output}->{reverse}) {
302                splice @{$children}, $i + 1, 0, $node;
303              } else {
304                splice @{$children}, $i, 0, $node;
305              }
306            }
307          } else {
308    ## TODO:
309          }
310    
311          ## XML format -> Text format
312          my $text = __FUNCPACK__->xml_to_text ($xml, {%opt});
313    
314          my %fragment = (fragment => $opt{o}->{form}->{output}->{id}
315                                || 'wikiform-'.$opt{o}->{form}->{output}->{index});
316          if (not $opt{o}->{form}->{output}->{reverse} and
317              $opt{o}->{var}->{sw09__anchor_index}) {
318            %fragment = (anchor_no => $opt{o}->{var}->{sw09__anchor_index});
319          }
320    
321          my $action = [
322            {
323              type => 'write',
324              content => $text,
325              update_lastmodified => time,
326            },
327            {
328              type => 'ok',
329              %fragment,
330            },
331          ];
332    
333      @HeadSummary:
334        @@Main:
335          my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => \%opt,
336                                                wiki => $self->{wiki});
337          return $xml->inner_text;
338    
339    FormattingRule:
340      @Category[list]:form-template
341      @Name: index
342      @Description:
343        @@@: Next anchor index number
344        @@lang:en
345      @After:
346        if ($o->{var}->{sw09__anchor_index}) {
347          ++$o->{var}->{sw09__anchor_index};
348        } else {
349          $o->{var}->{sw09__anchor_index}
350            = 1 + __FUNCPACK__->get_last_anchor_index
351                                  ($o->{var}->{sw09__document_tree});
352        }
353        $p->{-result} .= $o->{var}->{sw09__anchor_index};
354    
355    Function:
356      @Name: get_last_anchor_index
357      @Main:
358          my (undef, $xml) = @_;
359          my $anchor = 0;
360          my $get_anchor_no;
361          $get_anchor_no = sub {
362            my $node = shift;
363            for my $child (@{$node->child_nodes}) {
364              my $nt = $child->node_type;
365              if ($nt eq '#element') {
366                if ($child->namespace_uri => $NS_SW09 and
367                    $child->local_name eq 'anchor-end') {
368                  my $a = $child->get_attribute_value ('anchor', default => 0,
369                                                       namespace_uri => $NS_SW09);
370                  $anchor = 0+$a if $anchor < 0+$a;
371                } else {
372                  $get_anchor_no->($child);
373                }
374              } elsif ($nt eq '#document' or $nt eq '#fragment') {
375                $get_anchor_no->($child);
376              }
377            }
378          };
379          $get_anchor_no->($xml);
380          $anchor;
381    
382    
383    Function:
384      @Name: get_xml_tree
385      @Main:
386        my (undef, %opt) = @_;
387        if ($opt{opt}->{page}) {
388          
389      ## TODO:
390          unless ($__FUNCPACK__::DBLoaded) {
391            $opt{wiki}->{db}->_set_prop_db (sw09__xml_tree => {-db_open => sub {
392              require SuikaWiki::DB::Hash;
393              new SuikaWiki::DB::Hash;
394            }});
395            $__FUNCPACK__::DBLoaded++;
396          }
397        
398          my $xml = new Message::Markup::XML::Node type => '#fragment';
399          __FUNCPACK__->text_to_xml (${$opt{text}}, {%{$opt{opt}}, -parent => $xml});
400    
401          $opt{wiki}->{db}->set (sw09__xml_tree => $opt{opt}->{page} => $xml);
402          $xml;
403        } else {
404          my $xml = new Message::Markup::XML::Node type => '#fragment';
405          __FUNCPACK__->text_to_xml (${$opt{text}}, {%{$opt{opt}}, -parent => $xml});
406          $xml;
407        }
408    
409    Function:
410      @Name: sw09_to_xhtml1
411      @Description:
412        @@lang:en
413        @@@: Transform a SuikaWiki/0.9 or SuikaWiki/0.10 XML tree to an XHTML tree.
414      @Main:
415        my (undef, %opt) = @_;
416    
417        my ($apply_template, $apply_template_children);        my ($apply_template, $apply_template_children);
418        $apply_template_children = sub {        $apply_template_children = sub {
419          my ($parent, $result) = @_;          for (@{$_[0]->child_nodes}) {
420          for (@{$parent->child_nodes}) {            $apply_template->($_ => $_[1]) unless $_->node_type eq '#attribute';
           $apply_template->($_ => $result) unless $_->node_type eq '#attribute';  
421          }          }
422        };        };
423        $apply_template = sub {        $apply_template = sub {
# Line 105  Format: Line 425  Format:
425          my $ln = $source->local_name;          my $ln = $source->local_name;
426          if ($source->node_type eq '#text') {          if ($source->node_type eq '#text') {
427            $result->append_text ($source->inner_text);            $result->append_text ($source->inner_text);
428          } elsif ({qw/code 1 samp 1 var 1 dfn 1 kbd 1 sub 1 sup 1/}->{$ln}) {          } elsif ({qw/code 1 samp 1 var 1 dfn 1 kbd 1 sub 1 sup 1
429                         cite 1/   ## SuikaWiki/0.10
430                     }->{$ln}) {
431            my $node = $result->append_new_node            my $node = $result->append_new_node
432                                  (type => '#element',                                  (type => '#element',
433                                   namespace_uri => $NS_XHTML1,                                   namespace_uri => $NS_XHTML1,
# Line 113  Format: Line 435  Format:
435            my $class = $source->get_attribute_value ('class', default => '');            my $class = $source->get_attribute_value ('class', default => '');
436            $node->set_attribute (class => $class) if $class;            $node->set_attribute (class => $class) if $class;
437            $apply_template_children->($source => $node);            $apply_template_children->($source => $node);
438          } elsif ({qw/ins 1 del 1/}->{$ln}) {          } elsif ({qw/ins 1 del 1 insert 1 delete 1/}->{$ln}) {
439            my $node = $result->append_new_node            my $node = $result->append_new_node
440                                  (type => '#element',                                  (type => '#element',
441                                   namespace_uri => $NS_XHTML1,                                   namespace_uri => $NS_XHTML1,
442                                   local_name => $ln);                                   local_name => {qw/ins ins insert ins
443                                                       delete del del del/}->{$ln});
444            my $class = $source->get_attribute_value ('class', default => '');            my $class = $source->get_attribute_value ('class', default => '');
445            $node->set_attribute (class => $class) if $class;            $node->set_attribute (class => $class) if $class;
446            ## TODO: cite            ## TODO: cite
# Line 134  Format: Line 457  Format:
457            } elsif ($ln eq 'pre') {            } elsif ($ln eq 'pre') {
458              $node->set_attribute (space => 'preserve',              $node->set_attribute (space => 'preserve',
459                                    namespace_uri => NS_xml_URI);                                    namespace_uri => NS_xml_URI);
460                my $class = $source->get_attribute_value ('class', default => '');
461                $node->set_attribute (class => $class) if length $class;
462            }            }
463            $apply_template_children->($source => $node);            $apply_template_children->($source => $node);
464          } elsif ($ln eq 'anchor') {          } elsif ($ln eq 'anchor') {
465            local $opt->{o}->{var}->{sw09__anchor_content} = sub {            local $opt{o}->{var}->{sw09__anchor_content} = sub {
466              $apply_template_children->($source => shift);              $apply_template_children->($source => shift);
467            };            };
468            SuikaWiki::Plugin->module_package ('WikiLinking')            SuikaWiki::Plugin->module_package ('WikiLinking')
469                             ->to_wikipage_in_html ({                             ->to_wikipage_in_html ({
470              label       => SuikaWiki::Plugin->resource              label => $WIKIRESOURCE->get_text
471                               ('Link:SuikaWiki/0.9:toWikiPage:SourceLabel'),                                   (name =>
472                                        'Link:SuikaWiki/0.9:toWikiPage:SourceLabel',
473                                      param => $opt{o},
474                                      wiki => $opt{o}->{wiki}),
475            } => {            } => {
476      ## TODO:              base                => $opt{o}->{wiki}->{var}->{page},
477              page_name_relative  => [split m#//#, $source->inner_text],              page_name   => $opt{o}->{wiki}->name ($source->inner_text)
478              page_anchor_no      => $source->get_attribute_value ('anchor'),                                            ->absolute (wiki => $opt{o}->{wiki},
479                                                     nearest => 'content',
480                                                     base => $opt{o}->{wiki}
481                                                                    ->{var}->{page}),
482                page_anchor_no      => $source->get_attribute_value
483                                         ('anchor',
484                                          namespace_uri => $NS_SW09),
485            }, {            }, {
486              o => $opt->{o},              o => $opt{o},
487              parent => $result,              parent => $result,
488            });            });
489          } elsif ($ln eq 'p') {          } elsif ($ln eq 'p') {
# Line 159  Format: Line 493  Format:
493                                                     local_name => 'p'));                                                     local_name => 'p'));
494          } elsif ($ln eq 'h') {          } elsif ($ln eq 'h') {
495            my $node;            my $node;
496            if ($opt->{o}->{var}->{ws__section_depth} > 6) {            if ($opt{o}->{var}->{ws__section_depth} > 6) {
497              $node = $result->append_new_node              $node = $result->append_new_node
498                                  (type => '#element',                                  (type => '#element',
499                                   namespace_uri => $NS_XHTML1,                                   namespace_uri => $NS_XHTML1,
500                                   local_name => 'div');                                   local_name => 'div');
501              $node->set_attribute (class => 'heading h'.$opt->{o}->{var}              $node->set_attribute (class => 'heading h'.$opt{o}->{var}
502                                                     ->{ws__section_depth});                                                     ->{ws__section_depth});
503            } else {            } else {
504              $node = $result->append_new_node              $node = $result->append_new_node
505                                  (type => '#element',                                  (type => '#element',
506                                   namespace_uri => $NS_XHTML1,                                   namespace_uri => $NS_XHTML1,
507                                   local_name => 'h'.$opt->{o}->{var}                                   local_name => 'h'.$opt{o}->{var}
508                                                         ->{ws__section_depth});                                                         ->{ws__section_depth});
509            }            }
510            $apply_template_children->($source => $node);            $apply_template_children->($source => $node);
511              $WIKISTRUCT->set_section_id ($result, undef, $opt{o}->{wiki},
512                                                 title => $source->inner_text);
513          } elsif ($ln eq 'ruby' or $ln eq 'rubyb') {          } elsif ($ln eq 'ruby' or $ln eq 'rubyb') {
514            my @child;            my @child;
515            for (@{$source->child_nodes}) {            for (@{$source->child_nodes}) {
# Line 238  Format: Line 574  Format:
574                                   local_name => 'abbr');                                   local_name => 'abbr');
575            $node->set_attribute (title => $b[1]->inner_text) if $b[1];            $node->set_attribute (title => $b[1]->inner_text) if $b[1];
576            $apply_template_children->($b[0] => $node);            $apply_template_children->($b[0] => $node);
577            } elsif ($ln eq 'qn') {
578              my (@b);
579              for (@{$source->child_nodes}) {
580                push @b, $_ if {qw/qname 1 nsuri 1/}->{$_->local_name};
581              }
582              my $node = $result->append_new_node
583                                    (type => '#element',
584                                     namespace_uri => $NS_XHTML1,
585                                     local_name => 'code');
586              $node->set_attribute (class => 'qname');
587              $node->set_attribute (title => '{<'.$b[1]->inner_text.'>}') if $b[1];
588              $apply_template_children->($b[0] => $node);
589          } elsif ($ln eq 'q') {          } elsif ($ln eq 'q') {
590            my $node = $result->append_new_node            my $node = $result->append_new_node
591                                  (type => '#element',                                  (type => '#element',
# Line 245  Format: Line 593  Format:
593                                   local_name => 'q');                                   local_name => 'q');
594            ## TODO: cite            ## TODO: cite
595            $apply_template_children->($source => $node);            $apply_template_children->($source => $node);
596          } elsif ($ln eq 'weak') {          } elsif ($ln eq 'weak' or
597                     $ln eq 'aa'        ## SuikaWiki/0.10
598                    ) {
599            my $node = $result->append_new_node            my $node = $result->append_new_node
600                                  (type => '#element',                                  (type => '#element',
601                                   namespace_uri => $NS_XHTML1,                                   namespace_uri => $NS_XHTML1,
602                                   local_name => 'span');                                   local_name => 'span');
603            $node->set_attribute (class => 'weak');            my @class = split /\s+/,
604                             $source->get_attribute_value ('class', default => '');
605              $node->set_attribute (class => join ' ', $ln, @class);
606              $apply_template_children->($source => $node);
607            } elsif ($ln eq 'src' or $ln eq 'csection') { ## SuikaWiki/0.10
608              my $node = $result->append_new_node
609                                    (type => '#element',
610                                     namespace_uri => $NS_XHTML1,
611                                     local_name => 'cite');
612              my @class = split /\s+/,
613                             $source->get_attribute_value ('class', default => '');
614              $node->set_attribute (class => join ' ', $ln, @class);
615              $node->append_text ("[");
616              $apply_template_children->($source => $node);
617              $node->append_text ("]");
618            } elsif ($ln eq 'key') { ## SuikaWiki/0.10
619              my $node = $result->append_new_node
620                                    (type => '#element',
621                                     namespace_uri => $NS_XHTML1,
622                                     local_name => 'kbd');
623              my @class = split /\s+/,
624                             $source->get_attribute_value ('class', default => '');
625              $node->set_attribute (class => join ' ', $ln, @class);
626            $apply_template_children->($source => $node);            $apply_template_children->($source => $node);
627          } elsif ({qw/section 1 bodytext 1/}->{$ln}) {          } elsif ({qw/section 1 bodytext 1/}->{$ln}) {
628            my $node = $result->append_new_node            my $node = $result->append_new_node
# Line 258  Format: Line 630  Format:
630                                   namespace_uri => $NS_XHTML1,                                   namespace_uri => $NS_XHTML1,
631                                   local_name => 'div');                                   local_name => 'div');
632            $node->set_attribute (class => $ln);            $node->set_attribute (class => $ln);
633            local $opt->{o}->{var}->{ws__section_depth}            local $opt{o}->{var}->{ws__section_depth}
634                = $opt->{o}->{var}->{ws__section_depth} + 1;                = $opt{o}->{var}->{ws__section_depth} + 1;
635            $apply_template_children->($source => $node);            $apply_template_children->($source => $node);
636          } elsif ($ln eq 'anchor-end') {          } elsif ($ln eq 'anchor-end') {
637            my $node = $result->append_new_node            my $node = $result->append_new_node
# Line 267  Format: Line 639  Format:
639                                   namespace_uri => $NS_XHTML1,                                   namespace_uri => $NS_XHTML1,
640                                   local_name => 'a');                                   local_name => 'a');
641            $node->set_attribute (id => 'anchor-'.$source->get_attribute_value            $node->set_attribute (id => 'anchor-'.$source->get_attribute_value
642                                                    ('anchor', default => '0'));                                                    ('anchor', default => '0',
643                                                       namespace_uri => $NS_SW09));
644              $node->set_attribute (name => 'anchor-'.$source->get_attribute_value
645                                                      ('anchor', default => '0',
646                                                       namespace_uri => $NS_SW09))
647                if $opt{o}->{wiki}->{var}->{client}->{downgrade}->{html_no_id};
648              $node->set_attribute (class => 'anchor');
649            $node->append_text ($source->inner_text);            $node->append_text ($source->inner_text);
650          } elsif ($ln eq 'anchor-internal') {          } elsif ($ln eq 'anchor-internal') {
651            my $node = $result->append_new_node            my $node = $result->append_new_node
# Line 275  Format: Line 653  Format:
653                                   namespace_uri => $NS_XHTML1,                                   namespace_uri => $NS_XHTML1,
654                                   local_name => 'a');                                   local_name => 'a');
655            $node->set_attribute (href => '#anchor-'.$source->get_attribute_value            $node->set_attribute (href => '#anchor-'.$source->get_attribute_value
656                                                       ('anchor', default => '0'));                                                       ('anchor',
657                                       namespace_uri => $NS_SW09, default => '0'));
658            $node->set_attribute (class => 'wiki-anchor');            $node->set_attribute (class => 'wiki-anchor');
659            $node->append_text ($source->inner_text);            $node->append_text ($source->inner_text);
660            } elsif ($ln eq 'anchor-external') {
661              local $opt{o}->{var}->{sw09__anchor_content} = sub {
662                $apply_template_children->($source => shift);
663              };
664              $WIKILINKING
665                    ->to_resource_in_html (
666                        {
667                         label => $WIKIRESOURCE
668                                    ->get_text (name =>
669                                       'Link:SuikaWiki/0.9:toResource:SourceLabel',
670                                       param => $opt{o},
671                                       wiki => $opt{o}->{wiki}),
672                        }, {
673                          resource_scheme =>
674                            $source->get_attribute_value ('resScheme',
675                                                          namespace_uri => $NS_SW09,
676                                                          default => 'URI'),
677                          resource_parameter =>
678                            $source->get_attribute_value ('resParameter',
679                                                          namespace_uri => $NS_SW09,
680                                                          default => ''),
681                        }, {
682                         o => $opt{o},
683                         parent => $result,
684                        });
685            } elsif ($ln eq 'form') {
686              my $ref = $source->get_attribute_value ('ref', default => 'form');
687              if ($ref eq 'form') {
688                $WIKIFORMCORE->make_content_form_in_html
689                                     ($result,
690                                      $source->get_attribute_value
691                                                        ('input', default => ''),
692                                      option => $source->get_attribute_value
693                                                           ('option'),
694                                      name => $source->get_attribute_value ('id'),
695                                      o => $opt{o},
696                                      wiki => $opt{o}->{wiki},
697                                      output => {
698                                        page => $opt{page},
699                                      });
700              } elsif ($ref eq 'comment') {
701                $WIKIFORMCORE->make_content_form_in_html
702                                     ($result,
703                                      $WIKIRESOURCE->get
704                                        (name => 'SuikaWiki/0.9:form:comment:input',
705                                         o => $opt{o}, wiki => $opt{o}->{wiki}),
706                                      option => $WIKIRESOURCE->get
707                                        (name => 'SuikaWiki/0.9:form:comment:option',
708                                         o => $opt{o}, wiki => $opt{o}->{wiki}),
709                                      name => $source->get_attribute_value ('id'),
710                                      o => $opt{o},
711                                      wiki => $opt{o}->{wiki},
712                                      output => {
713                                        page => $opt{page},
714                                      });
715              } else {
716     ## TODO: Warning
717                $WIKIFORMCORE->make_content_form_in_html
718                                     ($result,
719                                      '',
720                                      option => '',
721                                      o => $opt{o},
722                                      wiki => $opt{o}->{wiki},
723                                      output => {
724                                        page => $opt{page},
725                                      });
726              }
727          } elsif ($ln eq 'dr') {          } elsif ($ln eq 'dr') {
728            $apply_template_children->($source => $result);            $apply_template_children->($source => $result);
729          } elsif ($ln eq 'document') {          } elsif ($ln eq 'document') {
# Line 290  Format: Line 736  Format:
736                                                     namespace_uri => $NS_XHTML1,                                                     namespace_uri => $NS_XHTML1,
737                                                     local_name => 'div');                                                     local_name => 'div');
738            $body_block->set_attribute (class => 'block SuikaWiki-0-9');            $body_block->set_attribute (class => 'block SuikaWiki-0-9');
           local $opt->{o}->{var}->{ws__section_depth}  
               = $opt->{o}->{var}->{ws__section_depth} + 1;  
739            $apply_template_children->($body => $body_block);            $apply_template_children->($body => $body_block);
740          } else {          } else {
741            my $node = $result->append_new_node            my $node = $result->append_new_node
# Line 314  Format: Line 758  Format:
758          }          }
759        };        };
760                
761        $apply_template_children->($xml => $opt->{-parent});        $apply_template_children->($opt{source} => $opt{parent});
762    
763    
764    @Converter:  Function:
765      @@Type:    @Name: xml_to_text
766        @@@@: application/x-suikawiki+xml    @Main:
767        @@@version: 0.9      my (undef, $src, $opt) = @_;
768      @@Description:  
769        @@@@: Converting SuikaWiki/0.9 text format to XML format  
770        @@@lang: en      my %is_block = (
771      @@Main:        qw/p 1 blockquote 1 pre 1 ul 1 ol 1 dl 1 section 1 h 1
772        __FUNCPACK__->text_to_xml ($source, $opt);           bodytext 1 document 1 head 1 body 1 table 1 text 1 form 1
773             insert 1 delete 1/
774        );
775    
776            my %x2t;
777            %x2t = (
778              anchor => sub {
779                my $source = shift;
780                my $result = '[['
781                          .  $x2t{'#inline'}->($source, no_newline => 1)
782                          .  ']';
783                my $anchor = $source->get_attribute_value
784                                      ('anchor',
785                                       namespace_uri => $NS_SW09,
786                                       default => '');
787                if (length $anchor) {
788                  $result .= '>>'.(0+$anchor);
789                } else {
790                  $anchor = $source->get_attribute_value
791                                      ('resScheme',
792                                       namespace_uri => $NS_SW09);
793                  if ($anchor) {
794                    my $param = $source->get_attribute_value
795                                      ('resParameter',
796                                       namespace_uri => $NS_SW09);
797                    if ($anchor eq 'URI' and $param =~ /^[0-9A-Za-z_+.%-]+:/) {
798                      $result .= '<' . $param . '>';
799                    } else {
800                      $result .= '<' . $anchor . ':' . $param . '>';
801                    }
802                  }
803                }
804                $result . ']';
805              },
806              li => sub {
807                my $source = shift;
808                my $result = ({qw/ul - ol =/}->{$opt->{o}->{var}->{sw09__list_type}}
809                              x $opt->{o}->{var}->{sw09__list_depth})
810                          .  ' ' . $x2t{'#flow'}->($source);
811                $result;
812              },
813              dt => sub {
814                ':' . $x2t{'#inline'}->(return, no_newline => 1) . ':';
815              },
816              h => sub {
817                  ("*" x ($opt->{o}->{var}->{ws__section_depth} - 1))
818                .  " "
819                .  $x2t{'#inline'}->(shift, no_newline => 1);
820              },
821              'anchor-end' => sub {
822                return shift->inner_text;
823              },
824              'anchor-internal' => sub {
825                return shift->inner_text;
826              },
827              'anchor-external' => sub {
828                return '<'.shift->inner_text.'>';
829              },
830              form => sub {
831                my $source = shift;
832                my $ref = $source->get_attribute_value ('ref', default => 'form');
833                my $result = '[[#'.$ref;
834                my $name = $source->get_attribute_value ('id');
835                $name =~ s/([()\\])/\\$1/g;
836                $result .= '(' . $name . ')' if $name;
837                ## General WikiForm
838                if ($ref eq 'form') {
839                  $result .= ":'";
840                  my $input = $source->get_attribute_value ('input', default => '');
841                  $input =~ s/(['\\])/\\$1/g;
842                  $result .= $input . "':'";
843                  my $template = $source->get_attribute_value ('template', default => '');
844                  $template =~ s/(['\\])/\\$1/g;
845                  $result .= $template . "'";
846                  my $option = $source->get_attribute_value ('option');
847                  if ($option) {
848                    $option =~ s/(['\\])/\\$1/g;
849                    $result .= ":'" . $option . "'";
850                  }
851                ## Specific WikiForm
852                } else {
853                  my $param = $source->get_attribute_value ('parameter');
854                  if ($param) {
855                    $result .= ':' . $param;
856                  }
857                }
858                $result .= ']]';
859              },
860              pre => sub {
861                my $source = shift;
862                my $result = '[PRE';
863                my $class = $source->get_attribute_value ('class');
864                if ($class) {
865                  $class =~ s/([\\()])/\\$1/g;
866                  $result .= '(' . $class . ')';
867                }
868                $result .= "[\x0A"
869                        .  $x2t{'#inline'}->($source);
870                $result .= "\x0A" unless substr ($result, -1) eq "\x0A";
871                $result .= "]PRE]\x0A";
872              },
873              insert => sub {
874                my $source = shift;
875                my $result = '[INS';
876                my $class = $source->get_attribute_value ('class');
877                if ($class) {
878                  $class =~ s/([\\()])/\\$1/g;
879                  $result .= '(' . $class . ')';
880                }
881                local $opt->{o}->{var}->{sw09__list_depth} = 0;
882                $result .= "[\x0A"
883                        .  $x2t{'#block'}->($source);
884                $result .= "\x0A" unless substr ($result, -1) eq "\x0A";
885                $result .= "]INS]\x0A";
886              },
887              delete => sub {
888                my $source = shift;
889                my $result = '[DEL';
890                my $class = $source->get_attribute_value ('class');
891                if ($class) {
892                  $class =~ s/([\\()])/\\$1/g;
893                  $result .= '(' . $class . ')';
894                }
895                local $opt->{o}->{var}->{sw09__list_depth} = 0;
896                $result .= "[\x0A"
897                        .  $x2t{'#block'}->($source);
898                $result .= "\x0A" unless substr ($result, -1) eq "\x0A";
899                $result .= "]DEL]\x0A";
900              },
901              document => sub {
902                my $source = shift;
903                my $result = '';
904                #$result = '#?'
905                #           . $source->get_attribute_value
906                #                        ('Name', namespace_uri => $NS_SW09,
907                #                         default => 'SuikaWiki')
908                #           . '/'
909                #           . $source->get_attribute_value
910                #                        ('Version', namespace_uri => $NS_SW09,
911                #                         default => '0.9');
912                for (@{$source->child_nodes}) {
913                  $result .= ($x2t{$_->local_name} or $x2t{'#undef'})->($_)
914                    if $_->node_type eq '#element';
915                }
916                $result;
917              },
918              head => sub {
919                my $source = shift;
920                my $result = '';
921                ## ISSUE: '#?SuikaWiki/0.9 ' required...
922                for (@{$source->child_nodes}) {
923                  if ($_->node_type eq '#element' and
924                      $_->local_name eq 'parameter') {
925                    $result .= ' '.$x2t{parameter}->($_);
926                  }
927                }
928                $result . "\x0A";
929              },
930              parameter => sub {
931                my $source = shift;
932                my $result = $source->get_attribute_value ('name', default => '')
933                          .  '="';
934                my @v;
935                for (@{$source->child_nodes}) {
936                  push @v, $x2t{value}->($_) if $_->node_type eq '#element' and
937                                                $_->local_name eq 'value';
938                }
939                $result .= join ',', @v;
940                $result .  '"';
941              },
942              value => sub {
943                my $value = $x2t{'#inline'}->(shift, no_newline => 1);
944                $value =~ s/(["\\])/\\$1/g;
945                $value =~ tr/\x0A\x0D/ /;
946                $value;
947              },
948              section => sub {
949                local $opt->{o}->{var}->{ws__section_depth}
950                    = $opt->{o}->{var}->{ws__section_depth} + 1;
951                $x2t{'#block'}->(shift);
952              },
953              body => sub {
954                local $opt->{o}->{var}->{ws__section_depth} = 1;
955                $x2t{'#block'}->(shift);
956              },
957              text => sub {
958                my ($source, %opt) = @_;
959                my $result .= '';
960                for (@{$source->child_nodes}) {
961                  if ($_->node_type eq '#text') {
962                    $result .= $_->inner_text;
963                  } elsif ($_->node_type eq '#element') {
964                    $result .= ($x2t{$_->local_name} or $x2t{'#undef'})->($_);
965                  }
966                }
967                $result;
968              },
969              dr => sub {
970                my $result = $x2t{'#list'}->(shift);
971                if ($result) {
972                  $result . "\x0A";
973                } else {
974                  "::\x0A";
975                }
976              },
977              dt => sub {
978                ':' . $x2t{'#inline'}->(shift, no_newline => 1) . ':';
979              },
980              dd => sub {
981                $x2t{'#inline'}->(shift);
982              },
983              tr => sub {
984                my $result = $x2t{'#list'}->(shift);
985                if ($result) {
986                  substr ($result, 1) . "\x0A";
987                } else {
988                 "',\x0A";
989                }
990              },
991              td => sub {
992                my $source = shift;
993                my $result = $x2t{'#inline'}->($source, no_newline => 1);
994                if ($result =~ /[,"\\]/ or $result =~ /==/) {
995                  $result =~ s/(["\\])/\\$1/g;
996                  $result = '"' . $result . '"';
997                }
998                my $colspan = $source->get_attribute_value ('colspan', default => 1);
999                $result .= ("\t,==" x ($colspan - 1)) if $colspan > 1;
1000                "\t," . $result;
1001              },
1002              em => sub {
1003                "''" . $x2t{'#inline'}->($_, no_newline => 1) . "''";
1004              },
1005              strong => => sub {
1006                "'''" . $x2t{'#inline'}->($_, no_newline => 1) . "'''";
1007              },
1008              rb => sub {
1009                $x2t{'#inline'}->(shift, no_newline => 1);
1010              },
1011              qname => sub {
1012                $x2t{'#inline'}->(shift, no_newline => 1);
1013              },
1014              rt => sub {
1015                '] [' . $x2t{'#inline'}->(shift, no_newline => 1);
1016              },
1017              nsuri => sub {
1018                '] [' . $x2t{'#inline'}->(shift, no_newline => 1);
1019              },
1020              replace => sub {
1021                '__&&' . shift->get_attribute_value ('by', default => '') . '&&__';
1022              },
1023              bodytext => sub {
1024                my ($source, %opt) = @_;
1025                local $opt->{o}->{var}->{sw09__bq_depth}
1026                    = $opt->{o}->{var}->{sw09__bq_depth} + 1;
1027                my @result;
1028                for (@{$source->child_nodes}) {
1029                  if ($_->node_type eq '#element') {
1030                    my $ln = $_->local_name;
1031                    push @result, [($x2t{$ln} or $x2t{'#undef'})->($_),
1032                                   $ln];
1033                  }
1034                }
1035                my $result = '';
1036                my $prev = '';
1037                for (@result) {
1038                  my $s = $_->[0];
1039                  if ($_->[1] eq 'p') {
1040                    $result .= "\x0A" if length $result and
1041                                         substr ($result, -1) ne "\x0A";
1042                    $result .= ('>' x $opt->{o}->{var}->{sw09__bq_depth}) . ' ';
1043                  } elsif ($_->[1] eq 'form' or $_->[1] eq 'replace') {
1044                    $result .= "\x0A" if length $result and
1045                                         substr ($result, -1) ne "\x0A";
1046                    $result .= ('>' x $opt->{o}->{var}->{sw09__bq_depth})."\x0A";
1047                  } elsif ($_->[1] eq 'blockquote' or $_->[1] eq 'text') {
1048                    $result .= "\x0A" if length $result and
1049                                         substr ($result, -1) ne "\x0A";
1050                  } else {
1051                    unless ($prev eq 'text') {
1052                      $result .= "\x0A" if length $result and
1053                                           substr ($result, -1) ne "\x0A";
1054                    }
1055                    $result .= ('>' x $opt->{o}->{var}->{sw09__bq_depth})."\x0A";
1056                  }
1057                  $result .= $s;
1058                  $prev = $_->[1];
1059                }
1060                $result;
1061              },
1062              ## Note: This element will be interpreted as a paragraph
1063              ##       unless format is SuikaWikiImage/0.9.
1064              image => sub {
1065                my ($source, %opt) = @_;
1066                return "\x0A__IMAGE__\x0A" . $source->inner_text . "\x0A";
1067              },
1068              '#block' => sub {
1069                my ($source, %opt) = @_;
1070                my @result;
1071                for (@{$source->child_nodes}) {
1072                  if ($_->node_type eq '#element') {
1073                    my $ln = $_->local_name;
1074                    push @result, [($x2t{$ln} or $x2t{'#undef'})->($_),
1075                                   $ln];
1076                  }
1077                }
1078                my $result = '';
1079                my $prev = '';
1080                for (@result) {
1081                  my $s = $_->[0];
1082                  if ($_->[1] eq 'form') {
1083                    $result .= "\x0A" if length $result and
1084                                         substr ($result, -1) ne "\x0A";
1085                    $result .= "\x0A";
1086                  } elsif ($_->[1] eq 'replace') {
1087                    $result .= "\x0A" if length $result and
1088                                         substr ($result, -1) ne "\x0A";
1089                  } elsif ($_->[1] eq 'text') {
1090                    $result .= "\x0A" if length $result and
1091                                         substr ($result, -1) ne "\x0A";
1092                    $result .= "\x0A" if $prev eq 'p';
1093                  } else {
1094                    if ($prev ne 'text' and $prev ne 'replace') {
1095                      $result .= "\x0A" if length $result and
1096                                           substr ($result, -1) ne "\x0A";
1097                      $result .= "\x0A";
1098                    }
1099                  }
1100                  $result .= $s;
1101                  $prev = $_->[1];
1102                }
1103                $result;
1104              },
1105              '#flow' => sub {
1106                my ($source, %opt) = @_;
1107                my @result;
1108                for (@{$source->child_nodes}) {
1109                  if ($_->node_type eq '#element') {
1110                    my $ln = $_->local_name;
1111                    if ($is_block{$ln}) {
1112                      push @result, [($x2t{$ln} or $x2t{'#undef'})->($_),
1113                                     $ln];
1114                    } else {
1115                      if (@result and ($result[$#result]->[1] eq '#inline')) {
1116                        $result[$#result]->[0]
1117                          .= ($x2t{$ln} or $x2t{'#undef'})->($_);
1118                      } else {
1119                        push @result, [($x2t{$ln} or $x2t{'#undef'})->($_),
1120                                       '#inline'];
1121                      }
1122                    }
1123                  } elsif ($_->node_type eq '#text') {
1124                    if (@result and ($result[$#result]->[1] eq '#inline')) {
1125                      $result[$#result]->[0] .= $_->inner_text;
1126                    } else {
1127                      push @result, [$_->inner_text, '#inline'];
1128                    }
1129                  }
1130                }
1131                my $result = '';
1132                my $prev = '';
1133                for (@result) {
1134                  my $s = $_->[0];
1135                  if ($_->[1] eq '#inline') {
1136                    if ($prev ne 'text' and $prev ne 'form' and $prev ne 'replace') {
1137                      $result .= "\x0A" if length $result and
1138                                           substr ($result, -1) ne "\x0A";
1139                    }
1140                    $s =~ s/\x0D\x0A/\x0A/g;
1141                    $s =~ s/\x0D/\x0A/g;
1142                    $s =~ s/\x0A\x0A+/\x0A/g;
1143                    $s =~ s/\x0A/\x20/g if $opt{no_newline};
1144                  } elsif ($_->[1] eq 'form' or $_->[1] eq 'replace') {
1145                    if ($prev ne '#inline') {
1146                      $result .= "\x0A" if length $result and
1147                                           substr ($result, -1) ne "\x0A";
1148                    }
1149                  } elsif ($_->[1] eq 'text') {
1150                    $result .= "\x0A" if length $result and
1151                                         substr ($result, -1) ne "\x0A";
1152                  } else {
1153                    unless ($prev eq 'text') {
1154                      $result .= "\x0A" if length $result and
1155                                           substr ($result, -1) ne "\x0A";
1156                    }
1157                  }
1158                  $result .= $s;
1159                  $prev = $_->[1];
1160                }
1161                $result;
1162              },
1163              '#inline' => sub {
1164                my ($source, %opt) = @_;
1165                my $result .= '';
1166                for (@{$source->child_nodes}) {
1167                  if ($_->node_type eq '#text') {
1168                    $result .= $_->inner_text;
1169                  } elsif ($_->node_type eq '#element') {
1170                    $result .= ($x2t{$_->local_name} or $x2t{'#undef'})->($_);
1171                  }
1172                }
1173                $result =~ s/\x0D\x0A/\x0A/g;
1174                $result =~ s/\x0D/\x0A/g;
1175                $result =~ s/\x0A\x0A+/\x0A/g;
1176                $result =~ s/\x0A/\x20/g if $opt{no_newline};
1177                $result;
1178              },
1179              '#list' => sub {
1180                my ($source, %opt) = @_;
1181                my $result .= '';
1182                for (@{$source->child_nodes}) {
1183                  if ($_->node_type eq '#element') {
1184                    $result .= ($x2t{$_->local_name} or $x2t{'#undef'})->($_);
1185                  }
1186                }
1187                $result;
1188              },
1189              '#undef' => sub {
1190                my $source = shift;
1191                ## TODO:
1192                "<".$source->namespace_uri.">:".$source->local_name
1193                      .  $x2t{'#inline'}->($source);
1194              },
1195            );
1196            for (qw/blockquote dl tbody table/) {
1197              $x2t{$_} = sub { $x2t{'#list'}->(shift) };
1198            }
1199            for (qw/p dd/) {
1200              $x2t{$_} = sub { $x2t{'#flow'}->(shift) };
1201            }
1202            for my $type (qw/ul ol/) {
1203              $x2t{$type} = sub {
1204                my $source = shift;
1205                local $opt->{o}->{var}->{sw09__list_type} = $type;
1206                local $opt->{o}->{var}->{sw09__list_depth}
1207                    = $opt->{o}->{var}->{sw09__list_depth} + 1;
1208                my @result;
1209                for (@{$source->child_nodes}) {
1210                  push @result, $x2t{$_->local_name}->($_)
1211                    if $_->node_type eq '#element';
1212                }
1213                my $result = '';
1214                for (@result) {
1215                  $result .= "\x0A" unless substr ($result, -1) eq "\x0A";
1216                  $result .= $_;
1217                }
1218                substr ($result, 1);
1219              };
1220            }
1221            for my $type (qw/code samp var dfn kbd sub sup weak q ruby rubyb
1222                             abbr ins del aa src cite key qn csection/) {
1223              $x2t{$type} = sub {
1224                my $source = shift;
1225                my $result = '['.uc $type;
1226                my $class = $source->get_attribute_value ('class', default => '');
1227                if ($class) {
1228                  $class =~ s/([()\\])/\\$1/g;
1229                  $result .= '(' . $class . ')';
1230                }
1231                $result .= '['
1232                        .  $x2t{'#inline'}->($source, no_newline => 1)
1233                        .  ']';
1234                my $anchor = $source->get_attribute_value
1235                                      ('anchor',
1236                                       namespace_uri => $NS_SW09,
1237                                       default => '');
1238                if (length $anchor) {
1239                  $result .= '>>'.(0+$anchor);
1240                } else {
1241                  $anchor = $source->get_attribute_value
1242                                      ('resScheme',
1243                                       namespace_uri => $NS_SW09);
1244                  if ($anchor) {
1245                    my $param = $source->get_attribute_value
1246                                      ('resParameter',
1247                                       namespace_uri => $NS_SW09);
1248                    if ($anchor eq 'URI' and $param =~ /^[0-9A-Za-z_+.%-]+:/) {
1249                      $result .= '<' . $param . '>';
1250                    } else {
1251                      $result .= '<' . $anchor . ':' . $param . '>';
1252                    }
1253                  }
1254                }
1255                $result .= ']';
1256                $result;
1257              };
1258            }
1259    
1260        $x2t{'#list'}->($src);
1261    
1262    Function:
1263      @Name: get_nth_element
1264      @Main:
1265        my (undef, $node, $ns => $ln, $n) = @_;
1266        return $n if $n < 1;
1267        if ($node->node_type eq '#element' and
1268            $node->namespace_uri eq $ns and
1269            $node->local_name eq $ln) {
1270          return $node unless --$n;
1271        }
1272        for (@{$node->child_nodes}) {
1273          if ($_->node_type eq '#element') {
1274            if ($_->namespace_uri eq $ns and
1275                $_->local_name eq $ln) {
1276              return $_ unless --$n;
1277            } else {
1278              $n = __FUNCPACK__->get_nth_element ($_, $ns => $ln, $n);
1279              return $n if ref $n;
1280            }
1281          } elsif ($_->node_type eq '#fragment' or $_->node_type eq '#document') {
1282            $n = __FUNCPACK__->get_nth_element ($_, $ns => $ln, $n);
1283            return $n if ref $n;
1284          }
1285        }
1286        return $n;
1287    
1288    Function:
1289      @Name: get_element_by_id
1290      @Main:
1291        my (undef, $node, $id) = @_;
1292        return $node if $node->node_type eq '#element'
1293                    and $node->get_attribute_value ('id', default_value => '')
1294                     eq $id;
1295        for (@{$node->child_nodes}) {
1296          if ({'#element'=>1, '#fragment'=>1, '#document'=>1}->{$_->node_type}) {
1297            my $r = __FUNCPACK__->get_element_by_id ($_, $id);
1298            return $r if $r;
1299          }
1300        }
1301    
1302  Function:  Function:
1303    @Name: text_to_xml    @Name: text_to_xml
# Line 345  Function: Line 1317  Function:
1317      my $head = $root->append_new_node (type => '#element',      my $head = $root->append_new_node (type => '#element',
1318                                         namespace_uri => $NS_XHTML2,                                         namespace_uri => $NS_XHTML2,
1319                                         local_name => 'head');                                         local_name => 'head');
1320      if ($source =~ s#^\#\?SuikaWiki/0\.9\b((?>.*))\s*##) {      $root->append_text ("\x0A");
1321        my $param = $1;      my $body = $root->append_new_node (type => '#element',
1322                                           namespace_uri => $NS_XHTML2,
1323                                           local_name => 'body');
1324        $root->append_text ("\x0A");
1325    
1326        if ($source =~ s#^\#\?(SuikaWiki(?:Image)?)/0\.9\b((?>.*))\s*##) {
1327          my $type = $1;
1328          my $param = $2;
1329          $root->set_attribute (Name => $type, namespace_uri => $NS_SW09);
1330          $root->set_attribute (Version => '0.9', namespace_uri => $NS_SW09);
1331        while ($param =~ /\G\s+([a-z-]+)="((?>[^"\\]*)(?>(?>[^"\\]+|\\.)*))"/g) {        while ($param =~ /\G\s+([a-z-]+)="((?>[^"\\]*)(?>(?>[^"\\]+|\\.)*))"/g) {
1332          my ($name, $value) = ($1, $2);          my ($name, $value) = ($1, $2);
1333          $value =~ s/\\(.)/$1/g;          $value =~ s/\\(.)/$1/g;
1334          for ($head->append_new_node (type => '#element',          for ($head->append_new_node (type => '#element',
1335                                       namespace_uri => $NS_SW09,                                       namespace_uri => $NS_SW09,
1336                                       local_name => 'parmeter')) {                                       local_name => 'parameter')) {
1337            $_->set_attribute (name => $name);            $_->set_attribute (name => $name);
1338            for my $value (split /,/, $value) {            for my $value (split /,/, $value) {
1339              $_->append_new_node (type => '#element',              $_->append_new_node (type => '#element',
# Line 363  Function: Line 1344  Function:
1344          }          }
1345          $head->append_text ("\x0A");          $head->append_text ("\x0A");
1346        }        }
1347          
1348          if ($type eq 'SuikaWikiImage') {
1349            $source =~ s/\x0A__IMAGE__\x0A(.*)$//s;
1350            if (my $image = $1) {
1351              $image =~ s/^\s+//;
1352              $image =~ s/\s+$//;
1353              $root->append_new_node
1354                       (type => '#element',
1355                        namespace_uri => $NS_SW09,
1356                        local_name => 'image')
1357                   ->append_text ($image);
1358              $root->append_text ("\x0A");
1359            }
1360          }
1361      } else {      } else {
1362        ## TODO: warn        #$root->set_attribute (Name => 'SuikaWiki', namespace_uri => $NS_SW09);
1363          #$root->set_attribute (Version => '0.9', namespace_uri => $NS_SW09);
1364      }      }
     $root->append_text ("\x0A");  
1365            
1366      my $body = $root->append_new_node (type => '#element',      __FUNCPACK__->block_text_to_xml (\$source => $body, opt => $opt);
                                        namespace_uri => $NS_XHTML2,  
                                        local_name => 'body');  
     __FUNCPACK__->block_text_to_xml (\$source => $body);  
1367    
1368  Function:  Function:
1369    @Name:block_text_to_xml    @Name:block_text_to_xml
# Line 382  Function: Line 1374  Function:
1374      @@lang:en      @@lang:en
1375    @Main:    @Main:
1376      my (undef, $source, $current, %opt) = @_;      my (undef, $source, $current, %opt) = @_;
1377      my %depth;      my %depth = %{$opt{depth} || {}};
1378      my $back_to_section = sub {      my $back_to_section = sub {
1379        my $cur_type = $current->local_name;        my $cur_type = $current->local_name;
1380        while (not (        while (not (
1381                    $cur_type eq 'section'                    $cur_type eq 'section'
1382                 or $cur_type eq 'body'                 or $cur_type eq 'body'
1383                 or $cur_type eq 'bodytext'                 or $cur_type eq 'bodytext'
1384                 or $cur_type eq 'ins'                 or $cur_type eq 'insert'
1385                 or $cur_type eq 'del'                 or $cur_type eq 'delete'
1386                   )                   )
1387        ) {        ) {
1388          $current = $current->parent_node;          $current = $current->parent_node;
# Line 403  Function: Line 1395  Function:
1395        while (not (        while (not (
1396                    $cur_type eq 'section'                    $cur_type eq 'section'
1397                 or $cur_type eq 'body'                 or $cur_type eq 'body'
1398                 or $cur_type eq 'ins'                 or $cur_type eq 'insert'
1399                 or $cur_type eq 'del'                 or $cur_type eq 'delete'
1400                   )                   )
1401              ) {              ) {
1402          $current = $current->parent_node;          $current = $current->parent_node;
# Line 465  Function: Line 1457  Function:
1457          $current = $current->append_new_node (type => '#element',          $current = $current->append_new_node (type => '#element',
1458                                                namespace_uri => $NS_XHTML2,                                                namespace_uri => $NS_XHTML2,
1459                                                local_name => 'li');                                                local_name => 'li');
1460          __FUNCPACK__->inline_text_to_xml (\$line => $current);          __FUNCPACK__->inline_text_to_xml (\$line => $current, %opt);
1461        } elsif ($line =~ s/^(\*+)\s*//) {        } elsif ($line =~ s/^(\*+)\s*//) {
1462          my $depth = length $1;          my $depth = length $1;
1463          $back_to_real_section->();          $back_to_real_section->();
# Line 491  Function: Line 1483  Function:
1483          __FUNCPACK__->inline_text_to_xml (\$line =>          __FUNCPACK__->inline_text_to_xml (\$line =>
1484            $current->append_new_node (type => '#element',            $current->append_new_node (type => '#element',
1485                                       namespace_uri => $NS_XHTML2,                                       namespace_uri => $NS_XHTML2,
1486                                       local_name => 'h')                                       local_name => 'h'), %opt,
1487          );          );
1488        } elsif ($line =~ s/^(?!>>[0-9])(>+)\s*//) {        } elsif ($line =~ s/^(?!>>[0-9])(>+)\s*//) {
1489          my $depth = length $1;          my $depth = length $1;
# Line 523  Function: Line 1515  Function:
1515                                   (type => '#element',                                   (type => '#element',
1516                                    namespace_uri => $NS_XHTML2,                                    namespace_uri => $NS_XHTML2,
1517                                    local_name => 'p');                                    local_name => 'p');
1518            __FUNCPACK__->inline_text_to_xml (\$line => $current);            __FUNCPACK__->inline_text_to_xml (\$line => $current, %opt);
1519          }          }
1520        } elsif ($line =~ s/^(?>:\s*)([^:]+?)\s*:\s*//) {        } elsif ($line =~ s/^(?>:\s*)([^:]+?)\s*:\s*//) {
1521          my $parent_type = $current->local_name;          my $parent_type = $current->local_name;
# Line 542  Function: Line 1534  Function:
1534          __FUNCPACK__->inline_text_to_xml (\"$1" =>          __FUNCPACK__->inline_text_to_xml (\"$1" =>
1535            $current->append_new_node (type => '#element',            $current->append_new_node (type => '#element',
1536                                       namespace_uri => $NS_XHTML2,                                       namespace_uri => $NS_XHTML2,
1537                                       local_name => 'dt')                                       local_name => 'dt'), %opt,
1538          );          );
1539          $current->append_text ("\x0A");          $current->append_text ("\x0A");
1540          $current = $current->append_new_node (type => '#element',          $current = $current->append_new_node (type => '#element',
1541                                                namespace_uri => $NS_XHTML2,                                                namespace_uri => $NS_XHTML2,
1542                                                local_name => 'dd');                                                local_name => 'dd');
1543            __FUNCPACK__->inline_text_to_xml (\$line => $current);            __FUNCPACK__->inline_text_to_xml (\$line => $current, %opt);
1544        } elsif ($line =~ /^\[(INS|DEL)(\([^()\\]*\))?\[\s*$/) {        } elsif ($line =~ /^\[(INS|DEL)(?>(\([^()\\]*\))?)\[\s*$/) {
1545          $current->append_text ("\x0A");          $current->append_text ("\x0A");
1546          my $mod = $current->append_new_node (type => '#element',          my $mod = $current->append_new_node
1547                                               namespace_uri => $NS_XHTML1,                                (type => '#element',
1548                                               local_name => lc $1);                                 namespace_uri => $NS_SW09,
1549                                   local_name => {qw/INS insert DEL delete/}->{$1});
1550          $mod->set_attribute (class => $2) if $2;          $mod->set_attribute (class => $2) if $2;
1551          __FUNCPACK__->block_text_to_xml ($source => $mod,          __FUNCPACK__->block_text_to_xml ($source => $mod, %opt,
1552                                           'return_by_'.$1 => 1);                                           'return_by_'.$1 => 1,
1553                                             depth => \%depth);
1554        } elsif ($line =~ /^\](INS|DEL)\]\s*$/) {        } elsif ($line =~ /^\](INS|DEL)\]\s*$/) {
1555          if ($opt{'return_by_'.$1}) {          if ($opt{'return_by_'.$1}) {
1556            return;            return;
1557          } else {          } else {
1558            ## TODO: warn            ## TODO: warn
1559          }          }
1560        } elsif ($line =~ /^\[PRE(\([^()\\]*\))?\[\s*$/) {        } elsif ($line =~ /^\[PRE(?>(?>\(((?>[^()\\]*)(?>(?>[^()\\]+|\\.)*))\))?)\[\s*$/) {
1561          $current->append_text ("\x0A");          $current->append_text ("\x0A");
1562          my $pre = $current->append_new_node (type => '#element',          my $pre = $current->append_new_node (type => '#element',
1563                                               namespace_uri => $NS_XHTML1,                                               namespace_uri => $NS_XHTML1,
# Line 578  Function: Line 1572  Function:
1572              last;              last;
1573            } else {            } else {
1574              $f ? undef $f : $pre->append_text ("\x0A");              $f ? undef $f : $pre->append_text ("\x0A");
1575              __FUNCPACK__->inline_text_to_xml (\$line => $pre);              __FUNCPACK__->inline_text_to_xml (\$line => $pre, %opt);
1576            }            }
1577          }          }
1578          if (ref $pre) {          if (ref $pre) {
# Line 590  Function: Line 1584  Function:
1584                                               namespace_uri => $NS_XHTML1,                                               namespace_uri => $NS_XHTML1,
1585                                               local_name => 'pre');                                               local_name => 'pre');
1586          $pre->set_attribute (space => 'preserve', namespace_uri => NS_xml_URI);          $pre->set_attribute (space => 'preserve', namespace_uri => NS_xml_URI);
1587          __FUNCPACK__->inline_text_to_xml (\$line => $pre);          __FUNCPACK__->inline_text_to_xml (\$line => $pre, %opt);
1588          while ($$source =~ /\G([^\x0A]*)\x0A/gc) {          while ($$source =~ /\G([^\x0A]*)\x0A/gc) {
1589            my $line = $1;            my $line = $1;
1590            if (length $line == 0) {            if (length $line == 0) {
1591              pos ($$source) -= 1;              pos ($$source) -= 1;
1592              last;              last;
1593              } elsif ($opt{return_by_INS} and $line =~ /^\]INS\]\s*$/) {
1594                return;
1595              } elsif ($opt{return_by_DEL} and $line =~ /^\]DEL\]\s*$/) {
1596                return;
1597            } else {            } else {
1598              $pre->append_text ("\x0A");              $pre->append_text ("\x0A");
1599              __FUNCPACK__->inline_text_to_xml (\$line => $pre);              __FUNCPACK__->inline_text_to_xml (\$line => $pre, %opt);
1600            }            }
1601          }          }
1602        } elsif ($line =~ /^,/) {        } elsif ($line =~ /^,/) {
# Line 609  Function: Line 1607  Function:
1607                              ->append_new_node (type => '#element',                              ->append_new_node (type => '#element',
1608                                                 namespace_uri => $NS_XHTML2,                                                 namespace_uri => $NS_XHTML2,
1609                                                 local_name => 'tbody');                                                 local_name => 'tbody');
1610          __FUNCPACK__->tablerow_text_to_xml (\$line => $tbody);          __FUNCPACK__->tablerow_text_to_xml (\$line => $tbody, %opt);
1611          while ($$source =~ /\G(,[^\x0A]*)\x0A/gc) {          while ($$source =~ /\G(,[^\x0A]*)\x0A/gc) {
1612            __FUNCPACK__->tablerow_text_to_xml (\"$1" => $tbody);            __FUNCPACK__->tablerow_text_to_xml (\"$1" => $tbody, %opt);
1613          }          }
1614        } else {        } else {
1615          my $current_type = $current->local_name;          my $current_type = $current->local_name;
1616          if ($current_type eq 'section'          if ($current_type eq 'section'
1617           or $current_type eq 'body'           or $current_type eq 'body'
1618           or $current_type eq 'bodytext'           or $current_type eq 'bodytext'
1619           or $current_type eq 'ins'           or $current_type eq 'insert'
1620           or $current_type eq 'del') {           or $current_type eq 'delete') {
1621            $current->append_text ("\x0A");            $current->append_text ("\x0A");
1622            if ($line =~ s/^__&&([^&]+)&&__//) {            if ($line =~ s/^__&&([^&]+)&&__//) {
1623              $current->append_new_node (type => '#element',              $current->append_new_node (type => '#element',
# Line 632  Function: Line 1630  Function:
1630                                              local_name => 'form')) {                                              local_name => 'form')) {
1631                $_->set_attribute (id => $1) if $1;                $_->set_attribute (id => $1) if $1;
1632                my ($i, $t, $o) = ($2, $3 || '', $4 || '');                my ($i, $t, $o) = ($2, $3 || '', $4 || '');
1633                s/\\(.)/$1/g for $i, $t, $o;                s/\\(.)/$1/g for ($i, $t, $o);
1634                $_->set_attribute (input => $i);                $_->set_attribute (input => $i);
1635                $_->set_attribute (template => $t);                $_->set_attribute (template => $t);
1636                $_->set_attribute (option => $o);                $_->set_attribute (option => $o);
# Line 646  Function: Line 1644  Function:
1644                $_->set_attribute (parameter => $3) if defined $3;                $_->set_attribute (parameter => $3) if defined $3;
1645              }              }
1646            }            }
1647            $current = $current->append_new_node            if (length $line) {
1648                                   (type => '#element',              $current = $current->append_new_node
1649                                    namespace_uri => $NS_XHTML2,                                     (type => '#element',
1650                                    local_name => 'p');                                      namespace_uri => $NS_XHTML2,
1651            __FUNCPACK__->inline_text_to_xml (\$line => $current);                                      local_name => 'p');
1652                __FUNCPACK__->inline_text_to_xml (\$line => $current, %opt);
1653              }        
1654          } else {          } else {
1655            $current->append_text (" "); # replacement of prev.line's \n            $current->append_text ("\x0A"); # replacement of prev.line's \n
1656            __FUNCPACK__->inline_text_to_xml (\$line => $current);            __FUNCPACK__->inline_text_to_xml (\$line => $current, %opt);
1657          }          }
1658        }        }
1659      }      }
# Line 676  Function: Line 1676  Function:
1676                                            local_name => 'tr');                                            local_name => 'tr');
1677      my $prev_cell;      my $prev_cell;
1678      while ($$source =~ /\G,\s*/gc) {      while ($$source =~ /\G,\s*/gc) {
1679        $$source =~ /\G([^,"]+|"(?>[^"\\]*)(?>(?>[^"\\]+|\\.)*)"\s*)/gc;        $$source =~ /\G([^,"][^,]*|"(?>[^"\\]*)(?>(?>[^"\\]+|\\.)*)"\s*)/gc;
1680        my $cell = $1;        my $cell = $1;
1681        if ($cell =~ s/^"//) {        if ($cell =~ s/^"//) {
1682          $cell =~ s/"\s*$//g;          $cell =~ s/"\s*$//g;
# Line 698  Function: Line 1698  Function:
1698                                 (type => '#element',                                 (type => '#element',
1699                                  namespace_uri => $NS_XHTML2,                                  namespace_uri => $NS_XHTML2,
1700                                  local_name => 'td');                                  local_name => 'td');
1701        __FUNCPACK__->inline_text_to_xml (\$cell => $prev_cell);        __FUNCPACK__->inline_text_to_xml (\$cell => $prev_cell, %opt);
1702      }      }
1703      # TODO: warn      # TODO: warn
1704    
# Line 709  Function: Line 1709  Function:
1709        SuikaWiki/0.9 text format to XML representation - inline level elements        SuikaWiki/0.9 text format to XML representation - inline level elements
1710      @@lang:en      @@lang:en
1711    @Main:    @Main:
1712        my (undef, $source => $current, %opt) = @_;
1713    
1714    my $ElementDef = {    my $ElementDef = {
1715      ABBR    => {ln => 'abbr', ns_uri => $NS_SW09},      ABBR    => {ln => 'abbr', ns_uri => $NS_XHTML2},
1716      CODE    => {ln => 'code', ns_uri => $NS_XHTML2},      CODE    => {ln => 'code', ns_uri => $NS_XHTML2},
1717      DEL     => {ln => 'del',  ns_uri => $NS_XHTML1},      DEL     => {ln => 'del',  ns_uri => $NS_XHTML1},
1718      DFN     => {ln => 'dfn',  ns_uri => $NS_XHTML2},      DFN     => {ln => 'dfn',  ns_uri => $NS_XHTML2},
# Line 722  Function: Line 1724  Function:
1724      SAMP    => {ln => 'samp', ns_uri => $NS_XHTML2},      SAMP    => {ln => 'samp', ns_uri => $NS_XHTML2},
1725      SUB     => {ln => 'sub',  ns_uri => $NS_XHTML2},      SUB     => {ln => 'sub',  ns_uri => $NS_XHTML2},
1726      SUP     => {ln => 'sup',  ns_uri => $NS_XHTML2},      SUP     => {ln => 'sup',  ns_uri => $NS_XHTML2},
1727      VAR     => {ln => 'var',  ns_uri => $NS_XHTML2},      VAR     => {ln => 'var',  ns_uri => $NS_XHTML2},
1728      WEAK    => {ln => 'weak', ns_uri => $NS_SW09},      WEAK    => {ln => 'weak', ns_uri => $NS_SW09},
1729        AA      => {ln => 'aa',   ns_uri => $NS_AA},     ## SuikaWiki/0.10
1730        CITE    => {ln => 'cite', ns_uri => $NS_XHTML2}, ## SuikaWiki/0.10
1731        CSECTION => {ln => 'csection', ns_uri => $NS_SW010}, ## SuikaWiki/0.10
1732        KEY     => {ln => 'key',  ns_uri => $NS_SW010},  ## SuikaWiki/0.10
1733        QN      => {ln => 'qn',   ns_uri => $NS_SW010},  ## SuikaWiki/0.10
1734        SRC     => {ln => 'src',  ns_uri => $NS_SW010},  ## SuikaWiki/0.10
1735      anchor  => {ln => 'anchor', ns_uri => $NS_SW09, has_fragment_no => 1},      anchor  => {ln => 'anchor', ns_uri => $NS_SW09, has_fragment_no => 1},
1736      del     => {has_cite => 1},      del     => {has_cite => 1},
1737      ins     => {has_cite => 1},      ins     => {has_cite => 1},
1738        nsuri   => {ln => 'nsuri', ns_uri => $NS_SW010}, ## SuikaWiki/0.10
1739      q       => {has_cite => 1},      q       => {has_cite => 1},
1740        qname   => {ln => 'qname', ns_uri => $NS_SW010}, ## SuikaWiki/0.10
1741      rb      => {ln => 'rb',   ns_uri => $NS_XHTML2, is_nested => 1},      rb      => {ln => 'rb',   ns_uri => $NS_XHTML2, is_nested => 1},
1742      rt      => {ln => 'rt',   ns_uri => $NS_XHTML2, is_nested => 1},      rt      => {ln => 'rt',   ns_uri => $NS_XHTML2, is_nested => 1},
1743    };    };
1744    
     my (undef, $source => $current, %opt) = @_;  
1745      if ($$source =~ /\G\[([0-9]+)\]/gc) {      if ($$source =~ /\G\[([0-9]+)\]/gc) {
1746        for ($current->append_new_node (type => '#element',        for ($current->append_new_node (type => '#element',
1747                                        namespace_uri => $NS_SW09,                                        namespace_uri => $NS_SW09,
1748                                        local_name => 'anchor-end')) {                                        local_name => 'anchor-end')) {
1749          $_->set_attribute (anchor => 0+$1);          $_->set_attribute (anchor => 0+$1,
1750                               namespace_uri => $NS_SW09);
1751          $_->append_text ('['.$1.']');          $_->append_text ('['.$1.']');
1752        }        }
1753      }      }
# Line 749  Function: Line 1759  Function:
1759                                                local_name => 'form');                                                local_name => 'form');
1760          if ($$source =~ /\G$Reg_Form_Content_M\]\]/ogc) {          if ($$source =~ /\G$Reg_Form_Content_M\]\]/ogc) {
1761            $form->set_attribute (id => $1) if $1;            $form->set_attribute (id => $1) if $1;
1762            $form->set_attribute (input => $2);            my ($i, $t, $o) = ($2, $3, $4);
1763            $form->set_attribute (template => $3);            s/\\(.)/$1/g for ($i, $t, $o);
1764            $form->set_attribute (option => $4);            $form->set_attribute (input => $i);
1765              $form->set_attribute (template => $t);
1766              $form->set_attribute (option => $o);
1767          } elsif ($$source =~ /\G$Reg_Embed_Content_M\]\]/ogc) {          } elsif ($$source =~ /\G$Reg_Embed_Content_M\]\]/ogc) {
1768            $form->set_attribute (ref => $1);            $form->set_attribute (ref => $1);
1769            $form->set_attribute (id => $2) if $2;            $form->set_attribute (id => $2) if $2;
1770            $form->set_attribute (parameter => $3) if defined $3;            $form->set_attribute (parameter => $3) if defined $3;
1771          } else {          } else {
1772            ## TODO: error            ## TODO: error
1773            CORE::die $$source;            SuikaWiki::Plugin->module_package('Error')->report_error_simple ($opt{opt}->{o}->{wiki}, InvalidForm => substr ($$source, pos ($$source)));
1774          }          }
1775        } elsif ($$source =~ /\G\[(?>([A-Z]+)(?>\(([^)]*)\))?)?\[/gc) {        } elsif ($$source =~ /\G\[(?>([A-Z]+)(?>\(((?>[^()\\]*)(?>(?>[^()\\]+|\\.)*))\))?)?\[/gc) {
1776          my $type = $1 || 'anchor';          my $type = $1 || 'anchor';
1777          my $param = $2;          my $param = $2;
1778          my $def = $ElementDef->{ $type };          my $def = $ElementDef->{ $type };
1779          unless ($def) {          unless ($def) {
1780            ## TODO: error            ## TODO: error
1781              $def = $ElementDef->{CODE};
1782          }          }
1783          $current = $current->append_new_node (type => '#element',          $current = $current->append_new_node (type => '#element',
1784                                                namespace_uri => $def->{ns_uri},                                                namespace_uri => $def->{ns_uri},
# Line 777  Function: Line 1790  Function:
1790                                   (type => '#element',                                   (type => '#element',
1791                                    namespace_uri => $ElementDef->{rb}->{ns_uri},                                    namespace_uri => $ElementDef->{rb}->{ns_uri},
1792                                    local_name => $ElementDef->{rb}->{ln});                                    local_name => $ElementDef->{rb}->{ln});
1793            } elsif ($type eq 'QN') {
1794              $current = $current->append_new_node
1795                                   (type => '#element',
1796                                    namespace_uri => $ElementDef->{qname}->{ns_uri},
1797                                    local_name => $ElementDef->{qname}->{ln});
1798          }          }
1799          $depth++;          $depth++;
1800        } elsif ($$source =~ /\G\](?> <([0-9A-Za-z_+.%-]+):($Reg_URI_Opaque)>        } elsif ($$source =~ /\G\](?> <([0-9A-Za-z_+.%-]+):($Reg_URI_Opaque)>
# Line 789  Function: Line 1807  Function:
1807          }          }
1808          my $def = $ElementDef->{$current->local_name} || {};          my $def = $ElementDef->{$current->local_name} || {};
1809          if (defined $anchor) {          if (defined $anchor) {
1810            if ($def->{has_fragment_no}) {            $current->set_attribute (anchor => $anchor + 0,
1811              $current->set_attribute (anchor => $anchor + 0);                                     namespace_uri => $NS_SW09);
           } else {  
             $current->set_attribute (anchor => $anchor + 0,  
                                      namespace_uri => $NS_SW09);  
           }  
1812          } elsif (defined $scheme) {          } elsif (defined $scheme) {
1813            if ($def->{has_cite}) {            if ($scheme =~ /[A-Z]/) {
1814              $current->set_attribute (cite => "$scheme:$opaque");              $current->set_attribute (resScheme => $scheme,
1815                                         namespace_uri => $NS_SW09);
1816                $current->set_attribute (resParameter => $opaque,
1817                                         namespace_uri => $NS_SW09);
1818            } else {            } else {
1819              $current->set_attribute (cite => "$scheme:$opaque",              $current->set_attribute (resScheme => 'URI',
1820                                         namespace_uri => $NS_SW09);
1821                $current->set_attribute (resParameter => "$scheme:$opaque",
1822                                       namespace_uri => $NS_SW09);                                       namespace_uri => $NS_SW09);
1823            }            }
1824          }          }
1825          $current = $current->parent_node;          $current = $current->parent_node;
1826          $current = $current->parent_node if $def->{is_nested};          $current = $current->parent_node if $def->{is_nested};
1827          $depth--;          $depth--;
1828        } elsif ($$source =~ /\G\]\s+\[/gc) {        } elsif ($$source =~ /\G\]\s*\[/gc) {
1829          if ($current->local_name eq 'rb' or $current->local_name eq 'rt') {          if ($current->local_name eq 'rb' or $current->local_name eq 'rt') {
1830            $current = $current->parent_node            $current = $current->parent_node
1831                               ->append_new_node                               ->append_new_node
1832                                   (type => '#element',                                   (type => '#element',
1833                                    namespace_uri => $ElementDef->{rt}->{ns_uri},                                    namespace_uri => $ElementDef->{rt}->{ns_uri},
1834                                    local_name => $ElementDef->{rt}->{ln});                                    local_name => $ElementDef->{rt}->{ln});
1835            } elsif ($current->local_name eq 'qname') {
1836              $current = $current->parent_node
1837                                 ->append_new_node
1838                                   (type => '#element',
1839                                    namespace_uri => $ElementDef->{nsuri}->{ns_uri},
1840                                    local_name => $ElementDef->{nsuri}->{ln});
1841          } else {          } else {
1842            $current->append_text ($$source, $-[0], $+[0]-$-[0]);            $current->append_text (substr ($$source, $-[0], $+[0]-$-[0]-1));
1843              pos ($$source)--;
1844          }          }
1845        } elsif ($$source =~ /\G'''?/gc) {        } elsif ($$source =~ /\G'''?/gc) {
1846          my $type = $+[0] - $-[0] == 3 ? 'strong' : 'em';          my $type = $+[0] - $-[0] == 3 ? 'strong' : 'em';
# Line 826  Function: Line 1852  Function:
1852                                    namespace_uri => $NS_XHTML2,                                    namespace_uri => $NS_XHTML2,
1853                                    local_name => $type);                                    local_name => $type);
1854          }          }
1855        } elsif ($$source =~ /\G<([0-9A-Za-z_+.%-]+):($Reg_URI_Opaque)>/gc) {        } elsif ($$source =~ /\G<([0-9A-Za-z_+.%-]+):($Reg_URI_Opaque)>/gco) {
1856          my ($scheme, $data) = ($1, $2);          my ($scheme, $data) = ($1, $2);
1857          my $link = $current->append_new_node          my $link = $current->append_new_node
1858                                   (type => '#element',                                   (type => '#element',
1859                                    namespace_uri => $NS_SW09,                                    namespace_uri => $NS_SW09,
1860                                    local_name => 'anchor-external');                                    local_name => 'anchor-external');
1861          if (substr ($scheme, 0, 1) =~ /[A-Z]/) {          if (substr ($scheme, 0, 1) =~ /[A-Z]/) {
1862            $link->set_attribute (scheme => $scheme);            $link->set_attribute (resScheme => $scheme,
1863            $link->set_attribute (data => $data);                                  namespace_uri => $NS_SW09);
1864              $link->set_attribute (resParameter => $data,
1865                                    namespace_uri => $NS_SW09);
1866          } else { # URI Reference          } else { # URI Reference
1867            $link->set_attribute (href => $scheme.':'.$data);            $link->set_attribute (resScheme => 'URI',
1868                                    namespace_uri => $NS_SW09);
1869              $link->set_attribute (resParameter => $scheme.':'.$data,
1870                                    namespace_uri => $NS_SW09);
1871          }          }
1872            $link->append_text ($scheme.':'.$data);
1873        } elsif ($$source =~ /\G__&&/gc) {        } elsif ($$source =~ /\G__&&/gc) {
1874          if ($$source =~ /\G([^&]+)&&__/gc) {          if ($$source =~ /\G([^&]+)&&__/gc) {
1875            $current->append_new_node            $current->append_new_node
# Line 849  Function: Line 1881  Function:
1881            $current->append_text ('__&&');            $current->append_text ('__&&');
1882          }          }
1883        } elsif ($$source =~ /\G((?>        } elsif ($$source =~ /\G((?>
1884                                    [^'\[\]<>]+                                    [^'\[\]<>_]+
1885                                  | '   (?!')                                  | '   (?!')
1886                                  | \[  (?![A-Z\[])                                  | \[  (?!\[|[A-Z]+(?>\([^()\\]*
1887                                                           (?>[^()\\]+|\\.)*\))?\[)
1888                                  | \]  (?! \]                                  | \]  (?! \]
1889                                          | >>[0-9]+\]                                          | >>[0-9]+\]
1890                                          | <[0-9A-Za-z_+.%-]+:$Reg_URI_Opaque>\]                                          | <[0-9A-Za-z_+.%-]+:$Reg_URI_Opaque>\]
# Line 865  Function: Line 1898  Function:
1898          for ($current->append_new_node (type => '#element',          for ($current->append_new_node (type => '#element',
1899                                          namespace_uri => $NS_SW09,                                          namespace_uri => $NS_SW09,
1900                                          local_name => 'anchor-internal')) {                                          local_name => 'anchor-internal')) {
1901            $_->set_attribute (anchor => 0+$1);            $_->set_attribute (anchor => 0+$1,
1902                                 namespace_uri => $NS_SW09);
1903            $_->append_text ('>>'.$1);            $_->append_text ('>>'.$1);
1904          }          }
1905        } else {        } else {
1906          die "Implementation buggy: ", substr ($$source, pos $$source);          CORE::die "Implementation buggy: ", substr ($$source, pos $$source);
1907        }        }
1908      }      }
1909    
 Function:  
   @Name: to_html  
   @Description:  
     @@@:Converting SuikaWiki/0.9 to Hypertext Markup Language  
     @@lang:en  
   @Main:  
             my (undef, $txt, %option) = @_;  
               
             ## Load constants  
 #           my %const;  
 #           if ($option{magic} =~ /import="([^"]+)"/) {  
 #             for (split /\s*,\s*/, $1) {  
 #               my $wp = $main::database{$_};  
 #               if ($wp =~ m!^\#\?SuikaWikiConst/(?:0.9|1.0)!) {  
 #                 wiki::suikawikiconst::to_hash ($wp => \%const);  
 #               }  
 #             }  
 #           }  
               
 #           $txt =~ s{__&&([^&]+)&&__}{defined $const{$1}?$const{$1}:qq(__&&$1&&__)}ge;  
   
             my (@txt) = split(/\n/, $txt);  
             my (@saved, @result);  
             my $p = $option{-parent}  
                  || Message::Markup::XML::Node->new (type => '#fragment');  
             my $current = $p;  
             my %depth;  
             my $exit_p = sub {  
                   my $current = shift;  
                   if ($current->local_name eq 'p') {  
                     $current = $current->parent_node;  
                   }  
                   $current;  
             };  
             my $cut_anchor = sub {  
               my ($current, $content) = @_;  
                   if ($content =~ s/^\s*\[([0-9]+)\]\s+//) {  
                     my $num = 0 + $1;  
                     for my $A ($current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'a')) {  
                       $A->set_attribute (id => 'anchor-' . $num);  
                       $A->set_attribute (name => 'anchor-' . $num);  
                       $A->set_attribute (class => 'anchor');  
                       $A->append_text ('[' . $num . ']');  
                     }  
                     $current->append_text (' ');  
                   }  
               $content;  
             };  
             my $back_to_section = sub {  
               my $current = shift;  
               while ($current->node_type ne '#fragment') {  
                 if ({ins=>1,del=>1,blockquote=>1}->{$current->local_name}) {  
                   return $current;  
                 }  
                 $current = $current->parent_node;  
               }  
               return $current;  
             };  
               
             foreach (@txt) {  
                 chomp;  
                 if ($depth{block_name}->{$depth{block}} ne 'PRE' && /^\*\*\*\*\*([^\x0D\x0A]*)/) {  
                     $current = &$back_to_section ($current);  
                     for my $H ($current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'h6')) {  
                       $H->append_node (_inline_xml ($1, %option));  
                     }  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^\*\*\*\*([^\x0D\x0A]*)/) {  
                     $current = &$back_to_section ($current);  
                     for my $H ($current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'h5')) {  
                       $H->append_node (_inline_xml ($1, %option));  
                     }  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^\*\*\*([^\x0D\x0A]*)/) {  
                     $current = &$back_to_section ($current);  
                     for my $H ($current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'h4')) {  
                       $H->append_node (_inline_xml ($1, %option));  
                     }  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^\*\*([^\x0D\x0A]*)/) {  
                     $current = &$back_to_section ($current);  
                     for my $H ($current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'h3')) {  
                       $H->append_node (_inline_xml ($1, %option));  
                     }  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^\*([^\x0D\x0A]*)/) {  
                     $current = &$back_to_section ($current);  
                     for my $H ($current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'h2')) {  
                       $H->append_node (_inline_xml ($1, %option));  
                     }  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^([-=]{1,6})(.*)/) {  
                   my ($depth, $content, $type) = (length ($1), $2, (substr ($1, -1) eq '-' ? 'ul' : 'ol'));  
                   $current = &$exit_p ($current);  
                   if ($current->local_name eq 'li') {  
                     if ($depth{list} == $depth && $depth{list_type} eq $type) {  
                       $current = $current->parent_node;  
                     } elsif ($depth <= $depth{list}) {  
                       for (1..($depth{list} - $depth)*2) {  
                         ($depth{list} = 1, last) unless ref $current->parent_node;  
                         ($depth{list} = 1, last) unless {li=>1,ul=>1,ol=>1}->{$current->local_name};  
                         $current = $current->parent_node;  
                         $depth{list} -= 0.5;  
                       }  
                       $current = $current->parent_node;  
                       if ($type ne $current->local_name) {  
                         $current = $current->parent_node->append_new_node (namespace_uri => $NS_XHTML1, local_name => $type);  
                         $current->parent_node->append_text ("\n");  
                       }  
                     } else {    # $depth{list} < $depth  
                       $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => $type);  
                       $current->parent_node->append_text ("\n");  
                       $depth{list}++;  
                     }  
                   } else {  
                     $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => $type);  
                     $current->parent_node->append_text ("\n\n");  
                     $depth{list} = 1;  
                   }  
                   $depth{list_type} = $type;  
                   $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'li');  
                   $current->parent_node->append_text ("\n");  
                   $content = &$cut_anchor ($current, $content);  
                   $current->append_node (_inline_xml ($content, %option));  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^:([^:]+):(.*)/) {  
                   $current = &$exit_p ($current);  
                   if ($current->local_name eq 'dd') {  
                     $current = $current->parent_node;  
                   } else {  
                     $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'dl');  
                   }  
                   $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'dt')  
                           ->append_node (_inline_xml ($1, %option));  
                   $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'dd');  
                   $current->append_node (_inline_xml ($2, %option));  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^(?!>>[0-9])(>{1,5})(.*)/) {  
                   my ($depth, $content) = (length $1, $2);  
                   $current = &$exit_p ($current);  
                   if ($depth == $depth{bq}) {  
                     #  
                   } elsif ($depth{bq} < $depth) {  
                     $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'blockquote');  
                     $depth{bq}++;  
                   } else {      # $depth < $depth{bq}  
                     for (1..($depth{bq}-$depth)) {  
                       last if $current->node_type eq '#fragment';  
                       $current = &$back_to_section ($current->parent_node);  
                     }  
                     $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'blockquote')  
                       unless $current->local_name eq 'blockquote';  
                     $depth{bq} = $depth;  
                   }  
                   if (length $content) {  
                     $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'p');  
                     $current->append_node (_inline_xml ($content, %option));  
                   }  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^\s*$/) {  
                   $current = &$back_to_section ($current);  
                   while ($current->local_name eq 'blockquote') {  
                     $depth{bq}--;  
                     $current = &$back_to_section ($current->parent_node);  
                   }  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^(\s+.*)$/) {  
                   if ($current->local_name ne 'pre') {  
                     $current = &$exit_p ($current)->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'pre');  
                     #$depth{block_name}->{++$depth{block}} = 'pre';  
                   }  
                   $current->append_node (_inline_xml ($1, %option));  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^\,(.*?)[\x0D\x0A]*$/) {  
                   $current = &$exit_p ($current);  
                   if ($current->local_name eq 'td') {  
                     $current = $current  
                                ->parent_node    # tr  
                                ->parent_node    # tbody  
                                ->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'tr');  
                   } else {  
                     $current = $current  
                                ->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'table')  
                                ->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'tbody')  
                                ->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'tr');  
                   }  
                   $current->parent_node->append_text ("\n");    # </tr>\n  
                   my $tmp = "$1,";  
                   my @value = map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_} ($tmp =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g);  
                   my @colspan = map {($_ eq '==') ? 0 : 1} @value;  
                   my ($tr, $td) = ($current, $current);  
                   for (my $i = 0; $i < @value; $i++) {  
                     if ($colspan[$i]) {  
                       while ($i + $colspan[$i] < @value and $value[$i + $colspan[$i]] eq '==') {  
                         $colspan[$i]++;  
                       }  
                       $td = $tr->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'td');  
                       $td->set_attribute (colspan => $colspan[$i]) if $colspan[$i] > 1;  
                       $td->append_node (_inline_xml ($value[$i], %option));  
                     }  
                   }  
                   if ($td->local_name eq 'tr') {        # No <td/> in the <tr/> (error!)  
                     $td = $tr->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'td');  
                   }  
                   $current = $td;  
                 } elsif (/^\[(INS|DEL|PRE)\[\s*$/) {  
                   if ($depth{block_name}->{$depth{block}} ne 'PRE') {  
                     $current = &$exit_p ($current)->append_new_node (namespace_uri => $NS_XHTML1, local_name => lc $1);  
                     $depth{block}++;  
                     $depth{block_name}->{$depth{block}} = $1;  
                   } else {  
                     $current->append_text ($_);  
                   }  
                 } elsif ($depth{block} && /^\]($depth{block_name}->{$depth{block}})\]\s*$/) {  
                   while ($current->node_type ne '#fragment') {  
                     if ($current->local_name eq lc $depth{block_name}->{$depth{block}}) {  
                       $current = $current->parent_node;  
                       $depth{block}--;  
                       last;  
                     }  
                     $current = $current->parent_node;  
                   }  
                 } else {  
                   if ($current->node_type eq '#fragment' || {ins=>1,del=>1}->{$current->local_name}) {  
                     $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'p');  
                     $current->parent_node->append_text ("\n\n");        # <P> is two <BR>s:-)  
                   }  
                   $current->append_node (_inline_xml (&$cut_anchor ($current, $_), %option));  
                 }  
             }  
             $p;  
   
 Function:  
   @Name: _id_and_name_xml  
   @Main:          
           my ($e, $name) = @_;  
           $e->set_attribute (id => $name);  
           if (SuikaWiki::Plugin->user_agent_names =~ m#Mozilla/[12]\.|Microsoft Internet Explorer#) {  
             $e->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'a')  
               ->set_attribute (name => $name);  
           }  
   
 Function:  
   @Name: _inline_xml  
   @Main:          
           my ($line, %option) = @_;  
           my $l = Message::Markup::XML::Node->new (type => '#fragment');  
           my $current = $l;  
           $line =~ s{(?:\[([A-Z]+)(?:\(([^)]*)\))?\[|(\[\[#form(?:\([A-Za-z0-9-]+\))?(?::'(?:[^'\\]|\\.)*')+\]\]|\[\[[^]]+\](?:>>[0-9]+)?\])|(\]\])|(\] \[)|(>>[0-9]+|<[A-Za-z0-9%]+:[^>]+>|'''?)|([\[\]'<>]|[^\[\]'<>]+))}{  
             my ($el_name, $attr, $lnk, $etag, $nxt, $misc, $s) = ($1, $2, $3, $4, $5, $6, $7);  
             if ($el_name) {  
               my $edef = {  
                 ABBR    => {html_el => 'abbr', use_class_attr => 1},  
                 CODE    => {html_el => 'code', use_class_attr => 1},  
                 DEL     => {html_el => 'del', use_class_attr => 1},  
                 DFN     => {html_el => 'dfn', use_class_attr => 1},  
                 INS     => {html_el => 'ins', use_class_attr => 1},  
                 KBD     => {html_el => 'kbd', use_class_attr => 1},  
                 RUBY    => {html_el => 'ruby'},  
                 RUBYB   => {html_el => 'ruby', html_class => 'descriptive'},  
                 SAMP    => {html_el => 'samp', use_class_attr => 1},  
                 SUB     => {html_el => 'sub'},  
                 SUP     => {html_el => 'sup'},  
                 VAR     => {html_el => 'var', use_class_attr => 1},  
                 WEAK    => {html_el => 'span', html_class => 'weak'},  
               }->{ $el_name };  
               if ($edef) {  
                 $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => $edef->{html_el});  
                 $current->set_attribute (class => $edef->{html_class}) if $edef->{html_class};  
                 $current->get_attribute ('class', make_new_node => 1)  
                         ->append_text ($attr) if $attr && $edef->{use_class_attr};  
                 if ($edef->{html_el} eq 'ruby') {  
                   $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'rb');  
                 }  
               } else {  
                 $current->append_text ($&);  
               }  
             } elsif ($etag) {  
               if (ref $current->parent_node) {  
                 if ($current->node_type eq '#attribute') {  
                   $current = $current->parent_node;  
                 }  
                 $current = $current->parent_node;  
                 if ($current->local_name eq 'ruby') {  
                   $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'rp', value => ')');  
                   $current = $current->parent_node;  
                 }  
               } else {  
                 $current->append_text (']]');  
               }  
             } elsif ($nxt) {  
               my $c_l_n = $current->local_name;  
               if ($c_l_n eq 'rb') {  
                 for ($current->parent_node) {  
                   $_->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'rp', value => '(');  
                   $current = $_->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'rt');  
                 }  
               } elsif ($c_l_n eq 'rt') {  
                 for ($current->parent_node) {  
                   $_->append_text (' ');  
                   $current = $_->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'rt');  
                 }  
               } elsif ($c_l_n eq 'abbr') {  
                 $current = $current->get_attribute ('title', make_new_node => 1);  
               } else {  
                 $current->append_text ('] [');  
               }  
             } elsif ($lnk) {  
               if ($lnk =~ /\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/) {  
                 $current->append_new_node (type => '#xml', value => scalar SuikaWiki::Plugin::WikiFormCore->_make_custom_form ($1, $2, $3, $4, \%option));  
               } elsif ($lnk =~ /\[\[([^]]+)\](?:>>([0-9]+))?\]/) {  
                 my ($page, $anchor) = ($1, $2);  
                 if (substr ($page, 0, 1) eq '#') {  
                   $current->append_new_node (type => '#xml', value => scalar embedded_to_html ($lnk, $option{page}));  
                 } else {  
                   $current->append_node (SuikaWiki::Plugin->module_package ('WikiLinking')->to_wikipage_in_html ({  
                         label   => SuikaWiki::Plugin->resource ('Link:toWikiPage:SourceLabel'),  
                   } => {  
 #TODO:                  base    => [$option{page}],  
                         page_name_relative      => [split m#//#, $page],  
                         page_anchor_no  => 0+$anchor,  
                   }, {o=>$option{o}}));  
                   #$current->append_new_node (type => '#xml', value => scalar main::make_wikilink ($page, anchor => 0+$anchor, base => $option{page}));  
                 }  
               }  
             } elsif ($misc) {  
               if ($misc =~ />>([0-9]+)/) {  
                 for my $A ($current->append_new_node (local_name => 'a', namespace_uri => $NS_XHTML1)) {  
                   $A->set_attribute (href => '#anchor-' . $1);  
                   $A->set_attribute (class => 'wiki-anchor');  
                   $A->append_text ('>>' . $1);  
                 }  
               } elsif ($misc =~ /<([A-Za-z0-9%]+:[^>]+)>/) {    # BUG: <IW:foo:"<foo>"> doesn't match  
                 $current->append_new_node (type => '#xml', value => scalar main::make_urilink ($1));  
               } elsif ($misc eq q('')) {  
                 if ($current->local_name eq 'em') {  
                   $current = $current->parent_node;  
                 } else {  
                   $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'em');  
                 }  
               } else {  # '''  
                 if ($current->local_name eq 'strong') {  
                   $current = $current->parent_node;  
                 } else {  
                   $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'strong');  
                 }  
               }  
             } else {  
               $current->append_text ($s);  
             }  
             '';  
           }ge;  
           return $l;  
   
 Function:  
   @Name: embedded_to_html  
   @Main:          
             my ($embedded, $bPage) = @_;  
             my $CommentIndex = SuikaWiki::Plugin->new_index ('sw09--comment');  
             if ($embedded eq '[[#comment]]' or $embedded eq '[[#rcomment]]') {  
               unless ($main::_EMBEDED) {  
                 my $lastmodified = SuikaWiki::Plugin->get_data (lastmodified => [split m!//!, $bPage]);  
                 return <<"EOD";  
                 <form action="@{[SuikaWiki::Plugin->uri ('wiki')]}" method="post" id="x-comment-@{[$CommentIndex]}" class="comment"><p>  
             <input type="hidden" name="mycmd" value="comment" />  
             <input type="hidden" name="mypage" value="@{[SuikaWiki::Plugin->escape($bPage)]}" />  
             <input type="hidden" name="myLastModified" value="$lastmodified" />  
             <input type="hidden" name="mytouch" value="on" />  
             <input type="hidden" name="comment_index" value="$CommentIndex" />  
         \    @{[SuikaWiki::Plugin->resource('WikiForm:WikiComment:Name=',escape=>1)]}  
             <input type="text" name="myname" value="" size="10" class="comment-name" />  
             <input type="text" name="mymsg" value="" size="30" class="comment-msg" />  
             <input type="submit" value="@{[SuikaWiki::Plugin->resource('WikiForm:Add',escape=>1)]}" title="@{[SuikaWiki::Plugin->resource('WikiForm:AddLong',escape=>1)]}" class="comment-submit" />  
         </p></form>  
   EOD  
              } else {  
                 return <<"EOD";  
         <del><form action="@{[SuikaWiki::Plugin->uri ('wiki')]}" method="get">  
             <input type="hidden" name="mycmd" value="default" />  
             <input type="hidden" name="mypage" value="@{[SuikaWiki::Plugin->escape($bPage)]}" />  
          \   @{[SuikaWiki::Plugin->resource('WikiForm:WikiComment:Name=',escape=>1)]}  
             <input type="text" name="myname" value="" size="10" disabled="disabled" />  
             <input type="text" name="mymsg" value="" size="60" disabled="disabled" />  
         </form></del>  
         EOD  
             }  
           } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) {  
             my ($name, $r) = ($1, '');  
             if ($name =~ s/^IMG://) {  
               my ($magic, $content) = SuikaWiki::Plugin->magic_and_content ($main::database{$name});  
               $r = &main::convert_format ($content, $magic => 'HTML_fragment', page => $name, magic => $magic, -error_no_return => 1);  
               if (defined $r) {  
                 return $r;  
               } else {  
                 return '<span class="error-embed-image">'.SuikaWiki::Plugin->resource ('Embed:ImageNotSupported', escape=>1).'</span>';  
               }  
             } else {  
               if ($main::_EMBEDED != 1) {  
                 my ($cf, $content) = SuikaWiki::Plugin->magic_and_content ($main::database{$name});  
                 $cf ||= '#?SuikaWiki/0.9';  
                 if ($cf =~ m!^#\?SuikaWiki/0.9(?:$|\s)!) {  
                   $main::_EMBEDED = 1;  
                   $r = &text_to_html ($content, magic => $cf, page => $name);  
                   $main::_EMBEDED = 0;  
                 } elsif (length $content) {  
                   $r = "<pre>@{[SuikWiki::Plugin->escape ($content)]}</pre>";  
                 } else {  
                   $r = &text_to_html ("[INS[\n[[$name]]: @{[SuikaWiki::Plugin->resource('Embed:PageNotFound')]}\n]INS]\n", magic => '#?SuikaWiki/0.9');  
                 }  
               } else {  ## nested #EMBED  
                 $r = &text_to_html ("[INS[\n[[$name]]: @{[SuikaWiki::Plugin->resource('Embed:Nested',escape=>1)]}\n]INS]\n", magic => '#?SuikaWiki/0.9');  
               }  
               return qq(<blockquote title="@{[SuikaWiki::Plugin->escape($name)]}" class="wiki-embed">$r<div class="cite-note">¡Ø<cite><a href="@{[SuikaWiki::Plugin->uri ('wiki') . SuikaWiki::Plugin->encode($name)]}" class="wiki">@{[SuikaWiki::Plugin->escape($name)]}</a></cite>¡Ù</div></blockquote>);  
             }  
           } else {  
             return $embedded;  
           }  
   
1910  FormattingRule:  FormattingRule:
1911    @Category[list]: page-link    @Category[list]:
1912        page-link
1913        link-to-resource
1914    @Name: sw09--link-anchor-content    @Name: sw09--link-anchor-content
1915    @Description:    @Description:
1916      @@@:      @@@:
# Line 1292  FormattingRule: Line 1920  FormattingRule:
1920      if ($o->{var}->{sw09__anchor_content}) {      if ($o->{var}->{sw09__anchor_content}) {
1921        $o->{var}->{sw09__anchor_content}->($p->{-parent});        $o->{var}->{sw09__anchor_content}->($p->{-parent});
1922      } else {      } else {
1923        $p->{-parent}->append_node (SuikaWiki::Plugin->resource        $WIKIRESOURCE->append_tree
1924                        ('Link:SuikaWiki/0.9:link-anchor-content:InvalidContext'),              (name => 'Link:SuikaWiki/0.9:link-anchor-content:InvalidContext',
1925                                    node_or_text => 1);               param => $o,
1926                 -parent => $p->{-parent},
1927                 wiki => $o->{wiki});
1928      }      }
1929    
1930  Resource:  Resource:
1931    @Link:SuikaWiki/0.9:link-anchor-content:InvalidContext:    @Link:SuikaWiki/0.9:link-anchor-content:InvalidContext:
1932      @@@: %sw09--link-anchor-content; cannot be used in this context.      @@@: %percent;sw09--link-anchor-content; cannot be used in this context.
1933        @@lang:en
1934      @Link:SuikaWiki/0.9:toResource:SourceLabel:
1935        @@@:
1936          %select_link_resource_scheme (
1937            URI => {<%link-to-it(
1938              label=>{%link-resource-parameters;}p,
1939            );>},
1940            IW => {%iw--source-label (default => {<%link-to-it (
1941              label => {%link-resource-scheme;:%link-resource-parameters;}p,
1942            );});},
1943            MAIL => {<%link-to-it(
1944              label => {%link-resource-parameters;}p,
1945              description
1946                => {%res (name=>{Link:MailAddress=});<%link-resource-parameters;>}p,
1947            );>},
1948            otherwise => {<%link-to-it(
1949              label => {%sw09--link-anchor-content;}p,
1950              description => {%res (name=>{Link:URIReference=});<%uri-reference;>}p,
1951            );>},
1952          );
1953      @@lang:en      @@lang:en
1954    @Link:SuikaWiki/0.9:toWikiPage:SourceLabel:    @Link:SuikaWiki/0.9:toWikiPage:SourceLabel:
1955      @@@:      @@@:
# Line 1314  Resource: Line 1964  Resource:
1964          );}p,          );}p,
1965          class=>{%if-linked-wikipage-exist(false=>{not-exist});}p,          class=>{%if-linked-wikipage-exist(false=>{not-exist});}p,
1966        );        );
1967      @SuikaWiki/0.9:form:comment:input:
1968          %line (content => {%textarea (id=>msg,size=>20,lines=>3);}p);
1969          %line (content => {
1970            (%text (description => {%res (name => {Form:Description:HumanName});}p,
1971                    id => name, size => 6);
1972             [%text (description =>
1973                       {%res (name => {Form:Description:MailAddress});}p,
1974                     id => mail, size => 5);]
1975             %check (default, id => record-date,
1976                     label => {%res (name => {Form:Label:LogDate});}p,
1977                     description => {%res (name => {Form:Description:LogDate});}p);)
1978             %submit (label => {%res (name => {Form:Label:Add});}p,
1979                      description => {%res (name => {Form:Description:Add});}p);
1980             %we--update-lastmodified-datetime;
1981          }p);
1982      @SuikaWiki/0.9:form:comment:template:
1983        %n
1984       ;[%index;]%n
1985       ;%text(source=>msg);%n;(%name;%text(source=>mail,prefix=>" [",suffix=>"]");%iif(source=>record-date,true=>" [WEAK[%date;]]");)%n;
1986      @SuikaWiki/0.9:form:comment:option:
1987        %require (msg);
1988      @SuikaWiki/0.9:form:footannotate:input:
1989          %line (content => {%textarea (id=>msg,size=>20,lines=>3);}p);
1990          %line (content => {
1991            (%text (description => {%res (name => {Form:Description:HumanName});}p,
1992                    id => name, size => 6);
1993             [%text (description =>
1994                       {%res (name => {Form:Description:MailAddress});}p,
1995                     id => mail, size => 5);]
1996             %check (default, id => record-date,
1997                     label => {%res (name => {Form:Label:LogDate});}p,
1998                     description => {%res (name => {Form:Description:LogDate});}p);)
1999             %submit (label => {%res (name => {Form:Label:Add});}p,
2000                      description => {%res (name => {Form:Description:Add});}p);
2001             %we--update-lastmodified-datetime;
2002          }p);
2003      @SuikaWiki/0.9:form:footannotate:template:
2004         %n
2005        ;[%index;]%n
2006        ;%text(source=>msg);%n
2007        ;(%name;%text(source=>mail,prefix=>" [",suffix=>"]");%iif(source=>record-date,true=>" [WEAK[%date;]]");)%n;
2008      @SuikaWiki/0.9:form:footannotate:option:
2009        %require (msg);
2010      @WikiFormat:MediaType:Description:IMT:text/x-suikawiki;version="0.9"##:
2011        @@@: SuikaWiki/0.9 (text format), as used in SuikaWiki 2
2012        @@lang: en
2013      @WikiFormat:MediaType:Description:IMT:text/x-suikawiki;version="0.10"##:
2014        @@@: SuikaWiki/0.10 (text format)
2015        @@lang: en
2016      @WikiFormat:MediaType:Label:IMT:text/x-suikawiki;version="0.9"##:
2017        @@@: SuikaWiki/0.9 (text)
2018        @@lang: en
2019      @WikiFormat:MediaType:Label:IMT:text/x-suikawiki;version="0.10"##:
2020        @@@: SuikaWiki/0.10 (text)
2021        @@lang: en
2022      @WikiFormat:MediaType:Description:MAGIC:SuikaWiki/0.9##:
2023        @@@: SuikaWiki/0.9 (text format), as used in SuikaWiki 2
2024        @@lang: en
2025      @WikiFormat:MediaType:Description:MAGIC:SuikaWiki/0.10##:
2026        @@@: SuikaWiki/0.10 (text format)
2027        @@lang: en
2028      @WikiFormat:MediaType:Label:MAGIC:SuikaWiki/0.9##:
2029        @@@: SuikaWiki/0.9 (text format)
2030        @@lang: en
2031      @WikiFormat:MediaType:Label:MAGIC:SuikaWiki/0.10##:
2032        @@@: SuikaWiki/0.10 (text)
2033        @@lang: en
2034    
2035    
2036    Error:
2037      @Name: text_parse
2038      @Definition:
2039        @@INLINE_NO_CLOSE_TAG:
2040          @@@description:
2041            Close tag of element "%t (name => element_type);" not found.
2042          @@@level: non-fatal
2043        @@BLOCK_NO_CLOSE_TAG:
2044          @@@description:
2045            Close tag of element "%t (name => element_type);" not found.
2046          @@@level: non-fatal
2047        @@INVALID_FORM:
2048          @@@description:
2049            Invalid syntax of WikiForm
2050          @@@level: non-fatal
2051        
2052    Error:
2053      @Name: xml_to_text
2054      @IsA[list]:
2055        ::SuikaWiki::Format::
2056      @Definition:
2057        @@

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.19

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24