/[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.5 by wakaba, Sun Feb 1 12:11:28 2004 UTC revision 1.6 by wakaba, Sun Feb 8 08:49:05 2004 UTC
# Line 102  Format: Line 102  Format:
102                                              wiki => $self->{wiki});                                              wiki => $self->{wiki});
103    
104      ## SuikaWiki/0.9 -> XHTML 1      ## SuikaWiki/0.9 -> XHTML 1
105          __FUNCPACK__->sw09_to_xhtml1 (source => $xml, parent => $opt->{-parent},
106                                        o => $opt->{o}, page => $opt->{page});
107    
108          if ($opt->{-with_annotation_input}) {
109            SuikaWiki::Plugin->module_package ('WikiFormCore')
110                             ->make_content_form_in_html
111                                 ($opt->{-parent},
112                                  $WIKIRESOURCE->get
113                                    (name => 'SuikaWiki/0.9:form:footannotate:input',
114                                     o => $opt->{o}, wiki => $opt->{o}->{wiki}),
115                                  option => $WIKIRESOURCE->get
116                                    (name => 'SuikaWiki/0.9:form:footannotate:option',
117                                     o => $opt->{o}, wiki => $opt->{o}->{wiki}),
118                                  o => $opt->{o},
119                                  wiki => $opt->{o}->{wiki},
120                                  output => {
121                                    page => $opt->{page},
122                                  });
123          }
124    
125    
126      @Converter:
127        @@Type:
128          @@@@: application/x-suikawiki+xml
129          @@@version: 0.9
130        @@Description:
131          @@@@: Converting SuikaWiki/0.9 text format to XML format
132          @@@lang: en
133        @@Main:
134          my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => $opt,
135                                                wiki => $self->{wiki});
136    ## TODO: Make a clone
137          $opt->{-parent}->append_node ($xml);
138    
139      @NextIndex:
140        @@Name: anchor
141        @@Main:
142          my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => \%opt,
143                                                wiki => $self->{wiki});
144          (__FUNCPACK__->get_last_anchor_index ($xml)) + 1;
145      
146      @WikiForm:
147        @@Main:
148          ## Text format -> XML format
149          my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => \%opt,
150                                                wiki => $self->{wiki});
151          local $opt{o}->{var}->{sw09__anchor_index};
152          local $opt{o}->{var}->{sw09__document_tree} = $xml;
153    
154          my $form;
155          if ($opt{o}->{form}->{output}->{id}) {
156            $form = __FUNCPACK__->get_element_by_id
157                      ($xml, $opt{o}->{form}->{output}->{id});
158            undef $form unless ref $form and
159                               $form->namespace_uri eq $NS_SW09 and
160                               $form->local_name eq 'form';
161          } else {
162            $form = __FUNCPACK__->get_nth_element
163                      ($xml, $NS_SW09 => 'form',
164                       $opt{o}->{form}->{output}->{index});
165          }
166          
167          my $ref;
168          if (ref $form) {
169            $ref = $form->get_attribute_value ('ref', default => 'form');
170          } else {
171            $ref = '#footannotate';
172          }
173          
174          
175          ## WikiForm Option
176          if ($ref eq 'form') {
177            $opt{option} ||= $form->get_attribute_value ('option');
178          } elsif ($ref eq 'comment') {
179            $opt{option} ||= $WIKIRESOURCE->get
180                               (name => 'SuikaWiki/0.9:form:comment:option',
181                                o => $opt{o}, wiki => $opt{o}->{wiki});
182          } elsif ($ref eq '#footannotate') {
183            $opt{option} ||= $WIKIRESOURCE->get
184                               (name => 'SuikaWiki/0.9:form:footannotate:option',
185                                o => $opt{o}, wiki => $opt{o}->{wiki});
186          } else {
187    ## TODO:
188          }
189          SuikaWiki::Plugin->module_package ('WikiFormCore')
190                           ->set_option ($opt{option} => $opt{o}) if $opt{option};
191          
192          ## Replace Output Template
193          my $result;
194          if ($ref eq 'form') {
195            $opt{template} ||= $form->get_attribute_value
196                                        ('template', default => '');
197          } elsif ($ref eq 'comment') {
198            $opt{template} ||= $WIKIRESOURCE->get
199                                 (name => 'SuikaWiki/0.9:form:comment:template',
200                                  o => $opt{o}, wiki => $opt{o}->{wiki});
201          } elsif ($ref eq '#footannotate') {
202            $opt{template} ||= $WIKIRESOURCE->get
203                                 (name => 'SuikaWiki/0.9:form:footannotate:template',
204                                  o => $opt{o}, wiki => $opt{o}->{wiki});
205          }
206          try {
207            $result = SuikaWiki::Plugin->text_formatter ('form_template')
208                             ->replace ($opt{template}, param => $opt{o});
209          } catch Message::Util::Formatter::error with {
210            my $err = shift;
211            SuikaWiki::Plugin->module_package ('Error')
212                             ->reporting_formatting_template_error
213                                 ($err, $err->{option}->{param}->{wiki});
214    ##TODO:
215            throw SuikaWiki::View::Implementation::error -type => 'ERROR_REPORTED';
216          };      
217    
218          ## Insert
219          if (length $result) {
220            if ($ref eq '#footannotate') {
221              my $parent;
222              for (@{$xml->child_nodes}) {
223                if ($_->node_type eq '#element' and
224                    $_->local_name eq 'document') {
225                  for (@{$_->child_nodes}) {
226                    if ($_->node_type eq '#element' and
227                        $_->local_name eq 'body') {
228                      $parent = $_;
229                      last;
230                    }
231                  }
232                }
233              }
234              CORE::die "Buggy implementation: no body element".$xml unless ref $parent;
235              
236              $parent->append_new_node (type => '#element',
237                                        namespace_uri => $NS_SW09,
238                                        local_name => 'text')
239                     ->append_text ($result);
240            } else {
241              my $parent = $form->parent_node;
242              CORE::die "Byggy implementation: No parent of form" unless ref $parent;
243              my $children = $parent->child_nodes;
244              
245              $result .= "\x0A" unless substr ($result, -1) eq "\x0A";
246              $parent->append_new_node (type => '#element',
247                                        namespace_uri => $NS_SW09,
248                                        local_name => 'text')
249                     ->append_text ($result);
250              my $node = pop @{$children};
251              my $form_str = overload::StrVal ($form);
252              my $i = 0;
253              for (@{$children}) {
254                last if overload::StrVal ($_) eq $form_str;
255                $i++;
256              }
257              if ($opt{o}->{form}->{output}->{reverse}) {
258                splice @{$children}, $i + 1, 0, $node;
259              } else {
260                splice @{$children}, $i, 0, $node;
261              }
262            }
263          } else {
264    ## TODO:
265          }
266    
267          ## XML format -> Text format
268          my $text = __FUNCPACK__->xml_to_text ($xml, {%opt});
269    
270          my %fragment = (fragment => $opt{o}->{form}->{output}->{id}
271                                || 'wikiform-'.$opt{o}->{form}->{output}->{index});
272          if (not $opt{o}->{form}->{output}->{reverse} and
273              $opt{o}->{var}->{sw09__anchor_index}) {
274            %fragment = (anchor_no => $opt{o}->{var}->{sw09__anchor_index});
275          }
276    
277          my $action = [
278            {
279              type => 'write',
280              content => $text,
281              update_lastmodified => time,
282            },
283            {
284              type => 'view',
285              %fragment,
286            },
287          ];
288    
289      @HeadSummary:
290        @@Main:
291          my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => \%opt,
292                                                wiki => $self->{wiki});
293          return $xml->inner_text;
294    
295    FormattingRule:
296      @Category[list]:form-template
297      @Name: index
298      @Description:
299        @@@: Next anchor index number
300        @@lang:en
301      @After:
302        if ($o->{var}->{sw09__anchor_index}) {
303          ++$o->{var}->{sw09__anchor_index};
304        } else {
305          $o->{var}->{sw09__anchor_index}
306            = 1 + __FUNCPACK__->get_last_anchor_index
307                                  ($o->{var}->{sw09__document_tree});
308        }
309        $p->{-result} .= $o->{var}->{sw09__anchor_index};
310    
311    Function:
312      @Name: get_last_anchor_index
313      @Main:
314          my (undef, $xml) = @_;
315          my $anchor = 0;
316          my $get_anchor_no;
317          $get_anchor_no = sub {
318            my $node = shift;
319            for my $child (@{$node->child_nodes}) {
320              if ($child->node_type eq '#element') {
321                if ($child->namespace_uri => $NS_SW09 and
322                    $child->local_name eq 'anchor-end') {
323                  my $a = $child->get_attribute_value ('anchor', default => 0,
324                                                       namespace_uri => $NS_SW09);
325                  $anchor = 0+$a if $anchor < 0+$a;
326                } else {
327                  $get_anchor_no->($child);
328                }
329              } elsif ($child->node_type eq '#document' or
330                       $child->node_type eq '#fragment') {
331                $get_anchor_no->($child);
332              }
333            }
334          };
335          $get_anchor_no->($xml);
336          $anchor;
337    
338    
339    Function:
340      @Name: get_xml_tree
341      @Main:
342        my (undef, %opt) = @_;
343        if ($opt{opt}->{page}) {
344          unless ($__FUNCPACK__::DBLoaded) {
345            $opt{wiki}->{db}->_set_prop_db (sw09__xml_tree => {-db_open => sub {
346              require SuikaWiki::DB::Hash;
347              new SuikaWiki::DB::Hash;
348            }});
349            $__FUNCPACK__::DBLoaded++;
350          }
351        
352          my $xml = new Message::Markup::XML::Node type => '#fragment';
353          __FUNCPACK__->text_to_xml (${$opt{text}}, {%{$opt{opt}}, -parent => $xml});
354    
355          $opt{wiki}->{db}->set (sw09__xml_tree => $opt{opt}->{page} => $xml);
356          $xml;
357        } else {
358          my $xml = new Message::Markup::XML::Node type => '#fragment';
359          __FUNCPACK__->text_to_xml (${$opt{text}}, {%{$opt{opt}}, -parent => $xml});
360          $xml;
361        }
362    
363    Function:
364      @Name: sw09_to_xhtml1
365      @Main:
366        my (undef, %opt) = @_;
367    
368        my ($apply_template, $apply_template_children);        my ($apply_template, $apply_template_children);
369        $apply_template_children = sub {        $apply_template_children = sub {
370          my ($parent, $result) = @_;          my ($parent, $result) = @_;
# Line 147  Format: Line 410  Format:
410            }            }
411            $apply_template_children->($source => $node);            $apply_template_children->($source => $node);
412          } elsif ($ln eq 'anchor') {          } elsif ($ln eq 'anchor') {
413            local $opt->{o}->{var}->{sw09__anchor_content} = sub {            local $opt{o}->{var}->{sw09__anchor_content} = sub {
414              $apply_template_children->($source => shift);              $apply_template_children->($source => shift);
415            };            };
416            SuikaWiki::Plugin->module_package ('WikiLinking')            SuikaWiki::Plugin->module_package ('WikiLinking')
# Line 156  Format: Line 419  Format:
419                               ->get_text                               ->get_text
420                                   (name =>                                   (name =>
421                                      'Link:SuikaWiki/0.9:toWikiPage:SourceLabel',                                      'Link:SuikaWiki/0.9:toWikiPage:SourceLabel',
422                                    param => $opt->{o},                                    param => $opt{o},
423                                    wiki => $opt->{o}->{wiki}),                                    wiki => $opt{o}->{wiki}),
424            } => {            } => {
425      ## TODO:              base                => $opt{o}->{wiki}->{var}->{page},
426              page_name_relative  => [split m#//#, $source->inner_text],              page_name_relative  => $opt{o}->{wiki}->name ($source->inner_text),
427              page_anchor_no      => $source->get_attribute_value              page_anchor_no      => $source->get_attribute_value
428                                       ('anchor',                                       ('anchor',
429                                        namespace_uri => $NS_SW09),                                        namespace_uri => $NS_SW09),
430            }, {            }, {
431              o => $opt->{o},              o => $opt{o},
432              parent => $result,              parent => $result,
433            });            });
434          } elsif ($ln eq 'p') {          } elsif ($ln eq 'p') {
# Line 175  Format: Line 438  Format:
438                                                     local_name => 'p'));                                                     local_name => 'p'));
439          } elsif ($ln eq 'h') {          } elsif ($ln eq 'h') {
440            my $node;            my $node;
441            if ($opt->{o}->{var}->{ws__section_depth} > 6) {            if ($opt{o}->{var}->{ws__section_depth} > 6) {
442              $node = $result->append_new_node              $node = $result->append_new_node
443                                  (type => '#element',                                  (type => '#element',
444                                   namespace_uri => $NS_XHTML1,                                   namespace_uri => $NS_XHTML1,
445                                   local_name => 'div');                                   local_name => 'div');
446              $node->set_attribute (class => 'heading h'.$opt->{o}->{var}              $node->set_attribute (class => 'heading h'.$opt{o}->{var}
447                                                     ->{ws__section_depth});                                                     ->{ws__section_depth});
448            } else {            } else {
449              $node = $result->append_new_node              $node = $result->append_new_node
450                                  (type => '#element',                                  (type => '#element',
451                                   namespace_uri => $NS_XHTML1,                                   namespace_uri => $NS_XHTML1,
452                                   local_name => 'h'.$opt->{o}->{var}                                   local_name => 'h'.$opt{o}->{var}
453                                                         ->{ws__section_depth});                                                         ->{ws__section_depth});
454            }            }
455            $apply_template_children->($source => $node);            $apply_template_children->($source => $node);
456            SuikaWiki::Plugin->module_package ('WikiStruct')            SuikaWiki::Plugin->module_package ('WikiStruct')
457                             ->set_section_id ($result, undef, $opt->{o}->{wiki},                             ->set_section_id ($result, undef, $opt{o}->{wiki},
458                                               title => $source->inner_text);                                               title => $source->inner_text);
459          } elsif ($ln eq 'ruby' or $ln eq 'rubyb') {          } elsif ($ln eq 'ruby' or $ln eq 'rubyb') {
460            my @child;            my @child;
# Line 277  Format: Line 540  Format:
540                                   namespace_uri => $NS_XHTML1,                                   namespace_uri => $NS_XHTML1,
541                                   local_name => 'div');                                   local_name => 'div');
542            $node->set_attribute (class => $ln);            $node->set_attribute (class => $ln);
543            local $opt->{o}->{var}->{ws__section_depth}            local $opt{o}->{var}->{ws__section_depth}
544                = $opt->{o}->{var}->{ws__section_depth} + 1;                = $opt{o}->{var}->{ws__section_depth} + 1;
545            $apply_template_children->($source => $node);            $apply_template_children->($source => $node);
546          } elsif ($ln eq 'anchor-end') {          } elsif ($ln eq 'anchor-end') {
547            my $node = $result->append_new_node            my $node = $result->append_new_node
# Line 300  Format: Line 563  Format:
563            $node->set_attribute (class => 'wiki-anchor');            $node->set_attribute (class => 'wiki-anchor');
564            $node->append_text ($source->inner_text);            $node->append_text ($source->inner_text);
565          } elsif ($ln eq 'anchor-external') {          } elsif ($ln eq 'anchor-external') {
566            local $opt->{o}->{var}->{sw09__anchor_content} = sub {            local $opt{o}->{var}->{sw09__anchor_content} = sub {
567              $apply_template_children->($source => shift);              $apply_template_children->($source => shift);
568            };            };
569            SuikaWiki::Plugin->module_package ('WikiLinking')            SuikaWiki::Plugin->module_package ('WikiLinking')
# Line 309  Format: Line 572  Format:
572                       label => SuikaWiki::Plugin->module_package ('WikiResource')                       label => SuikaWiki::Plugin->module_package ('WikiResource')
573                                  ->get_text (name =>                                  ->get_text (name =>
574                                     'Link:SuikaWiki/0.9:toResource:SourceLabel',                                     'Link:SuikaWiki/0.9:toResource:SourceLabel',
575                                     param => $opt->{o},                                     param => $opt{o},
576                                     wiki => $opt->{o}->{wiki}),                                     wiki => $opt{o}->{wiki}),
577                      }, {                      }, {
578                        resource_scheme =>                        resource_scheme =>
579                          $source->get_attribute_value ('resScheme',                          $source->get_attribute_value ('resScheme',
# Line 321  Format: Line 584  Format:
584                                                        namespace_uri => $NS_SW09,                                                        namespace_uri => $NS_SW09,
585                                                        default => ''),                                                        default => ''),
586                      }, {                      }, {
587                       o => $opt->{o},                       o => $opt{o},
588                       parent => $result,                       parent => $result,
589                      });                      });
590          } elsif ($ln eq 'form') {          } elsif ($ln eq 'form') {
# Line 335  Format: Line 598  Format:
598                                    option => $source->get_attribute_value                                    option => $source->get_attribute_value
599                                                         ('option'),                                                         ('option'),
600                                    name => $source->get_attribute_value ('id'),                                    name => $source->get_attribute_value ('id'),
601                                    o => $opt->{o},                                    o => $opt{o},
602                                    wiki => $opt->{o}->{wiki},                                    wiki => $opt{o}->{wiki},
603                                    output => {                                    output => {
604                                      page => $opt->{page},                                      page => $opt{page},
605                                    });                                    });
606            } elsif ($ref eq 'comment') {            } elsif ($ref eq 'comment') {
607              SuikaWiki::Plugin->module_package ('WikiFormCore')              SuikaWiki::Plugin->module_package ('WikiFormCore')
# Line 346  Format: Line 609  Format:
609                                   ($result,                                   ($result,
610                                    $WIKIRESOURCE->get                                    $WIKIRESOURCE->get
611                                      (name => 'SuikaWiki/0.9:form:comment:input',                                      (name => 'SuikaWiki/0.9:form:comment:input',
612                                       o => $opt->{o}, wiki => $opt->{o}->{wiki}),                                       o => $opt{o}, wiki => $opt{o}->{wiki}),
613                                    option => $WIKIRESOURCE->get                                    option => $WIKIRESOURCE->get
614                                      (name => 'SuikaWiki/0.9:form:comment:option',                                      (name => 'SuikaWiki/0.9:form:comment:option',
615                                       o => $opt->{o}, wiki => $opt->{o}->{wiki}),                                       o => $opt{o}, wiki => $opt{o}->{wiki}),
616                                    name => $source->get_attribute_value ('id'),                                    name => $source->get_attribute_value ('id'),
617                                    o => $opt->{o},                                    o => $opt{o},
618                                    wiki => $opt->{o}->{wiki},                                    wiki => $opt{o}->{wiki},
619                                    output => {                                    output => {
620                                      page => $opt->{page},                                      page => $opt{page},
621                                    });                                    });
622            } else {            } else {
623   ## TODO:   ## TODO:
# Line 393  Format: Line 656  Format:
656          }          }
657        };        };
658                
659        $apply_template_children->($xml => $opt->{-parent});        $apply_template_children->($opt{source} => $opt{parent});
   
       if ($opt->{-with_annotation_input}) {  
         SuikaWiki::Plugin->module_package ('WikiFormCore')  
                          ->make_content_form_in_html  
                              ($opt->{-parent},  
                               $WIKIRESOURCE->get  
                                 (name => 'SuikaWiki/0.9:form:footannotate:input',  
                                  o => $opt->{o}, wiki => $opt->{o}->{wiki}),  
                               option => $WIKIRESOURCE->get  
                                 (name => 'SuikaWiki/0.9:form:footannotate:option',  
                                  o => $opt->{o}, wiki => $opt->{o}->{wiki}),  
                               o => $opt->{o},  
                               wiki => $opt->{o}->{wiki},  
                               output => {  
                                 page => $opt->{page},  
                               });  
       }  
   
   
   @Converter:  
     @@Type:  
       @@@@: application/x-suikawiki+xml  
       @@@version: 0.9  
     @@Description:  
       @@@@: Converting SuikaWiki/0.9 text format to XML format  
       @@@lang: en  
     @@Main:  
       my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => $opt,  
                                             wiki => $self->{wiki});  
 ## TODO: Make a clone  
       $opt->{-parent}->append_node ($xml);  
   
   @NextIndex:  
     @@Name: anchor  
     @@Main:  
       my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => \%opt,  
                                             wiki => $self->{wiki});  
       (__FUNCPACK__->get_last_anchor_index ($xml)) + 1;  
     
   @WikiForm:  
     @@Main:  
       ## Text format -> XML format  
       my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => \%opt,  
                                             wiki => $self->{wiki});  
       local $opt{o}->{var}->{sw09__anchor_index};  
       local $opt{o}->{var}->{sw09__document_tree} = $xml;  
   
       my $form;  
       if ($opt{o}->{form}->{output}->{id}) {  
         $form = __FUNCPACK__->get_element_by_id  
                   ($xml, $opt{o}->{form}->{output}->{id});  
         undef $form unless ref $form and  
                            $form->namespace_uri eq $NS_SW09 and  
                            $form->local_name eq 'form';  
       } else {  
         $form = __FUNCPACK__->get_nth_element  
                   ($xml, $NS_SW09 => 'form',  
                    $opt{o}->{form}->{output}->{index});  
       }  
         
       my $ref;  
       if (ref $form) {  
         $ref = $form->get_attribute_value ('ref', default => 'form');  
       } else {  
         $ref = '#footannotate';  
       }  
         
         
       ## WikiForm Option  
       if ($ref eq 'form') {  
         $opt{option} ||= $form->get_attribute_value ('option');  
       } elsif ($ref eq 'comment') {  
         $opt{option} ||= $WIKIRESOURCE->get  
                            (name => 'SuikaWiki/0.9:form:comment:option',  
                             o => $opt{o}, wiki => $opt{o}->{wiki});  
       } elsif ($ref eq '#footannotate') {  
         $opt{option} ||= $WIKIRESOURCE->get  
                            (name => 'SuikaWiki/0.9:form:footannotate:option',  
                             o => $opt{o}, wiki => $opt{o}->{wiki});  
       } else {  
 ## TODO:  
       }  
       SuikaWiki::Plugin->module_package ('WikiFormCore')  
                        ->set_option ($opt{option} => $opt{o}) if $opt{option};  
         
       ## Replace Output Template  
       my $result;  
       if ($ref eq 'form') {  
         $opt{template} ||= $form->get_attribute_value  
                                     ('template', default => '');  
       } elsif ($ref eq 'comment') {  
         $opt{template} ||= $WIKIRESOURCE->get  
                              (name => 'SuikaWiki/0.9:form:comment:template',  
                               o => $opt{o}, wiki => $opt{o}->{wiki});  
       } elsif ($ref eq '#footannotate') {  
         $opt{template} ||= $WIKIRESOURCE->get  
                              (name => 'SuikaWiki/0.9:form:footannotate:template',  
                               o => $opt{o}, wiki => $opt{o}->{wiki});  
       }  
       try {  
         $result = SuikaWiki::Plugin->text_formatter ('form_template')  
                          ->replace ($opt{template}, param => $opt{o});  
       } catch Message::Util::Formatter::error with {  
         my $err = shift;  
         SuikaWiki::Plugin->module_package ('Error')  
                          ->reporting_formatting_template_error  
                              ($err, $err->{option}->{param}->{wiki});  
 ##TODO:  
         throw SuikaWiki::View::Implementation::error -type => 'ERROR_REPORTED';  
       };        
   
       ## Insert  
       if (length $result) {  
         if ($ref eq '#footannotate') {  
           my $parent;  
           for (@{$xml->child_nodes}) {  
             if ($_->node_type eq '#element' and  
                 $_->local_name eq 'document') {  
               for (@{$_->child_nodes}) {  
                 if ($_->node_type eq '#element' and  
                     $_->local_name eq 'body') {  
                   $parent = $_;  
                   last;  
                 }  
               }  
             }  
           }  
           CORE::die "Buggy implementation: no body element".$xml unless ref $parent;  
             
           $parent->append_new_node (type => '#element',  
                                     namespace_uri => $NS_SW09,  
                                     local_name => 'text')  
                  ->append_text ($result);  
         } else {  
           my $parent = $form->parent_node;  
           CORE::die "Byggy implementation: No parent of form" unless ref $parent;  
           my $children = $parent->child_nodes;  
             
           $result .= "\x0A" unless substr ($result, -1) eq "\x0A";  
           $parent->append_new_node (type => '#element',  
                                     namespace_uri => $NS_SW09,  
                                     local_name => 'text')  
                  ->append_text ($result);  
           my $node = pop @{$children};  
           my $form_str = overload::StrVal ($form);  
           my $i = 0;  
           for (@{$children}) {  
             last if overload::StrVal ($_) eq $form_str;  
             $i++;  
           }  
           if ($opt{o}->{form}->{output}->{reverse}) {  
             splice @{$children}, $i + 1, 0, $node;  
           } else {  
             splice @{$children}, $i, 0, $node;  
           }  
         }  
       } else {  
 ## TODO:  
       }  
   
       ## XML format -> Text format  
       my $text = __FUNCPACK__->xml_to_text ($xml, {%opt});  
   
       my %fragment = (fragment => $opt{o}->{form}->{output}->{id}  
                             || 'wikiform-'.$opt{o}->{form}->{output}->{index});  
       if (not $opt{o}->{form}->{output}->{reverse} and  
           $opt{o}->{var}->{sw09__anchor_index}) {  
         %fragment = (anchor_no => $opt{o}->{var}->{sw09__anchor_index});  
       }  
   
       my $action = [  
         {  
           type => 'write',  
           content => $text,  
           update_lastmodified => time,  
         },  
         {  
           type => 'view',  
           %fragment,  
         },  
       ];  
   
   @HeadSummary:  
     @@Main:  
       my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => \%opt,  
                                             wiki => $self->{wiki});  
       return $xml->inner_text;  
   
 FormattingRule:  
   @Category[list]:form-template  
   @Name: index  
   @Description:  
     @@@: Next anchor index number  
     @@lang:en  
   @After:  
     if ($o->{var}->{sw09__anchor_index}) {  
       ++$o->{var}->{sw09__anchor_index};  
     } else {  
       $o->{var}->{sw09__anchor_index}  
         = 1 + __FUNCPACK__->get_last_anchor_index  
                               ($o->{var}->{sw09__document_tree});  
     }  
     $p->{-result} .= $o->{var}->{sw09__anchor_index};  
   
 Function:  
   @Name: get_last_anchor_index  
   @Main:  
       my (undef, $xml) = @_;  
       my $anchor = 0;  
       my $get_anchor_no;  
       $get_anchor_no = sub {  
         my $node = shift;  
         for my $child (@{$node->child_nodes}) {  
           if ($child->node_type eq '#element') {  
             if ($child->namespace_uri => $NS_SW09 and  
                 $child->local_name eq 'anchor-end') {  
               my $a = $child->get_attribute_value ('anchor', default => 0,  
                                                    namespace_uri => $NS_SW09);  
               $anchor = 0+$a if $anchor < 0+$a;  
             } else {  
               $get_anchor_no->($child);  
             }  
           } elsif ($child->node_type eq '#document' or  
                    $child->node_type eq '#fragment') {  
             $get_anchor_no->($child);  
           }  
         }  
       };  
       $get_anchor_no->($xml);  
       $anchor;  
   
   
 Function:  
   @Name: get_xml_tree  
   @Main:  
     my (undef, %opt) = @_;  
     if ($opt{opt}->{page}) {  
       unless ($__FUNCPACK__::DBLoaded) {  
         $opt{wiki}->{db}->_set_prop_db (sw09__xml_tree => {-db_open => sub {  
           require SuikaWiki::DB::Hash;  
           new SuikaWiki::DB::Hash;  
         }});  
         $__FUNCPACK__::DBLoaded++;  
       }  
       
       my $xml = new Message::Markup::XML::Node type => '#fragment';  
       __FUNCPACK__->text_to_xml (${$opt{text}}, {%{$opt{opt}}, -parent => $xml});  
   
       $opt{wiki}->{db}->set (sw09__xml_tree => $opt{opt}->{page} => $xml);  
       $xml;  
     } else {  
       my $xml = new Message::Markup::XML::Node type => '#fragment';  
       __FUNCPACK__->text_to_xml (${$opt{text}}, {%{$opt{opt}}, -parent => $xml});  
       $xml;  
     }  
