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

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

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

revision 1.2 by wakaba, Sat Dec 13 04:53:59 2003 UTC revision 1.4 by wakaba, Fri Jan 16 07:58:28 2004 UTC
# Line 14  Plugin: Line 14  Plugin:
14      @@Mail[list]: w@suika.fam.cx      @@Mail[list]: w@suika.fam.cx
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') {
300              local $opt->{o}->{var}->{sw09__anchor_content} = sub {
301                $apply_template_children->($source => shift);
302              };
303              SuikaWiki::Plugin->module_package ('WikiLinking')
304                    ->to_resource_in_html (
305                        {
306                         label => SuikaWiki::Plugin->module_package ('WikiResource')
307                                    ->get_text (name =>
308                                       'Link:SuikaWiki/0.9:toResource:SourceLabel',
309                                       param => $opt->{o},
310                                       wiki => $opt->{o}->{wiki}),
311                        }, {
312                          resource_scheme =>
313                            $source->get_attribute_value ('resScheme',
314                                                          namespace_uri => $NS_SW09,
315                                                          default => 'URI'),
316                          resource_parameter =>
317                            $source->get_attribute_value ('resParameter',
318                                                          namespace_uri => $NS_SW09,
319                                                          default => ''),
320                        }, {
321                         o => $opt->{o},
322                         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 290  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 325  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 352  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 371  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 382  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 403  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 465  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 491  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 523  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 542  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 578  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 590  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 609  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 632  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 646  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 676  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 698  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 737  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 749  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 766  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 789  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 814  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 833  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 (href => $scheme.':'.$data);            $link->set_attribute (resScheme => 'URI',
1596                                    namespace_uri => $NS_SW09);
1597              $link->set_attribute (resParameter => $scheme.':'.$data,
1598                                    namespace_uri => $NS_SW09);
1599          }          }
1600            $link->append_text ($scheme.':'.$data);
1601        } elsif ($$source =~ /\G__&&/gc) {        } elsif ($$source =~ /\G__&&/gc) {
1602          if ($$source =~ /\G([^&]+)&&__/gc) {          if ($$source =~ /\G([^&]+)&&__/gc) {
1603            $current->append_new_node            $current->append_new_node
# Line 849  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 865  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    
 Function:  
   @Name: to_html  
   @Description:  
     @@@:Converting SuikaWiki/0.9 to Hypertext Markup Language  
     @@lang:en  
   @Main:  
             my (undef, $txt, %option) = @_;  
               
             ## Load constants  
 #           my %const;  
 #           if ($option{magic} =~ /import="([^"]+)"/) {  
 #             for (split /\s*,\s*/, $1) {  
 #               my $wp = $main::database{$_};  
 #               if ($wp =~ m!^\#\?SuikaWikiConst/(?:0.9|1.0)!) {  
 #                 wiki::suikawikiconst::to_hash ($wp => \%const);  
 #               }  
 #             }  
 #           }  
               
 #           $txt =~ s{__&&([^&]+)&&__}{defined $const{$1}?$const{$1}:qq(__&&$1&&__)}ge;  
   
             my (@txt) = split(/\n/, $txt);  
             my (@saved, @result);  
             my $p = $option{-parent}  
                  || Message::Markup::XML::Node->new (type => '#fragment');  
             my $current = $p;  
             my %depth;  
             my $exit_p = sub {  
                   my $current = shift;  
                   if ($current->local_name eq 'p') {  
                     $current = $current->parent_node;  
                   }  
                   $current;  
             };  
             my $cut_anchor = sub {  
               my ($current, $content) = @_;  
                   if ($content =~ s/^\s*\[([0-9]+)\]\s+//) {  
                     my $num = 0 + $1;  
                     for my $A ($current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'a')) {  
                       $A->set_attribute (id => 'anchor-' . $num);  
                       $A->set_attribute (name => 'anchor-' . $num);  
                       $A->set_attribute (class => 'anchor');  
                       $A->append_text ('[' . $num . ']');  
                     }  
                     $current->append_text (' ');  
                   }  
               $content;  
             };  
             my $back_to_section = sub {  
               my $current = shift;  
               while ($current->node_type ne '#fragment') {  
                 if ({ins=>1,del=>1,blockquote=>1}->{$current->local_name}) {  
                   return $current;  
                 }  
                 $current = $current->parent_node;  
               }  
               return $current;  
             };  
               
             foreach (@txt) {  
                 chomp;  
                 if ($depth{block_name}->{$depth{block}} ne 'PRE' && /^\*\*\*\*\*([^\x0D\x0A]*)/) {  
                     $current = &$back_to_section ($current);  
                     for my $H ($current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'h6')) {  
                       $H->append_node (_inline_xml ($1, %option));  
                     }  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^\*\*\*\*([^\x0D\x0A]*)/) {  
                     $current = &$back_to_section ($current);  
                     for my $H ($current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'h5')) {  
                       $H->append_node (_inline_xml ($1, %option));  
                     }  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^\*\*\*([^\x0D\x0A]*)/) {  
                     $current = &$back_to_section ($current);  
                     for my $H ($current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'h4')) {  
                       $H->append_node (_inline_xml ($1, %option));  
                     }  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^\*\*([^\x0D\x0A]*)/) {  
                     $current = &$back_to_section ($current);  
                     for my $H ($current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'h3')) {  
                       $H->append_node (_inline_xml ($1, %option));  
                     }  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^\*([^\x0D\x0A]*)/) {  
                     $current = &$back_to_section ($current);  
                     for my $H ($current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'h2')) {  
                       $H->append_node (_inline_xml ($1, %option));  
                     }  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^([-=]{1,6})(.*)/) {  
                   my ($depth, $content, $type) = (length ($1), $2, (substr ($1, -1) eq '-' ? 'ul' : 'ol'));  
                   $current = &$exit_p ($current);  
                   if ($current->local_name eq 'li') {  
                     if ($depth{list} == $depth && $depth{list_type} eq $type) {  
                       $current = $current->parent_node;  
                     } elsif ($depth <= $depth{list}) {  
                       for (1..($depth{list} - $depth)*2) {  
                         ($depth{list} = 1, last) unless ref $current->parent_node;  
                         ($depth{list} = 1, last) unless {li=>1,ul=>1,ol=>1}->{$current->local_name};  
                         $current = $current->parent_node;  
                         $depth{list} -= 0.5;  
                       }  
                       $current = $current->parent_node;  
                       if ($type ne $current->local_name) {  
                         $current = $current->parent_node->append_new_node (namespace_uri => $NS_XHTML1, local_name => $type);  
                         $current->parent_node->append_text ("\n");  
                       }  
                     } else {    # $depth{list} < $depth  
                       $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => $type);  
                       $current->parent_node->append_text ("\n");  
                       $depth{list}++;  
                     }  
                   } else {  
                     $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => $type);  
                     $current->parent_node->append_text ("\n\n");  
                     $depth{list} = 1;  
                   }  
                   $depth{list_type} = $type;  
                   $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'li');  
                   $current->parent_node->append_text ("\n");  
                   $content = &$cut_anchor ($current, $content);  
                   $current->append_node (_inline_xml ($content, %option));  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^:([^:]+):(.*)/) {  
                   $current = &$exit_p ($current);  
                   if ($current->local_name eq 'dd') {  
                     $current = $current->parent_node;  
                   } else {  
                     $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'dl');  
                   }  
                   $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'dt')  
                           ->append_node (_inline_xml ($1, %option));  
                   $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'dd');  
                   $current->append_node (_inline_xml ($2, %option));  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^(?!>>[0-9])(>{1,5})(.*)/) {  
                   my ($depth, $content) = (length $1, $2);  
                   $current = &$exit_p ($current);  
                   if ($depth == $depth{bq}) {  
                     #  
                   } elsif ($depth{bq} < $depth) {  
                     $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'blockquote');  
                     $depth{bq}++;  
                   } else {      # $depth < $depth{bq}  
                     for (1..($depth{bq}-$depth)) {  
                       last if $current->node_type eq '#fragment';  
                       $current = &$back_to_section ($current->parent_node);  
                     }  
                     $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'blockquote')  
                       unless $current->local_name eq 'blockquote';  
                     $depth{bq} = $depth;  
                   }  
                   if (length $content) {  
                     $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'p');  
                     $current->append_node (_inline_xml ($content, %option));  
                   }  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^\s*$/) {  
                   $current = &$back_to_section ($current);  
                   while ($current->local_name eq 'blockquote') {  
                     $depth{bq}--;  
                     $current = &$back_to_section ($current->parent_node);  
                   }  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^(\s+.*)$/) {  
                   if ($current->local_name ne 'pre') {  
                     $current = &$exit_p ($current)->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'pre');  
                     #$depth{block_name}->{++$depth{block}} = 'pre';  
                   }  
                   $current->append_node (_inline_xml ($1, %option));  
                 } elsif ($depth{block_name}->{$depth{block}} ne 'PRE' && /^\,(.*?)[\x0D\x0A]*$/) {  
                   $current = &$exit_p ($current);  
                   if ($current->local_name eq 'td') {  
                     $current = $current  
                                ->parent_node    # tr  
                                ->parent_node    # tbody  
                                ->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'tr');  
                   } else {  
                     $current = $current  
                                ->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'table')  
                                ->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'tbody')  
                                ->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'tr');  
                   }  
                   $current->parent_node->append_text ("\n");    # </tr>\n  
                   my $tmp = "$1,";  
                   my @value = map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_} ($tmp =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g);  
                   my @colspan = map {($_ eq '==') ? 0 : 1} @value;  
                   my ($tr, $td) = ($current, $current);  
                   for (my $i = 0; $i < @value; $i++) {  
                     if ($colspan[$i]) {  
                       while ($i + $colspan[$i] < @value and $value[$i + $colspan[$i]] eq '==') {  
                         $colspan[$i]++;  
                       }  
                       $td = $tr->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'td');  
                       $td->set_attribute (colspan => $colspan[$i]) if $colspan[$i] > 1;  
                       $td->append_node (_inline_xml ($value[$i], %option));  
                     }  
                   }  
                   if ($td->local_name eq 'tr') {        # No <td/> in the <tr/> (error!)  
                     $td = $tr->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'td');  
                   }  
                   $current = $td;  
                 } elsif (/^\[(INS|DEL|PRE)\[\s*$/) {  
                   if ($depth{block_name}->{$depth{block}} ne 'PRE') {  
                     $current = &$exit_p ($current)->append_new_node (namespace_uri => $NS_XHTML1, local_name => lc $1);  
                     $depth{block}++;  
                     $depth{block_name}->{$depth{block}} = $1;  
                   } else {  
                     $current->append_text ($_);  
                   }  
                 } elsif ($depth{block} && /^\]($depth{block_name}->{$depth{block}})\]\s*$/) {  
                   while ($current->node_type ne '#fragment') {  
                     if ($current->local_name eq lc $depth{block_name}->{$depth{block}}) {  
                       $current = $current->parent_node;  
                       $depth{block}--;  
                       last;  
                     }  
                     $current = $current->parent_node;  
                   }  
                 } else {  
                   if ($current->node_type eq '#fragment' || {ins=>1,del=>1}->{$current->local_name}) {  
                     $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'p');  
                     $current->parent_node->append_text ("\n\n");        # <P> is two <BR>s:-)  
                   }  
                   $current->append_node (_inline_xml (&$cut_anchor ($current, $_), %option));  
                 }  
             }  
             $p;  
   
 Function:  
   @Name: _id_and_name_xml  
   @Main:          
           my ($e, $name) = @_;  
           $e->set_attribute (id => $name);  
           if (SuikaWiki::Plugin->user_agent_names =~ m#Mozilla/[12]\.|Microsoft Internet Explorer#) {  
             $e->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'a')  
               ->set_attribute (name => $name);  
           }  
   
 Function:  
   @Name: _inline_xml  
   @Main:          
           my ($line, %option) = @_;  
           my $l = Message::Markup::XML::Node->new (type => '#fragment');  
           my $current = $l;  
           $line =~ s{(?:\[([A-Z]+)(?:\(([^)]*)\))?\[|(\[\[#form(?:\([A-Za-z0-9-]+\))?(?::'(?:[^'\\]|\\.)*')+\]\]|\[\[[^]]+\](?:>>[0-9]+)?\])|(\]\])|(\] \[)|(>>[0-9]+|<[A-Za-z0-9%]+:[^>]+>|'''?)|([\[\]'<>]|[^\[\]'<>]+))}{  
             my ($el_name, $attr, $lnk, $etag, $nxt, $misc, $s) = ($1, $2, $3, $4, $5, $6, $7);  
             if ($el_name) {  
               my $edef = {  
                 ABBR    => {html_el => 'abbr', use_class_attr => 1},  
                 CODE    => {html_el => 'code', use_class_attr => 1},  
                 DEL     => {html_el => 'del', use_class_attr => 1},  
                 DFN     => {html_el => 'dfn', use_class_attr => 1},  
                 INS     => {html_el => 'ins', use_class_attr => 1},  
                 KBD     => {html_el => 'kbd', use_class_attr => 1},  
                 RUBY    => {html_el => 'ruby'},  
                 RUBYB   => {html_el => 'ruby', html_class => 'descriptive'},  
                 SAMP    => {html_el => 'samp', use_class_attr => 1},  
                 SUB     => {html_el => 'sub'},  
                 SUP     => {html_el => 'sup'},  
                 VAR     => {html_el => 'var', use_class_attr => 1},  
                 WEAK    => {html_el => 'span', html_class => 'weak'},  
               }->{ $el_name };  
               if ($edef) {  
                 $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => $edef->{html_el});  
                 $current->set_attribute (class => $edef->{html_class}) if $edef->{html_class};  
                 $current->get_attribute ('class', make_new_node => 1)  
                         ->append_text ($attr) if $attr && $edef->{use_class_attr};  
                 if ($edef->{html_el} eq 'ruby') {  
                   $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'rb');  
                 }  
               } else {  
                 $current->append_text ($&);  
               }  
             } elsif ($etag) {  
               if (ref $current->parent_node) {  
                 if ($current->node_type eq '#attribute') {  
                   $current = $current->parent_node;  
                 }  
                 $current = $current->parent_node;  
                 if ($current->local_name eq 'ruby') {  
                   $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'rp', value => ')');  
                   $current = $current->parent_node;  
                 }  
               } else {  
                 $current->append_text (']]');  
               }  
             } elsif ($nxt) {  
               my $c_l_n = $current->local_name;  
               if ($c_l_n eq 'rb') {  
                 for ($current->parent_node) {  
                   $_->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'rp', value => '(');  
                   $current = $_->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'rt');  
                 }  
               } elsif ($c_l_n eq 'rt') {  
                 for ($current->parent_node) {  
                   $_->append_text (' ');  
                   $current = $_->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'rt');  
                 }  
               } elsif ($c_l_n eq 'abbr') {  
                 $current = $current->get_attribute ('title', make_new_node => 1);  
               } else {  
                 $current->append_text ('] [');  
               }  
             } elsif ($lnk) {  
               if ($lnk =~ /\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/) {  
                 $current->append_new_node (type => '#xml', value => scalar SuikaWiki::Plugin::WikiFormCore->_make_custom_form ($1, $2, $3, $4, \%option));  
               } elsif ($lnk =~ /\[\[([^]]+)\](?:>>([0-9]+))?\]/) {  
                 my ($page, $anchor) = ($1, $2);  
                 if (substr ($page, 0, 1) eq '#') {  
                   $current->append_new_node (type => '#xml', value => scalar embedded_to_html ($lnk, $option{page}));  
                 } else {  
                   $current->append_node (SuikaWiki::Plugin->module_package ('WikiLinking')->to_wikipage_in_html ({  
                         label   => SuikaWiki::Plugin->resource ('Link:toWikiPage:SourceLabel'),  
                   } => {  
 #TODO:                  base    => [$option{page}],  
                         page_name_relative      => [split m#//#, $page],  
                         page_anchor_no  => 0+$anchor,  
                   }, {o=>$option{o}}));  
                   #$current->append_new_node (type => '#xml', value => scalar main::make_wikilink ($page, anchor => 0+$anchor, base => $option{page}));  
                 }  
               }  
             } elsif ($misc) {  
               if ($misc =~ />>([0-9]+)/) {  
                 for my $A ($current->append_new_node (local_name => 'a', namespace_uri => $NS_XHTML1)) {  
                   $A->set_attribute (href => '#anchor-' . $1);  
                   $A->set_attribute (class => 'wiki-anchor');  
                   $A->append_text ('>>' . $1);  
                 }  
               } elsif ($misc =~ /<([A-Za-z0-9%]+:[^>]+)>/) {    # BUG: <IW:foo:"<foo>"> doesn't match  
                 $current->append_new_node (type => '#xml', value => scalar main::make_urilink ($1));  
               } elsif ($misc eq q('')) {  
                 if ($current->local_name eq 'em') {  
                   $current = $current->parent_node;  
                 } else {  
                   $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'em');  
                 }  
               } else {  # '''  
                 if ($current->local_name eq 'strong') {  
                   $current = $current->parent_node;  
                 } else {  
                   $current = $current->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'strong');  
                 }  
               }  
             } else {  
               $current->append_text ($s);  
             }  
             '';  
           }ge;  
           return $l;  
   
 Function:  
   @Name: embedded_to_html  
   @Main:          
             my ($embedded, $bPage) = @_;  
             my $CommentIndex = SuikaWiki::Plugin->new_index ('sw09--comment');  
             if ($embedded eq '[[#comment]]' or $embedded eq '[[#rcomment]]') {  
               unless ($main::_EMBEDED) {  
                 my $lastmodified = SuikaWiki::Plugin->get_data (lastmodified => [split m!//!, $bPage]);  
                 return <<"EOD";  
                 <form action="@{[SuikaWiki::Plugin->uri ('wiki')]}" method="post" id="x-comment-@{[$CommentIndex]}" class="comment"><p>  
             <input type="hidden" name="mycmd" value="comment" />  
             <input type="hidden" name="mypage" value="@{[SuikaWiki::Plugin->escape($bPage)]}" />  
             <input type="hidden" name="myLastModified" value="$lastmodified" />  
             <input type="hidden" name="mytouch" value="on" />  
             <input type="hidden" name="comment_index" value="$CommentIndex" />  
         \    @{[SuikaWiki::Plugin->resource('WikiForm:WikiComment:Name=',escape=>1)]}  
             <input type="text" name="myname" value="" size="10" class="comment-name" />  
             <input type="text" name="mymsg" value="" size="30" class="comment-msg" />  
             <input type="submit" value="@{[SuikaWiki::Plugin->resource('WikiForm:Add',escape=>1)]}" title="@{[SuikaWiki::Plugin->resource('WikiForm:AddLong',escape=>1)]}" class="comment-submit" />  
         </p></form>  
   EOD  
              } else {  
                 return <<"EOD";  
         <del><form action="@{[SuikaWiki::Plugin->uri ('wiki')]}" method="get">  
             <input type="hidden" name="mycmd" value="default" />  
             <input type="hidden" name="mypage" value="@{[SuikaWiki::Plugin->escape($bPage)]}" />  
          \   @{[SuikaWiki::Plugin->resource('WikiForm:WikiComment:Name=',escape=>1)]}  
             <input type="text" name="myname" value="" size="10" disabled="disabled" />  
             <input type="text" name="mymsg" value="" size="60" disabled="disabled" />  
         </form></del>  
         EOD  
             }  
           } elsif ($embedded =~ /^\[\[\#embed:(.+)\]\]$/) {  
             my ($name, $r) = ($1, '');  
             if ($name =~ s/^IMG://) {  
               my ($magic, $content) = SuikaWiki::Plugin->magic_and_content ($main::database{$name});  
               $r = &main::convert_format ($content, $magic => 'HTML_fragment', page => $name, magic => $magic, -error_no_return => 1);  
               if (defined $r) {  
                 return $r;  
               } else {  
                 return '<span class="error-embed-image">'.SuikaWiki::Plugin->resource ('Embed:ImageNotSupported', escape=>1).'</span>';  
               }  
             } else {  
               if ($main::_EMBEDED != 1) {  
                 my ($cf, $content) = SuikaWiki::Plugin->magic_and_content ($main::database{$name});  
                 $cf ||= '#?SuikaWiki/0.9';  
                 if ($cf =~ m!^#\?SuikaWiki/0.9(?:$|\s)!) {  
                   $main::_EMBEDED = 1;  
                   $r = &text_to_html ($content, magic => $cf, page => $name);  
                   $main::_EMBEDED = 0;  
                 } elsif (length $content) {  
                   $r = "<pre>@{[SuikWiki::Plugin->escape ($content)]}</pre>";  
                 } else {  
                   $r = &text_to_html ("[INS[\n[[$name]]: @{[SuikaWiki::Plugin->resource('Embed:PageNotFound')]}\n]INS]\n", magic => '#?SuikaWiki/0.9');  
                 }  
               } else {  ## nested #EMBED  
                 $r = &text_to_html ("[INS[\n[[$name]]: @{[SuikaWiki::Plugin->resource('Embed:Nested',escape=>1)]}\n]INS]\n", magic => '#?SuikaWiki/0.9');  
               }  
               return qq(<blockquote title="@{[SuikaWiki::Plugin->escape($name)]}" class="wiki-embed">$r<div class="cite-note">¡Ø<cite><a href="@{[SuikaWiki::Plugin->uri ('wiki') . SuikaWiki::Plugin->encode($name)]}" class="wiki">@{[SuikaWiki::Plugin->escape($name)]}</a></cite>¡Ù</div></blockquote>);  
             }  
           } else {  
             return $embedded;  
           }  
   
1638  FormattingRule:  FormattingRule:
1639    @Category[list]: page-link    @Category[list]:
1640        page-link
1641        link-to-resource
1642    @Name: sw09--link-anchor-content    @Name: sw09--link-anchor-content
1643    @Description:    @Description:
1644      @@@:      @@@:
# Line 1292  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
1663      @Link:SuikaWiki/0.9:toResource:SourceLabel:
1664        @@@:
1665          %select_link_resource_scheme (
1666            URI => {<%link-to-it(
1667              label=>{%link-resource-parameters;}p,
1668            );>},
1669            MAIL => {<%link-to-it(
1670              label => {%link-resource-parameters;}p,
1671              description
1672                => {%res (name=>{Link:MailAddress=});<%link-resource-parameters;>}p,
1673            );>},
1674            otherwise => {<%link-to-it(
1675              label => {%sw09--link-anchor-content;}p,
1676              description => {%res (name=>{Link:URIReference=});<%uri-reference;>}p,
1677            );>},
1678          );
1679      @@lang:en      @@lang:en
1680    @Link:SuikaWiki/0.9:toWikiPage:SourceLabel:    @Link:SuikaWiki/0.9:toWikiPage:SourceLabel:
1681      @@@:      @@@:
# Line 1314  Resource: Line 1690  Resource:
1690          );}p,          );}p,
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.2  
changed lines
  Added in v.1.4

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24