/[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.3 by wakaba, Fri Dec 26 06:55:35 2003 UTC revision 1.4 by wakaba, Fri Jan 16 07:58:28 2004 UTC
# Line 14  Plugin: Line 14  Plugin:
14      @@Mail[list]: [email protected]      @@Mail[list]: [email protected]
15    @Date.RCS: $Date$    @Date.RCS: $Date$
16    @RequiredPlugin[list]:    @RequiredPlugin[list]:
17        Edit
18        WikiFormCore
19      WikiLinking      WikiLinking
20        WikiStruct
21    @Use:    @Use:
22      use Message::Markup::XML::QName qw/NS_xml_URI/;      use Message::Markup::XML::QName qw/NS_xml_URI/;
23      my $Reg_Form_Content_M = qr{      my $Reg_Form_Content_M = qr{
# Line 80  Format: Line 83  Format:
83        
84    @Use:    @Use:
85      use Message::Markup::XML::QName qw/NS_xml_URI/;      use Message::Markup::XML::QName qw/NS_xml_URI/;
86        use Message::Util::Error;
87    
88    @Converter:    @Converter:
89      @@Type: text/html      @@Type: text/html
# Line 88  Format: Line 92  Format:
92        @@@@: Converting SuikaWiki/0.9 to Hypertext Markup Language fragment        @@@@: Converting SuikaWiki/0.9 to Hypertext Markup Language fragment
93        @@@lang:en        @@@lang:en
94      @@Main:      @@Main:
95  #      __FUNCPACK__->to_html ($source, %$opt);        $opt->{o}->{wiki} ||= $self->{wiki};
     ## Text format -> XML format  
       my $xml = new Message::Markup::XML::Node type => '#fragment';  
       __FUNCPACK__->text_to_xml ($source, {%$opt, -parent => $xml});  
96                
97        ## Text format -> XML format
98          my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => $opt,
99                                                wiki => $self->{wiki});
100    
101        ## SuikaWiki/0.9 -> XHTML 1
102        my ($apply_template, $apply_template_children);        my ($apply_template, $apply_template_children);
103        $apply_template_children = sub {        $apply_template_children = sub {
104          my ($parent, $result) = @_;          my ($parent, $result) = @_;
# Line 113  Format: Line 119  Format:
119            my $class = $source->get_attribute_value ('class', default => '');            my $class = $source->get_attribute_value ('class', default => '');
120            $node->set_attribute (class => $class) if $class;            $node->set_attribute (class => $class) if $class;
121            $apply_template_children->($source => $node);            $apply_template_children->($source => $node);
122          } elsif ({qw/ins 1 del 1/}->{$ln}) {          } elsif ({qw/ins 1 del 1 insert 1 delete 1/}->{$ln}) {
123            my $node = $result->append_new_node            my $node = $result->append_new_node
124                                  (type => '#element',                                  (type => '#element',
125                                   namespace_uri => $NS_XHTML1,                                   namespace_uri => $NS_XHTML1,
126                                   local_name => $ln);                                   local_name => {qw/ins ins insert ins
127                                                       delete del del del/}->{$ln});
128            my $class = $source->get_attribute_value ('class', default => '');            my $class = $source->get_attribute_value ('class', default => '');
129            $node->set_attribute (class => $class) if $class;            $node->set_attribute (class => $class) if $class;
130            ## TODO: cite            ## TODO: cite
# Line 142  Format: Line 149  Format:
149            };            };
150            SuikaWiki::Plugin->module_package ('WikiLinking')            SuikaWiki::Plugin->module_package ('WikiLinking')
151                             ->to_wikipage_in_html ({                             ->to_wikipage_in_html ({
152              label       => SuikaWiki::Plugin->resource              label       => SuikaWiki::Plugin->module_package ('WikiResource')
153                               ('Link:SuikaWiki/0.9:toWikiPage:SourceLabel'),                               ->get_text
154                                     (name =>
155                                        'Link:SuikaWiki/0.9:toWikiPage:SourceLabel',
156                                      param => $opt->{o},
157                                      wiki => $opt->{o}->{wiki}),
158            } => {            } => {
159      ## TODO:      ## TODO:
160              page_name_relative  => [split m#//#, $source->inner_text],              page_name_relative  => [split m#//#, $source->inner_text],
161              page_anchor_no      => $source->get_attribute_value ('anchor'),              page_anchor_no      => $source->get_attribute_value
162                                         ('anchor',
163                                          namespace_uri => $NS_SW09),
164            }, {            }, {
165              o => $opt->{o},              o => $opt->{o},
166              parent => $result,              parent => $result,
# Line 174  Format: Line 187  Format:
187                                                         ->{ws__section_depth});                                                         ->{ws__section_depth});
188            }            }
189            $apply_template_children->($source => $node);            $apply_template_children->($source => $node);
190              SuikaWiki::Plugin->module_package ('WikiStruct')
191                               ->set_section_id ($result, undef, $opt->{o}->{wiki},
192                                                 title => $source->inner_text);
193          } elsif ($ln eq 'ruby' or $ln eq 'rubyb') {          } elsif ($ln eq 'ruby' or $ln eq 'rubyb') {
194            my @child;            my @child;
195            for (@{$source->child_nodes}) {            for (@{$source->child_nodes}) {
# Line 267  Format: Line 283  Format:
283                                   namespace_uri => $NS_XHTML1,                                   namespace_uri => $NS_XHTML1,
284                                   local_name => 'a');                                   local_name => 'a');
285            $node->set_attribute (id => 'anchor-'.$source->get_attribute_value            $node->set_attribute (id => 'anchor-'.$source->get_attribute_value
286                                                    ('anchor', default => '0'));                                                    ('anchor', default => '0',
287                                                       namespace_uri => $NS_SW09));
288            $node->append_text ($source->inner_text);            $node->append_text ($source->inner_text);
289          } elsif ($ln eq 'anchor-internal') {          } elsif ($ln eq 'anchor-internal') {
290            my $node = $result->append_new_node            my $node = $result->append_new_node
# Line 275  Format: Line 292  Format:
292                                   namespace_uri => $NS_XHTML1,                                   namespace_uri => $NS_XHTML1,
293                                   local_name => 'a');                                   local_name => 'a');
294            $node->set_attribute (href => '#anchor-'.$source->get_attribute_value            $node->set_attribute (href => '#anchor-'.$source->get_attribute_value
295                                                       ('anchor', default => '0'));                                                       ('anchor',
296                                       namespace_uri => $NS_SW09, default => '0'));
297            $node->set_attribute (class => 'wiki-anchor');            $node->set_attribute (class => 'wiki-anchor');
298            $node->append_text ($source->inner_text);            $node->append_text ($source->inner_text);
299          } elsif ($ln eq 'anchor-external') {          } elsif ($ln eq 'anchor-external') {
# Line 285  Format: Line 303  Format:
303            SuikaWiki::Plugin->module_package ('WikiLinking')            SuikaWiki::Plugin->module_package ('WikiLinking')
304                  ->to_resource_in_html (                  ->to_resource_in_html (
305                      {                      {
306                       label => SuikaWiki::Plugin->resource                       label => SuikaWiki::Plugin->module_package ('WikiResource')
307                                  ('Link:SuikaWiki/0.9:toResource:SourceLabel'),                                  ->get_text (name =>
308                                       'Link:SuikaWiki/0.9:toResource:SourceLabel',
309                                       param => $opt->{o},
310                                       wiki => $opt->{o}->{wiki}),
311                      }, {                      }, {
312                        resource_scheme =>                        resource_scheme =>
313                          $source->get_attribute_value ('scheme',                          $source->get_attribute_value ('resScheme',
314                                                          namespace_uri => $NS_SW09,
315                                                        default => 'URI'),                                                        default => 'URI'),
316                        resource_parameter =>                        resource_parameter =>
317                          $source->get_attribute_value ('data', default => ''),                          $source->get_attribute_value ('resParameter',
318                                                          namespace_uri => $NS_SW09,
319                                                          default => ''),
320                      }, {                      }, {
321                       o => $opt->{o},                       o => $opt->{o},
322                       parent => $result,                       parent => $result,
323                      });                      });
324            } elsif ($ln eq 'form') {
325              SuikaWiki::Plugin->module_package ('WikiFormCore')
326                               ->make_content_form_in_html
327                                   ($result,
328                                    $source->get_attribute_value
329                                                      ('input', default => ''),
330                                    option => $source->get_attribute_value
331                                                         ('option'),
332                                    name => $source->get_attribute_value ('id'),
333                                    o => $opt->{o},
334                                    wiki => $opt->{o}->{wiki});
335          } elsif ($ln eq 'dr') {          } elsif ($ln eq 'dr') {
336            $apply_template_children->($source => $result);            $apply_template_children->($source => $result);
337          } elsif ($ln eq 'document') {          } elsif ($ln eq 'document') {
# Line 309  Format: Line 344  Format:
344                                                     namespace_uri => $NS_XHTML1,                                                     namespace_uri => $NS_XHTML1,
345                                                     local_name => 'div');                                                     local_name => 'div');
346            $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;  
347            $apply_template_children->($body => $body_block);            $apply_template_children->($body => $body_block);
348          } else {          } else {
349            my $node = $result->append_new_node            my $node = $result->append_new_node
# Line 344  Format: Line 377  Format:
377        @@@@: Converting SuikaWiki/0.9 text format to XML format        @@@@: Converting SuikaWiki/0.9 text format to XML format
378        @@@lang: en        @@@lang: en
379      @@Main:      @@Main:
380        __FUNCPACK__->text_to_xml ($source, $opt);        my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => $opt,
381                                                wiki => $self->{wiki});
382    ## TODO: Make a clone
383          $opt->{-parent}->append_node ($xml);
384    
385      @NextIndex:
386        @@Name: anchor
387        @@Main:
388          my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => \%opt,
389                                                wiki => $self->{wiki});
390          (__FUNCPACK__->get_last_anchor_index ($xml)) + 1;
391      
392      @WikiForm:
393        @@Main:
394          ## Text format -> XML format
395          my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => \%opt,
396                                                wiki => $self->{wiki});
397          local $opt{o}->{var}->{sw09__anchor_index};
398          local $opt{o}->{var}->{sw09__document_tree} = $xml;
399    
400          my $form;
401          if ($opt{o}->{form}->{output}->{id}) {
402            $form = __FUNCPACK__->get_element_by_id
403                      ($xml, $opt{o}->{form}->{output}->{id});
404            undef $form unless ref $form and
405                               $form->namespace_uri eq $NS_SW09 and
406                               $form->local_name eq 'form';
407          } else {
408            $form = __FUNCPACK__->get_nth_element
409                      ($xml, $NS_SW09 => 'form',
410                       $opt{o}->{form}->{output}->{index});
411          }
412          
413          unless (ref $form) {
414    ## TOOD:
415     CORE::die "No form (ID $opt{o}->{form}->{output}->{id}; Index $opt{o}->{form}->{output}->{index})";
416          }
417          
418          ## WikiForm Option
419          $opt{option} ||= $form->get_attribute_value ('option');
420          SuikaWiki::Plugin->module_package ('WikiFormCore')
421                           ->set_option ($opt{option} => $opt{o}) if $opt{option};
422          
423          ## Replace Output Template
424          my $result;
425          $opt{template} ||= $form->get_attribute_value ('template', default => '');
426          try {
427            $result = SuikaWiki::Plugin->text_formatter ('form_template')
428                             ->replace ($opt{template}, param => $opt{o});
429          } catch Message::Util::Formatter::error with {
430            my $err = shift;
431            SuikaWiki::Plugin->module_package ('Error')
432                             ->reporting_formatting_template_error
433                                 ($err, $err->{option}->{param}->{wiki});
434    ##TODO:
435            throw SuikaWiki::View::Implementation::error -type => 'ERROR_REPORTED';
436          };      
437    
438          ## Insert
439          if (length $result) {
440            my $parent = $form->parent_node;
441            ## TODO:
442            CORE::die "No parent of form" unless ref $parent;
443            my $children = $parent->child_nodes;
444            
445            $result .= "\x0A" unless substr ($result, -1) eq "\x0A";
446            $parent->append_new_node (type => '#element',
447                                      namespace_uri => $NS_SW09,
448                                      local_name => 'text')
449                   ->append_text ($result);
450            my $node = pop @{$children};
451            my $form_str = overload::StrVal ($form);
452            my $i = 0;
453            for (@{$children}) {
454              last if overload::StrVal ($_) eq $form_str;
455              $i++;
456            }
457            if ($opt{o}->{form}->{output}->{reverse}) {
458              splice @{$children}, $i + 1, 0, $node;
459            } else {
460              splice @{$children}, $i, 0, $node;
461            }
462          }
463    
464          ## XML format -> Text format
465          my $text = __FUNCPACK__->xml_to_text ($xml, {%opt});
466    
467          my %fragment = (fragment => $opt{o}->{form}->{output}->{id}
468                                || 'wikiform-'.$opt{o}->{form}->{output}->{index});
469          if (not $opt{o}->{form}->{output}->{reverse} and
470              $opt{o}->{var}->{sw09__anchor_index}) {
471            %fragment = (anchor_no => $opt{o}->{var}->{sw09__anchor_index});
472          }
473    
474          my $action = [
475            {
476              type => 'write',
477              content => $text,
478            },
479            {
480              type => 'view',
481              %fragment,
482            },
483          ];
484    
485    FormattingRule:
486      @Category[list]:form-template
487      @Name: index
488      @Description:
489        @@@: Next anchor index number
490        @@lang:en
491      @After:
492        if ($o->{var}->{sw09__anchor_index}) {
493          ++$o->{var}->{sw09__anchor_index};
494        } else {
495          $o->{var}->{sw09__anchor_index}
496            = 1 + __FUNCPACK__->get_last_anchor_index
497                                  ($o->{var}->{sw09__document_tree});
498        }
499        $p->{-result} .= $o->{var}->{sw09__anchor_index};
500    
501    Function:
502      @Name: get_last_anchor_index
503      @Main:
504          my (undef, $xml) = @_;
505          my $anchor = 0;
506          my $get_anchor_no;
507          $get_anchor_no = sub {
508            my $node = shift;
509            for my $child (@{$node->child_nodes}) {
510              if ($child->node_type eq '#element') {
511                if ($child->namespace_uri => $NS_SW09 and
512                    $child->local_name eq 'anchor-end') {
513                  my $a = $child->get_attribute_value ('anchor', default => 0,
514                                                       namespace_uri => $NS_SW09);
515                  $anchor = 0+$a if $anchor < 0+$a;
516                } else {
517                  $get_anchor_no->($child);
518                }
519              } elsif ($child->node_type eq '#document' or
520                       $child->node_type eq '#fragment') {
521                $get_anchor_no->($child);
522              }
523            }
524          };
525          $get_anchor_no->($xml);
526          $anchor;
527    
528    
529    Function:
530      @Name: get_xml_tree
531      @Main:
532        my (undef, %opt) = @_;
533        if ($opt{opt}->{page}) {
534          unless ($__FUNCPACK__::DBLoaded) {
535            $opt{wiki}->{db}->_set_prop_db (sw09__xml_tree => {-db_open => sub {
536              require SuikaWiki::DB::Hash;
537              new SuikaWiki::DB::Hash;
538            }});
539            $__FUNCPACK__::DBLoaded++;
540          }
541        
542          my $xml = new Message::Markup::XML::Node type => '#fragment';
543          __FUNCPACK__->text_to_xml (${$opt{text}}, {%{$opt{opt}}, -parent => $xml});
544    
545          $opt{wiki}->{db}->set (sw09__xml_tree => $opt{opt}->{page} => $xml);
546          $xml;
547        } else {
548          my $xml = new Message::Markup::XML::Node type => '#fragment';
549          __FUNCPACK__->text_to_xml (${$opt{text}}, {%{$opt{opt}}, -parent => $xml});
550          $xml;
551        }
552    
553    
554    Function:
555      @Name: xml_to_text
556      @Main:
557        my (undef, $src, $opt) = @_;
558    
559    
560        my %is_block = (
561          qw/p 1 blockquote 1 pre 1 ul 1 ol 1 dl 1 section 1 h 1
562             bodytext 1 document 1 head 1 body 1 table 1 text 1 form 1
563             insert 1 delete 1/
564        );
565    
566            my %x2t;
567            %x2t = (
568              anchor => sub {
569                my $source = shift;
570                my $result = '[['
571                          .  $x2t{'#inline'}->($source, no_newline => 1)
572                          .  ']';
573                my $anchor = $source->get_attribute_value
574                                      ('anchor',
575                                       namespace_uri => $NS_SW09,
576                                       default => '');
577                if (length $anchor) {
578                  $result .= '>>'.(0+$anchor);
579                } else {
580                  $anchor = $source->get_attribute_value
581                                      ('resScheme',
582                                       namespace_uri => $NS_SW09);
583                  if ($anchor) {
584                    my $param = $source->get_attribute_value
585                                      ('resParameter',
586                                       namespace_uri => $NS_SW09);
587                    if ($anchor eq 'URI' and $param =~ /^[0-9A-Za-z_+.%-]+:/) {
588                      $result .= '<' . $param . '>';
589                    } else {
590                      $result .= '<' . $anchor . ':' . $param . '>';
591                    }
592                  }
593                }
594                $result . ']';
595              },
596              li => sub {
597                my $source = shift;
598                my $result = ({qw/ul - ol =/}->{$opt->{o}->{var}->{sw09__list_type}}
599                              x $opt->{o}->{var}->{sw09__list_depth})
600                          .  ' ' . $x2t{'#flow'}->($source);
601                $result;
602              },
603              dt => sub {
604                ':' . $x2t{'#inline'}->(return, no_newline => 1) . ':';
605              },
606              h => sub {
607                  ("*" x ($opt->{o}->{var}->{ws__section_depth} - 1))
608                .  " "
609                .  $x2t{'#inline'}->(shift, no_newline => 1);
610              },
611              'anchor-end' => sub {
612                return shift->inner_text;
613              },
614              'anchor-internal' => sub {
615                return shift->inner_text;
616              },
617              'anchor-external' => sub {
618                return '<'.shift->inner_text.'>';
619              },
620              form => sub {
621                my $source = shift;
622                my $ref = $source->get_attribute_value ('ref', default => 'form');
623                my $result = '[[#'.$ref;
624                my $name = $source->get_attribute_value ('id');
625                $name =~ s/([()\\])/\\$1/g;
626                $result .= '(' . $name . ')' if $name;
627                ## General WikiForm
628                if ($ref eq 'form') {
629                  $result .= ":'";
630                  my $input = $source->get_attribute_value ('input', default => '');
631                  $input =~ s/(['\\])/\\$1/g;
632                  $result .= $input . "':'";
633                  my $template = $source->get_attribute_value ('template', default => '');
634                  $template =~ s/(['\\])/\\$1/g;
635                  $result .= $template . "'";
636                  my $option = $source->get_attribute_value ('option');
637                  if ($option) {
638                    $option =~ s/(['\\])/\\$1/g;
639                    $result .= ":'" . $option . "'";
640                  }
641                ## Specific WikiForm
642                } else {
643                  my $param = $source->get_attribute_value ('parameter');
644                  if ($param) {
645                    $result .= ':' . $param;
646                  }
647                }
648                $result .= ']]';
649              },
650              pre => sub {
651                my $source = shift;
652                my $result = '[PRE';
653                my $class = $source->get_attribute_value ('class');
654                if ($class) {
655                  $class =~ s/([\\()])/\\$1/g;
656                  $result .= '(' . $class . ')';
657                }
658                $result .= "[\x0A"
659                        .  $x2t{'#inline'}->($source);
660                $result .= "\x0A" unless substr ($result, -1) eq "\x0A";
661                $result .= "]PRE]\x0A";
662              },
663              insert => sub {
664                my $source = shift;
665                my $result = '[INS';
666                my $class = $source->get_attribute_value ('class');
667                if ($class) {
668                  $class =~ s/([\\()])/\\$1/g;
669                  $result .= '(' . $class . ')';
670                }
671                local $opt->{o}->{var}->{sw09__list_depth} = 0;
672                $result .= "[\x0A"
673                        .  $x2t{'#block'}->($source);
674                $result .= "\x0A" unless substr ($result, -1) eq "\x0A";
675                $result .= "]INS]\x0A";
676              },
677              delete => sub {
678                my $source = shift;
679                my $result = '[DEL';
680                my $class = $source->get_attribute_value ('class');
681                if ($class) {
682                  $class =~ s/([\\()])/\\$1/g;
683                  $result .= '(' . $class . ')';
684                }
685                local $opt->{o}->{var}->{sw09__list_depth} = 0;
686                $result .= "[\x0A"
687                        .  $x2t{'#block'}->($source);
688                $result .= "\x0A" unless substr ($result, -1) eq "\x0A";
689                $result .= "]DEL]\x0A";
690              },
691              document => sub {
692                my $source = shift;
693                my $result = '';
694                for (@{$source->child_nodes}) {
695                  $result .= ($x2t{$_->local_name} or $x2t{'#undef'})->($_)
696                    if $_->node_type eq '#element';
697                }
698                $result;
699              },
700              head => sub {
701                my $source = shift;
702                my $result = '#?SuikaWiki/0.9';
703                for (@{$source->child_nodes}) {
704                  if ($_->node_type eq '#element' and
705                      $_->local_name eq 'parameter') {
706                    $result .= ' '.$x2t{parameter}->($_);
707                  }
708                }
709                $result . "\x0A";
710              },
711              parameter => sub {
712                my $source = shift;
713                my $result = $source->get_attribute_value ('name', default => '')
714                          .  '="';
715                my @v;
716                for (@{$source->child_nodes}) {
717                  push @v, $x2t{value}->($_) if $_->node_type eq '#element' and
718                                                $_->local_name eq 'value';
719                }
720                $result .= join ',', @v;
721                $result .  '"';
722              },
723              value => sub {
724                my $value = $x2t{'#inline'}->(shift, no_newline => 1);
725                $value =~ s/(["\\])/\\$1/g;
726                $value =~ tr/\x0A\x0D/ /;
727                $value;
728              },
729              section => sub {
730                local $opt->{o}->{var}->{ws__section_depth}
731                    = $opt->{o}->{var}->{ws__section_depth} + 1;
732                $x2t{'#block'}->(shift);
733              },
734              body => sub {
735                local $opt->{o}->{var}->{ws__section_depth} = 1;
736                $x2t{'#block'}->(shift);
737              },
738              text => sub {
739                my ($source, %opt) = @_;
740                my $result .= '';
741                for (@{$source->child_nodes}) {
742                  if ($_->node_type eq '#text') {
743                    $result .= $_->inner_text;
744                  } elsif ($_->node_type eq '#element') {
745                    $result .= ($x2t{$_->local_name} or $x2t{'#undef'})->($_);
746                  }
747                }
748                $result;
749              },
750              dr => sub {
751                my $result = $x2t{'#list'}->(shift);
752                if ($result) {
753                  $result . "\x0A";
754                } else {
755                  "::\x0A";
756                }
757              },
758              dt => sub {
759                ':' . $x2t{'#inline'}->(shift, no_newline => 1) . ':';
760              },
761              dd => sub {
762                $x2t{'#inline'}->(shift);
763              },
764              tr => sub {
765                my $result = $x2t{'#list'}->(shift);
766                if ($result) {
767                  substr ($result, 1) . "\x0A";
768                } else {
769                 "',\x0A";
770                }
771              },
772              td => sub {
773                my $source = shift;
774                my $result = $x2t{'#inline'}->($source, no_newline => 1);
775                if ($result =~ /[,"\\]/ or $result =~ /==/) {
776                  $result =~ s/(["\\])/\\$1/g;
777                  $result = '"' . $result . '"';
778                }
779                my $colspan = $source->get_attribute_value ('colspan', default => 1);
780                $result .= ("\t,==" x ($colspan - 1)) if $colspan > 1;
781                "\t," . $result;
782              },
783              em => sub {
784                "''" . $x2t{'#inline'}->($_, no_newline => 1) . "''";
785              },
786              strong => => sub {
787                "'''" . $x2t{'#inline'}->($_, no_newline => 1) . "'''";
788              },
789              rb => sub {
790                $x2t{'#inline'}->(shift, no_newline => 1);
791              },
792              rt => sub {
793                '] [' . $x2t{'#inline'}->(shift, no_newline => 1);
794              },
795              replace => sub {
796                '__&&' . shift->get_attribute_value ('by', default => '') . '&&__';
797              },
798              bodytext => sub {
799                my ($source, %opt) = @_;
800                local $opt->{o}->{var}->{sw09__bq_depth}
801                    = $opt->{o}->{var}->{sw09__bq_depth} + 1;
802                my @result;
803                for (@{$source->child_nodes}) {
804                  if ($_->node_type eq '#element') {
805                    my $ln = $_->local_name;
806                    push @result, [($x2t{$ln} or $x2t{'#undef'})->($_),
807                                   $ln];
808                  }
809                }
810                my $result = '';
811                my $prev = '';
812                for (@result) {
813                  my $s = $_->[0];
814                  if ($_->[1] eq 'p') {
815                    $result .= "\x0A" if length $result and
816                                         substr ($result, -1) ne "\x0A";
817                    $result .= ('>' x $opt->{o}->{var}->{sw09__bq_depth}) . ' ';
818                  } elsif ($_->[1] eq 'form' or $_->[1] eq 'replace') {
819                    $result .= "\x0A" if length $result and
820                                         substr ($result, -1) ne "\x0A";
821                    $result .= ('>' x $opt->{o}->{var}->{sw09__bq_depth})."\x0A";
822                  } elsif ($_->[1] eq 'blockquote' or $_->[1] eq 'text') {
823                    $result .= "\x0A" if length $result and
824                                         substr ($result, -1) ne "\x0A";
825                  } else {
826                    unless ($prev eq 'text') {
827                      $result .= "\x0A" if length $result and
828                                           substr ($result, -1) ne "\x0A";
829                    }
830                    $result .= ('>' x $opt->{o}->{var}->{sw09__bq_depth})."\x0A";
831                  }
832                  $result .= $s;
833                  $prev = $_->[1];
834                }
835                $result;
836              },
837              '#block' => sub {
838                my ($source, %opt) = @_;
839                my @result;
840                for (@{$source->child_nodes}) {
841                  if ($_->node_type eq '#element') {
842                    my $ln = $_->local_name;
843                    push @result, [($x2t{$ln} or $x2t{'#undef'})->($_),
844                                   $ln];
845                  }
846                }
847                my $result = '';
848                my $prev = '';
849                for (@result) {
850                  my $s = $_->[0];
851                  if ($_->[1] eq 'form') {
852                    $result .= "\x0A" if length $result and
853                                         substr ($result, -1) ne "\x0A";
854                    $result .= "\x0A";
855                  } elsif ($_->[1] eq 'replace') {
856                    $result .= "\x0A" if length $result and
857                                         substr ($result, -1) ne "\x0A";
858                  } elsif ($_->[1] eq 'text') {
859                    $result .= "\x0A" if length $result and
860                                         substr ($result, -1) ne "\x0A";
861                    $result .= "\x0A" if $prev eq 'p';
862                  } else {
863                    if ($prev ne 'text' and $prev ne 'replace') {
864                      $result .= "\x0A" if length $result and
865                                           substr ($result, -1) ne "\x0A";
866                      $result .= "\x0A";
867                    }
868                  }
869                  $result .= $s;
870                  $prev = $_->[1];
871                }
872                $result;
873              },
874              '#flow' => sub {
875                my ($source, %opt) = @_;
876                my @result;
877                for (@{$source->child_nodes}) {
878                  if ($_->node_type eq '#element') {
879                    my $ln = $_->local_name;
880                    if ($is_block{$ln}) {
881                      push @result, [($x2t{$ln} or $x2t{'#undef'})->($_),
882                                     $ln];
883                    } else {
884                      if (@result and ($result[$#result]->[1] eq '#inline')) {
885                        $result[$#result]->[0]
886                          .= ($x2t{$ln} or $x2t{'#undef'})->($_);
887                      } else {
888                        push @result, [($x2t{$ln} or $x2t{'#undef'})->($_),
889                                       '#inline'];
890                      }
891                    }
892                  } elsif ($_->node_type eq '#text') {
893                    if (@result and ($result[$#result]->[1] eq '#inline')) {
894                      $result[$#result]->[0] .= $_->inner_text;
895                    } else {
896                      push @result, [$_->inner_text, '#inline'];
897                    }
898                  }
899                }
900                my $result = '';
901                my $prev = '';
902                for (@result) {
903                  my $s = $_->[0];
904                  if ($_->[1] eq '#inline') {
905                    if ($prev ne 'text' and $prev ne 'form' and $prev ne 'replace') {
906                      $result .= "\x0A" if length $result and
907                                           substr ($result, -1) ne "\x0A";
908                    }
909                    $s =~ s/\x0D\x0A/\x0A/g;
910                    $s =~ s/\x0D/\x0A/g;
911                    $s =~ s/\x0A\x0A+/\x0A/g;
912                    $s =~ s/\x0A/\x20/g if $opt{no_newline};
913                  } elsif ($_->[1] eq 'form' or $_->[1] eq 'replace') {
914                    if ($prev ne '#inline') {
915                      $result .= "\x0A" if length $result and
916                                           substr ($result, -1) ne "\x0A";
917                    }
918                  } elsif ($_->[1] eq 'text') {
919                    $result .= "\x0A" if length $result and
920                                         substr ($result, -1) ne "\x0A";
921                  } else {
922                    unless ($prev eq 'text') {
923                      $result .= "\x0A" if length $result and
924                                           substr ($result, -1) ne "\x0A";
925                    }
926                  }
927                  $result .= $s;
928                  $prev = $_->[1];
929                }
930                $result;
931              },
932              '#inline' => sub {
933                my ($source, %opt) = @_;
934                my $result .= '';
935                for (@{$source->child_nodes}) {
936                  if ($_->node_type eq '#text') {
937                    $result .= $_->inner_text;
938                  } elsif ($_->node_type eq '#element') {
939                    $result .= ($x2t{$_->local_name} or $x2t{'#undef'})->($_);
940                  }
941                }
942                $result =~ s/\x0D\x0A/\x0A/g;
943                $result =~ s/\x0D/\x0A/g;
944                $result =~ s/\x0A\x0A+/\x0A/g;
945                $result =~ s/\x0A/\x20/g if $opt{no_newline};
946                $result;
947              },
948              '#list' => sub {
949                my ($source, %opt) = @_;
950                my $result .= '';
951                for (@{$source->child_nodes}) {
952                  if ($_->node_type eq '#element') {
953                    $result .= ($x2t{$_->local_name} or $x2t{'#undef'})->($_);
954                  }
955                }
956                $result;
957              },
958              '#undef' => sub {
959                my $source = shift;
960                ## TODO:
961                "<".$source->namespace_uri.">:".$source->local_name
962                      .  $x2t{'#inline'}->($source);
963              },
964            );
965            for (qw/blockquote dl tbody table/) {
966              $x2t{$_} = sub { $x2t{'#list'}->(shift) };
967            }
968            for (qw/p dd/) {
969              $x2t{$_} = sub { $x2t{'#flow'}->(shift) };
970            }
971            for my $type (qw/ul ol/) {
972              $x2t{$type} = sub {
973                my $source = shift;
974                local $opt->{o}->{var}->{sw09__list_type} = $type;
975                local $opt->{o}->{var}->{sw09__list_depth}
976                    = $opt->{o}->{var}->{sw09__list_depth} + 1;
977                my @result;
978                for (@{$source->child_nodes}) {
979                  push @result, $x2t{$_->local_name}->($_)
980                    if $_->node_type eq '#element';
981                }
982                my $result = '';
983                for (@result) {
984                  $result .= "\x0A" unless substr ($result, -1) eq "\x0A";
985                  $result .= $_;
986                }
987                substr ($result, 1);
988              };
989            }
990            for my $type (qw/code samp var dfn kbd sub sup weak q ruby rubyb
991                             abbr ins del/) {
992              $x2t{$type} = sub {
993                my $source = shift;
994                my $result = '['.uc $type;
995                my $class = $source->get_attribute_value ('class', default => '');
996                if ($class) {
997                  $class =~ s/([()\\])/\\$1/g;
998                  $result .= '(' . $class . ')';
999                }
1000                $result .= '['
1001                        .  $x2t{'#inline'}->($source, no_newline => 1)
1002                        .  ']';
1003                my $anchor = $source->get_attribute_value
1004                                      ('anchor',
1005                                       namespace_uri => $NS_SW09,
1006                                       default => '');
1007                if (length $anchor) {
1008                  $result .= '>>'.(0+$anchor);
1009                } else {
1010                  $anchor = $source->get_attribute_value
1011                                      ('resScheme',
1012                                       namespace_uri => $NS_SW09);
1013                  if ($anchor) {
1014                    my $param = $source->get_attribute_value
1015                                      ('resParameter',
1016                                       namespace_uri => $NS_SW09);
1017                    if ($anchor eq 'URI' and $param =~ /^[0-9A-Za-z_+.%-]+:/) {
1018                      $result .= '<' . $param . '>';
1019                    } else {
1020                      $result .= '<' . $anchor . ':' . $param . '>';
1021                    }
1022                  }
1023                }
1024                $result .= ']';
1025                $result;
1026              };
1027            }
1028    
1029        $x2t{'#list'}->($src);
1030    
1031    Function:
1032      @Name: get_nth_element
1033      @Main:
1034        my (undef, $node, $ns => $ln, $n) = @_;
1035        return $n if $n < 1;
1036        if ($node->node_type eq '#element' and
1037            $node->namespace_uri eq $ns and
1038            $node->local_name eq $ln) {
1039          return $node unless --$n;
1040        }
1041        for (@{$node->child_nodes}) {
1042          if ($_->node_type eq '#element') {
1043            if ($_->namespace_uri eq $ns and
1044                $_->local_name eq $ln) {
1045              return $_ unless --$n;
1046            } else {
1047              $n = __FUNCPACK__->get_nth_element ($_, $ns => $ln, $n);
1048              return $n if ref $n;
1049            }
1050          } elsif ($_->node_type eq '#fragment' or $_->node_type eq '#document') {
1051            $n = __FUNCPACK__->get_nth_element ($_, $ns => $ln, $n);
1052            return $n if ref $n;
1053          }
1054        }
1055        return $n;
1056    
1057    Function:
1058      @Name: get_element_by_id
1059      @Main:
1060        my (undef, $node, $id) = @_;
1061        return $node if $node->node_type eq '#element'
1062                    and $node->get_attribute_value ('id', default_value => '')
1063                     eq $id;
1064        for (@{$node->child_nodes}) {
1065          if ({'#element'=>1, '#fragment'=>1, '#document'=>1}->{$_->node_type}) {
1066            my $r = __FUNCPACK__->get_element_by_id ($_, $id);
1067            return $r if $r;
1068          }
1069        }
1070    
1071  Function:  Function:
1072    @Name: text_to_xml    @Name: text_to_xml
# Line 371  Function: Line 1093  Function:
1093          $value =~ s/\\(.)/$1/g;          $value =~ s/\\(.)/$1/g;
1094          for ($head->append_new_node (type => '#element',          for ($head->append_new_node (type => '#element',
1095                                       namespace_uri => $NS_SW09,                                       namespace_uri => $NS_SW09,
1096                                       local_name => 'parmeter')) {                                       local_name => 'parameter')) {
1097            $_->set_attribute (name => $name);            $_->set_attribute (name => $name);
1098            for my $value (split /,/, $value) {            for my $value (split /,/, $value) {
1099              $_->append_new_node (type => '#element',              $_->append_new_node (type => '#element',
# Line 390  Function: Line 1112  Function:
1112      my $body = $root->append_new_node (type => '#element',      my $body = $root->append_new_node (type => '#element',
1113                                         namespace_uri => $NS_XHTML2,                                         namespace_uri => $NS_XHTML2,
1114                                         local_name => 'body');                                         local_name => 'body');
1115      __FUNCPACK__->block_text_to_xml (\$source => $body);      __FUNCPACK__->block_text_to_xml (\$source => $body, opt => $opt);
1116    
1117  Function:  Function:
1118    @Name:block_text_to_xml    @Name:block_text_to_xml
# Line 401  Function: Line 1123  Function:
1123      @@lang:en      @@lang:en
1124    @Main:    @Main:
1125      my (undef, $source, $current, %opt) = @_;      my (undef, $source, $current, %opt) = @_;
1126      my %depth;      my %depth = %{$opt{depth} || {}};
1127      my $back_to_section = sub {      my $back_to_section = sub {
1128        my $cur_type = $current->local_name;        my $cur_type = $current->local_name;
1129        while (not (        while (not (
1130                    $cur_type eq 'section'                    $cur_type eq 'section'
1131                 or $cur_type eq 'body'                 or $cur_type eq 'body'
1132                 or $cur_type eq 'bodytext'                 or $cur_type eq 'bodytext'
1133                 or $cur_type eq 'ins'                 or $cur_type eq 'insert'
1134                 or $cur_type eq 'del'                 or $cur_type eq 'delete'
1135                   )                   )
1136        ) {        ) {
1137          $current = $current->parent_node;          $current = $current->parent_node;
# Line 422  Function: Line 1144  Function:
1144        while (not (        while (not (
1145                    $cur_type eq 'section'                    $cur_type eq 'section'
1146                 or $cur_type eq 'body'                 or $cur_type eq 'body'
1147                 or $cur_type eq 'ins'                 or $cur_type eq 'insert'
1148                 or $cur_type eq 'del'                 or $cur_type eq 'delete'
1149                   )                   )
1150              ) {              ) {
1151          $current = $current->parent_node;          $current = $current->parent_node;
# Line 484  Function: Line 1206  Function:
1206          $current = $current->append_new_node (type => '#element',          $current = $current->append_new_node (type => '#element',
1207                                                namespace_uri => $NS_XHTML2,                                                namespace_uri => $NS_XHTML2,
1208                                                local_name => 'li');                                                local_name => 'li');
1209          __FUNCPACK__->inline_text_to_xml (\$line => $current);          __FUNCPACK__->inline_text_to_xml (\$line => $current, %opt);
1210        } elsif ($line =~ s/^(\*+)\s*//) {        } elsif ($line =~ s/^(\*+)\s*//) {
1211          my $depth = length $1;          my $depth = length $1;
1212          $back_to_real_section->();          $back_to_real_section->();
# Line 510  Function: Line 1232  Function:
1232          __FUNCPACK__->inline_text_to_xml (\$line =>          __FUNCPACK__->inline_text_to_xml (\$line =>
1233            $current->append_new_node (type => '#element',            $current->append_new_node (type => '#element',
1234                                       namespace_uri => $NS_XHTML2,                                       namespace_uri => $NS_XHTML2,
1235                                       local_name => 'h')                                       local_name => 'h'), %opt,
1236          );          );
1237        } elsif ($line =~ s/^(?!>>[0-9])(>+)\s*//) {        } elsif ($line =~ s/^(?!>>[0-9])(>+)\s*//) {
1238          my $depth = length $1;          my $depth = length $1;
# Line 542  Function: Line 1264  Function:
1264                                   (type => '#element',                                   (type => '#element',
1265                                    namespace_uri => $NS_XHTML2,                                    namespace_uri => $NS_XHTML2,
1266                                    local_name => 'p');                                    local_name => 'p');
1267            __FUNCPACK__->inline_text_to_xml (\$line => $current);            __FUNCPACK__->inline_text_to_xml (\$line => $current, %opt);
1268          }          }
1269        } elsif ($line =~ s/^(?>:\s*)([^:]+?)\s*:\s*//) {        } elsif ($line =~ s/^(?>:\s*)([^:]+?)\s*:\s*//) {
1270          my $parent_type = $current->local_name;          my $parent_type = $current->local_name;
# Line 561  Function: Line 1283  Function:
1283          __FUNCPACK__->inline_text_to_xml (\"$1" =>          __FUNCPACK__->inline_text_to_xml (\"$1" =>
1284            $current->append_new_node (type => '#element',            $current->append_new_node (type => '#element',
1285                                       namespace_uri => $NS_XHTML2,                                       namespace_uri => $NS_XHTML2,
1286                                       local_name => 'dt')                                       local_name => 'dt'), %opt,
1287          );          );
1288          $current->append_text ("\x0A");          $current->append_text ("\x0A");
1289          $current = $current->append_new_node (type => '#element',          $current = $current->append_new_node (type => '#element',
1290                                                namespace_uri => $NS_XHTML2,                                                namespace_uri => $NS_XHTML2,
1291                                                local_name => 'dd');                                                local_name => 'dd');
1292            __FUNCPACK__->inline_text_to_xml (\$line => $current);            __FUNCPACK__->inline_text_to_xml (\$line => $current, %opt);
1293        } elsif ($line =~ /^\[(INS|DEL)(\([^()\\]*\))?\[\s*$/) {        } elsif ($line =~ /^\[(INS|DEL)(\([^()\\]*\))?\[\s*$/) {
1294          $current->append_text ("\x0A");          $current->append_text ("\x0A");
1295          my $mod = $current->append_new_node (type => '#element',          my $mod = $current->append_new_node
1296                                               namespace_uri => $NS_XHTML1,                                (type => '#element',
1297                                               local_name => lc $1);                                 namespace_uri => $NS_SW09,
1298                                   local_name => {qw/INS insert DEL delete/}->{$1});
1299          $mod->set_attribute (class => $2) if $2;          $mod->set_attribute (class => $2) if $2;
1300          __FUNCPACK__->block_text_to_xml ($source => $mod,          __FUNCPACK__->block_text_to_xml ($source => $mod, %opt,
1301                                           'return_by_'.$1 => 1);                                           'return_by_'.$1 => 1,
1302                                             depth => \%depth);
1303        } elsif ($line =~ /^\](INS|DEL)\]\s*$/) {        } elsif ($line =~ /^\](INS|DEL)\]\s*$/) {
1304          if ($opt{'return_by_'.$1}) {          if ($opt{'return_by_'.$1}) {
1305            return;            return;
# Line 597  Function: Line 1321  Function:
1321              last;              last;
1322            } else {            } else {
1323              $f ? undef $f : $pre->append_text ("\x0A");              $f ? undef $f : $pre->append_text ("\x0A");
1324              __FUNCPACK__->inline_text_to_xml (\$line => $pre);              __FUNCPACK__->inline_text_to_xml (\$line => $pre, %opt);
1325            }            }
1326          }          }
1327          if (ref $pre) {          if (ref $pre) {
# Line 609  Function: Line 1333  Function:
1333                                               namespace_uri => $NS_XHTML1,                                               namespace_uri => $NS_XHTML1,
1334                                               local_name => 'pre');                                               local_name => 'pre');
1335          $pre->set_attribute (space => 'preserve', namespace_uri => NS_xml_URI);          $pre->set_attribute (space => 'preserve', namespace_uri => NS_xml_URI);
1336          __FUNCPACK__->inline_text_to_xml (\$line => $pre);          __FUNCPACK__->inline_text_to_xml (\$line => $pre, %opt);
1337          while ($$source =~ /\G([^\x0A]*)\x0A/gc) {          while ($$source =~ /\G([^\x0A]*)\x0A/gc) {
1338            my $line = $1;            my $line = $1;
1339            if (length $line == 0) {            if (length $line == 0) {
1340              pos ($$source) -= 1;              pos ($$source) -= 1;
1341              last;              last;
1342              } elsif ($opt{return_by_INS} and $line =~ /^\]INS\]\s*$/) {
1343                return;
1344              } elsif ($opt{return_by_DEL} and $line =~ /^\]DEL\]\s*$/) {
1345                return;
1346            } else {            } else {
1347              $pre->append_text ("\x0A");              $pre->append_text ("\x0A");
1348              __FUNCPACK__->inline_text_to_xml (\$line => $pre);              __FUNCPACK__->inline_text_to_xml (\$line => $pre, %opt);
1349            }            }
1350          }          }
1351        } elsif ($line =~ /^,/) {        } elsif ($line =~ /^,/) {
# Line 628  Function: Line 1356  Function:
1356                              ->append_new_node (type => '#element',                              ->append_new_node (type => '#element',
1357                                                 namespace_uri => $NS_XHTML2,                                                 namespace_uri => $NS_XHTML2,
1358                                                 local_name => 'tbody');                                                 local_name => 'tbody');
1359          __FUNCPACK__->tablerow_text_to_xml (\$line => $tbody);          __FUNCPACK__->tablerow_text_to_xml (\$line => $tbody, %opt);
1360          while ($$source =~ /\G(,[^\x0A]*)\x0A/gc) {          while ($$source =~ /\G(,[^\x0A]*)\x0A/gc) {
1361            __FUNCPACK__->tablerow_text_to_xml (\"$1" => $tbody);            __FUNCPACK__->tablerow_text_to_xml (\"$1" => $tbody, %opt);
1362          }          }
1363        } else {        } else {
1364          my $current_type = $current->local_name;          my $current_type = $current->local_name;
1365          if ($current_type eq 'section'          if ($current_type eq 'section'
1366           or $current_type eq 'body'           or $current_type eq 'body'
1367           or $current_type eq 'bodytext'           or $current_type eq 'bodytext'
1368           or $current_type eq 'ins'           or $current_type eq 'insert'
1369           or $current_type eq 'del') {           or $current_type eq 'delete') {
1370            $current->append_text ("\x0A");            $current->append_text ("\x0A");
1371            if ($line =~ s/^__&&([^&]+)&&__//) {            if ($line =~ s/^__&&([^&]+)&&__//) {
1372              $current->append_new_node (type => '#element',              $current->append_new_node (type => '#element',
# Line 651  Function: Line 1379  Function:
1379                                              local_name => 'form')) {                                              local_name => 'form')) {
1380                $_->set_attribute (id => $1) if $1;                $_->set_attribute (id => $1) if $1;
1381                my ($i, $t, $o) = ($2, $3 || '', $4 || '');                my ($i, $t, $o) = ($2, $3 || '', $4 || '');
1382                s/\\(.)/$1/g for $i, $t, $o;                s/\\(.)/$1/g for ($i, $t, $o);
1383                $_->set_attribute (input => $i);                $_->set_attribute (input => $i);
1384                $_->set_attribute (template => $t);                $_->set_attribute (template => $t);
1385                $_->set_attribute (option => $o);                $_->set_attribute (option => $o);
# Line 665  Function: Line 1393  Function:
1393                $_->set_attribute (parameter => $3) if defined $3;                $_->set_attribute (parameter => $3) if defined $3;
1394              }              }
1395            }            }
1396            $current = $current->append_new_node            if (length $line) {
1397                                   (type => '#element',              $current = $current->append_new_node
1398                                    namespace_uri => $NS_XHTML2,                                     (type => '#element',
1399                                    local_name => 'p');                                      namespace_uri => $NS_XHTML2,
1400            __FUNCPACK__->inline_text_to_xml (\$line => $current);                                      local_name => 'p');
1401                __FUNCPACK__->inline_text_to_xml (\$line => $current, %opt);
1402              }        
1403          } else {          } else {
1404            $current->append_text (" "); # replacement of prev.line's \n            $current->append_text ("\x0A"); # replacement of prev.line's \n
1405            __FUNCPACK__->inline_text_to_xml (\$line => $current);            __FUNCPACK__->inline_text_to_xml (\$line => $current, %opt);
1406          }          }
1407        }        }
1408      }      }
# Line 695  Function: Line 1425  Function:
1425                                            local_name => 'tr');                                            local_name => 'tr');
1426      my $prev_cell;      my $prev_cell;
1427      while ($$source =~ /\G,\s*/gc) {      while ($$source =~ /\G,\s*/gc) {
1428        $$source =~ /\G([^,"]+|"(?>[^"\\]*)(?>(?>[^"\\]+|\\.)*)"\s*)/gc;        $$source =~ /\G([^,"][^,]*|"(?>[^"\\]*)(?>(?>[^"\\]+|\\.)*)"\s*)/gc;
1429        my $cell = $1;        my $cell = $1;
1430        if ($cell =~ s/^"//) {        if ($cell =~ s/^"//) {
1431          $cell =~ s/"\s*$//g;          $cell =~ s/"\s*$//g;
# Line 717  Function: Line 1447  Function:
1447                                 (type => '#element',                                 (type => '#element',
1448                                  namespace_uri => $NS_XHTML2,                                  namespace_uri => $NS_XHTML2,
1449                                  local_name => 'td');                                  local_name => 'td');
1450        __FUNCPACK__->inline_text_to_xml (\$cell => $prev_cell);        __FUNCPACK__->inline_text_to_xml (\$cell => $prev_cell, %opt);
1451      }      }
1452      # TODO: warn      # TODO: warn
1453    
# Line 756  Function: Line 1486  Function:
1486        for ($current->append_new_node (type => '#element',        for ($current->append_new_node (type => '#element',
1487                                        namespace_uri => $NS_SW09,                                        namespace_uri => $NS_SW09,
1488                                        local_name => 'anchor-end')) {                                        local_name => 'anchor-end')) {
1489          $_->set_attribute (anchor => 0+$1);          $_->set_attribute (anchor => 0+$1,
1490                               namespace_uri => $NS_SW09);
1491          $_->append_text ('['.$1.']');          $_->append_text ('['.$1.']');
1492        }        }
1493      }      }
# Line 768  Function: Line 1499  Function:
1499                                                local_name => 'form');                                                local_name => 'form');
1500          if ($$source =~ /\G$Reg_Form_Content_M\]\]/ogc) {          if ($$source =~ /\G$Reg_Form_Content_M\]\]/ogc) {
1501            $form->set_attribute (id => $1) if $1;            $form->set_attribute (id => $1) if $1;
1502            $form->set_attribute (input => $2);            my ($i, $t, $o) = ($2, $3, $4);
1503            $form->set_attribute (template => $3);            s/\\(.)/$1/g for ($i, $t, $o);
1504            $form->set_attribute (option => $4);            $form->set_attribute (input => $i);
1505              $form->set_attribute (template => $t);
1506              $form->set_attribute (option => $o);
1507          } elsif ($$source =~ /\G$Reg_Embed_Content_M\]\]/ogc) {          } elsif ($$source =~ /\G$Reg_Embed_Content_M\]\]/ogc) {
1508            $form->set_attribute (ref => $1);            $form->set_attribute (ref => $1);
1509            $form->set_attribute (id => $2) if $2;            $form->set_attribute (id => $2) if $2;
1510            $form->set_attribute (parameter => $3) if defined $3;            $form->set_attribute (parameter => $3) if defined $3;
1511          } else {          } else {
1512            ## TODO: error            ## TODO: error
1513            CORE::die $$source;            SuikaWiki::Plugin->module_package('Error')->report_error_simple ($opt{opt}->{o}->{wiki}, InvalidForm => substr ($$source, pos ($$source)));
1514          }          }
1515        } elsif ($$source =~ /\G\[(?>([A-Z]+)(?>\(([^)]*)\))?)?\[/gc) {        } elsif ($$source =~ /\G\[(?>([A-Z]+)(?>\(([^)]*)\))?)?\[/gc) {
1516          my $type = $1 || 'anchor';          my $type = $1 || 'anchor';
# Line 785  Function: Line 1518  Function:
1518          my $def = $ElementDef->{ $type };          my $def = $ElementDef->{ $type };
1519          unless ($def) {          unless ($def) {
1520            ## TODO: error            ## TODO: error
1521              $def = $ElementDef->{CODE};
1522          }          }
1523          $current = $current->append_new_node (type => '#element',          $current = $current->append_new_node (type => '#element',
1524                                                namespace_uri => $def->{ns_uri},                                                namespace_uri => $def->{ns_uri},
# Line 808  Function: Line 1542  Function:
1542          }          }
1543          my $def = $ElementDef->{$current->local_name} || {};          my $def = $ElementDef->{$current->local_name} || {};
1544          if (defined $anchor) {          if (defined $anchor) {
1545            if ($def->{has_fragment_no}) {            $current->set_attribute (anchor => $anchor + 0,
1546              $current->set_attribute (anchor => $anchor + 0);                                     namespace_uri => $NS_SW09);
           } else {  
             $current->set_attribute (anchor => $anchor + 0,  
                                      namespace_uri => $NS_SW09);  
           }  
1547          } elsif (defined $scheme) {          } elsif (defined $scheme) {
1548            if ($def->{has_cite}) {            if ($scheme =~ /[A-Z]/) {
1549              $current->set_attribute (cite => "$scheme:$opaque");              $current->set_attribute (resScheme => $scheme,
1550                                         namespace_uri => $NS_SW09);
1551                $current->set_attribute (resParameter => $opaque,
1552                                         namespace_uri => $NS_SW09);
1553            } else {            } else {
1554              $current->set_attribute (cite => "$scheme:$opaque",              $current->set_attribute (resScheme => 'URI',
1555                                         namespace_uri => $NS_SW09);
1556                $current->set_attribute (resParameter => "$scheme:$opaque",
1557                                       namespace_uri => $NS_SW09);                                       namespace_uri => $NS_SW09);
1558            }            }
1559          }          }
1560          $current = $current->parent_node;          $current = $current->parent_node;
1561          $current = $current->parent_node if $def->{is_nested};          $current = $current->parent_node if $def->{is_nested};
1562          $depth--;          $depth--;
1563        } elsif ($$source =~ /\G\]\s+\[/gc) {        } elsif ($$source =~ /\G\]\s*\[/gc) {
1564          if ($current->local_name eq 'rb' or $current->local_name eq 'rt') {          if ($current->local_name eq 'rb' or $current->local_name eq 'rt') {
1565            $current = $current->parent_node            $current = $current->parent_node
1566                               ->append_new_node                               ->append_new_node
# Line 833  Function: Line 1568  Function:
1568                                    namespace_uri => $ElementDef->{rt}->{ns_uri},                                    namespace_uri => $ElementDef->{rt}->{ns_uri},
1569                                    local_name => $ElementDef->{rt}->{ln});                                    local_name => $ElementDef->{rt}->{ln});
1570          } else {          } else {
1571            $current->append_text ($$source, $-[0], $+[0]-$-[0]);            $current->append_text (substr ($$source, $-[0], $+[0]-$-[0]));
1572          }          }
1573        } elsif ($$source =~ /\G'''?/gc) {        } elsif ($$source =~ /\G'''?/gc) {
1574          my $type = $+[0] - $-[0] == 3 ? 'strong' : 'em';          my $type = $+[0] - $-[0] == 3 ? 'strong' : 'em';
# Line 852  Function: Line 1587  Function:
1587                                    namespace_uri => $NS_SW09,                                    namespace_uri => $NS_SW09,
1588                                    local_name => 'anchor-external');                                    local_name => 'anchor-external');
1589          if (substr ($scheme, 0, 1) =~ /[A-Z]/) {          if (substr ($scheme, 0, 1) =~ /[A-Z]/) {
1590            $link->set_attribute (scheme => $scheme);            $link->set_attribute (resScheme => $scheme,
1591            $link->set_attribute (data => $data);                                  namespace_uri => $NS_SW09);
1592              $link->set_attribute (resParameter => $data,
1593                                    namespace_uri => $NS_SW09);
1594          } else { # URI Reference          } else { # URI Reference
1595            $link->set_attribute (scheme => 'URI');            $link->set_attribute (resScheme => 'URI',
1596            $link->set_attribute (data => $scheme.':'.$data);                                  namespace_uri => $NS_SW09);
1597              $link->set_attribute (resParameter => $scheme.':'.$data,
1598                                    namespace_uri => $NS_SW09);
1599          }          }
1600          $link->append_text ($scheme.':'.$data);          $link->append_text ($scheme.':'.$data);
1601        } elsif ($$source =~ /\G__&&/gc) {        } elsif ($$source =~ /\G__&&/gc) {
# Line 870  Function: Line 1609  Function:
1609            $current->append_text ('__&&');            $current->append_text ('__&&');
1610          }          }
1611        } elsif ($$source =~ /\G((?>        } elsif ($$source =~ /\G((?>
1612                                    [^'\[\]<>]+                                    [^'\[\]<>_]+
1613                                  | '   (?!')                                  | '   (?!')
1614                                  | \[  (?![A-Z\[])                                  | \[  (?!\[|[A-Z]+(?>\([^()\\]*
1615                                                           (?>[^()\\]+|\\.)*\))?\[)
1616                                  | \]  (?! \]                                  | \]  (?! \]
1617                                          | >>[0-9]+\]                                          | >>[0-9]+\]
1618                                          | <[0-9A-Za-z_+.%-]+:$Reg_URI_Opaque>\]                                          | <[0-9A-Za-z_+.%-]+:$Reg_URI_Opaque>\]
# Line 886  Function: Line 1626  Function:
1626          for ($current->append_new_node (type => '#element',          for ($current->append_new_node (type => '#element',
1627                                          namespace_uri => $NS_SW09,                                          namespace_uri => $NS_SW09,
1628                                          local_name => 'anchor-internal')) {                                          local_name => 'anchor-internal')) {
1629            $_->set_attribute (anchor => 0+$1);            $_->set_attribute (anchor => 0+$1,
1630                                 namespace_uri => $NS_SW09);
1631            $_->append_text ('>>'.$1);            $_->append_text ('>>'.$1);
1632          }          }
1633        } else {        } else {
1634          die "Implementation buggy: ", substr ($$source, pos $$source);          CORE::die "Implementation buggy: ", substr ($$source, pos $$source);
1635        }        }
1636      }      }
1637    
 OldFunction:  
   @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:  
             }  
   
 EOD:  
   