660    
661    
662  Function:  Function:
# Line 790  Function: Line 798  Function:
798            },            },
799            document => sub {            document => sub {
800              my $source = shift;              my $source = shift;
801              my $result = '';              my $result = '#?'
802                           . $source->get_attribute_value
803                                        ('Name', namespace_uri => $NS_SW09,
804                                         default => 'SuikaWiki')
805                           . '/'
806                           . $source->get_attribute_value
807                                        ('Version', namespace_uri => $NS_SW09,
808                                         default => '0.9');
809              for (@{$source->child_nodes}) {              for (@{$source->child_nodes}) {
810                $result .= ($x2t{$_->local_name} or $x2t{'#undef'})->($_)                $result .= ($x2t{$_->local_name} or $x2t{'#undef'})->($_)
811                  if $_->node_type eq '#element';                  if $_->node_type eq '#element';
# Line 799  Function: Line 814  Function:
814            },            },
815            head => sub {            head => sub {
816              my $source = shift;              my $source = shift;
817              my $result = '#?SuikaWiki/0.9';              my $result = '';
818              for (@{$source->child_nodes}) {              for (@{$source->child_nodes}) {
819                if ($_->node_type eq '#element' and                if ($_->node_type eq '#element' and
820                    $_->local_name eq 'parameter') {                    $_->local_name eq 'parameter') {
# Line 934  Function: Line 949  Function:
949              }              }
950              $result;              $result;
951            },            },
952              ## Note: This element will be interpreted as a paragraph
953              ##       unless format is SuikaWikiImage/0.9.
954              image => sub {
955                my ($source, %opt) = @_;
956                return "\x0A__IMAGE__\x0A" . $source->inner_text . "\x0A";
957              },
958            '#block' => sub {            '#block' => sub {
959              my ($source, %opt) = @_;              my ($source, %opt) = @_;
960              my @result;              my @result;
# Line 1186  Function: Line 1207  Function:
1207      my $head = $root->append_new_node (type => '#element',      my $head = $root->append_new_node (type => '#element',
1208                                         namespace_uri => $NS_XHTML2,                                         namespace_uri => $NS_XHTML2,
1209                                         local_name => 'head');                                         local_name => 'head');
1210      if ($source =~ s#^\#\?SuikaWiki/0\.9\b((?>.*))\s*##) {      $root->append_text ("\x0A");
1211        my $param = $1;      my $body = $root->append_new_node (type => '#element',
1212                                           namespace_uri => $NS_XHTML2,
1213                                           local_name => 'body');
1214        $root->append_text ("\x0A");
1215    
1216        if ($source =~ s#^\#\?(SuikaWiki(?:Image)?)/0\.9\b((?>.*))\s*##) {
1217          my $type = $1;
1218          my $param = $2;
1219          $root->set_attribute (Name => $type, namespace_uri => $NS_SW09);
1220          $root->set_attribute (Version => '0.9', namespace_uri => $NS_SW09);
1221        while ($param =~ /\G\s+([a-z-]+)="((?>[^"\\]*)(?>(?>[^"\\]+|\\.)*))"/g) {        while ($param =~ /\G\s+([a-z-]+)="((?>[^"\\]*)(?>(?>[^"\\]+|\\.)*))"/g) {
1222          my ($name, $value) = ($1, $2);          my ($name, $value) = ($1, $2);
1223          $value =~ s/\\(.)/$1/g;          $value =~ s/\\(.)/$1/g;
# Line 1204  Function: Line 1234  Function:
1234          }          }
1235          $head->append_text ("\x0A");          $head->append_text ("\x0A");
1236        }        }
1237          
1238          if ($type eq 'SuikaWikiImage') {
1239            $source =~ s/\x0A__IMAGE__\x0A(.*)$//s;
1240            if (my $image = $1) {
1241              $image =~ s/^\s+//;
1242              $image =~ s/\s+$//;
1243              $root->append_new_node
1244                       (type => '#element',
1245                        namespace_uri => $NS_SW09,
1246                        local_name => 'image')
1247                   ->append_text ($image);
1248              $root->append_text ("\x0A");
1249            }
1250          }
1251      } else {      } else {
1252          $root->set_attribute (Name => 'SuikaWiki', namespace_uri => $NS_SW09);
1253          $root->set_attribute (Version => '0.9', namespace_uri => $NS_SW09);
1254        ## TODO: warn        ## TODO: warn
1255      }      }
     $root->append_text ("\x0A");  
1256            
     my $body = $root->append_new_node (type => '#element',  
                                        namespace_uri => $NS_XHTML2,  
                                        local_name => 'body');  
1257      __FUNCPACK__->block_text_to_xml (\$source => $body, opt => $opt);      __FUNCPACK__->block_text_to_xml (\$source => $body, opt => $opt);
1258    
1259  Function:  Function:

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24