1638  FormattingRule:  FormattingRule:
1639    @Category[list]:    @Category[list]:
1640      page-link      page-link
# Line 943  FormattingRule: Line 1648  FormattingRule:
1648      if ($o->{var}->{sw09__anchor_content}) {      if ($o->{var}->{sw09__anchor_content}) {
1649        $o->{var}->{sw09__anchor_content}->($p->{-parent});        $o->{var}->{sw09__anchor_content}->($p->{-parent});
1650      } else {      } else {
1651        $p->{-parent}->append_node (SuikaWiki::Plugin->resource        SuikaWiki::Plugin->module_package ('WikiResource')
1652                        ('Link:SuikaWiki/0.9:link-anchor-content:InvalidContext'),          ->append_tree
1653                                    node_or_text => 1);              (name => 'Link:SuikaWiki/0.9:link-anchor-content:InvalidContext',
1654                 param => $o,
1655                 -parent => $p->{-parent},
1656                 wiki => $o->{wiki});
1657      }      }
1658    
1659  Resource:  Resource:
1660    @Link:SuikaWiki/0.9:link-anchor-content:InvalidContext:    @Link:SuikaWiki/0.9:link-anchor-content:InvalidContext:
1661      @@@: %sw09--link-anchor-content; cannot be used in this context.      @@@: %percent;sw09--link-anchor-content; cannot be used in this context.
1662      @@lang:en      @@lang:en
1663    @Link:SuikaWiki/0.9:toResource:SourceLabel:    @Link:SuikaWiki/0.9:toResource:SourceLabel:
1664      @@@:      @@@:
# Line 983  Resource: Line 1691  Resource:
1691          class=>{%if-linked-wikipage-exist(false=>{not-exist});}p,          class=>{%if-linked-wikipage-exist(false=>{not-exist});}p,
1692        );        );
1693    
1694    Error:
1695      @Name: text_parse
1696      @Definition:
1697        @@INLINE_NO_CLOSE_TAG:
1698          @@@description:
1699            Close tag of element "%t (name => element_type);" not found.
1700          @@@level: non-fatal
1701        @@BLOCK_NO_CLOSE_TAG:
1702          @@@description:
1703            Close tag of element "%t (name => element_type);" not found.
1704          @@@level: non-fatal
1705        @@INVALID_FORM:
1706          @@@description:
1707            Invalid syntax of WikiForm
1708          @@@level: non-fatal
1709        
1710    Error:
1711      @Name: xml_to_text
1712      @IsA[list]:
1713        ::SuikaWiki::Format::
1714      @Definition:
1715        @@

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24