# -*- perl -*- =head1 NAME SuikaWiki::SrcFormat --- SuikaWiki: Data source (input) format supports =cut package SuikaWiki::SrcFormat; use strict; our $VERSION = do{my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; require SuikaWiki::Plugin; sub new ($$) { my ($class, $source) = @_; my $self = bless {}, $class; ($self->{magic}, $self->{content}) = $self->_magic_and_content ($source); if (substr ($self->{magic}, 0, 2) eq '#?') { ## #?Type/Type/Type param="val" my $magic = $self->{magic}; $magic =~ s!^\#\?([0-9A-Za-z_.+-]+(?:/[0-9A-Za-z_.+-]+)*)\s*!!; $self->{type} = [split m!/!, $1]; if ($magic =~ s!([0-9A-Za-z_.+-]+)="((?:[^"]|\\.)+)"\s*!!) { $self->{param}->{$1} = $2; $self->{param}->{$1} =~ s/\\(.)/$1/ge; } } elsif (substr ($self->{magic}, 0, 2) eq '{magic} =~ m!^<\?xml\s!) { $self->{content} = $source; $self->{type} = ['xml']; } else { ## # not defined yet $self->{type} = []; } } else { ## /* Type/Type/Type */ if ($self->{magic} =~ m!([0-9A-Za-z_.+-]+(?:/[0-9A-Za-z_.+-]+)*)\s*!) { $self->{type} = [split m!/!, $1]; } } $self; } sub _magic_and_content ($$) { my ($magic, $page) = ('', $_[1]); $magic = $1 if $page =~ s!^((?:\#\?|/\*|<\?)[^\x02\x0A\x0D]+)[\x02\x0A\x0D]+!!s; ($magic, $page); } sub _get_converter ($%) { my ($self, %o) = @_; my $fmt = SuikaWiki::Plugin->formatter ('format'); for my $i (reverse 0..$#{$self->{type}}) { my $name = join '/', @{$self->{type}}[0..$i]; return $fmt->{$name . '_to_' . $o{to}} if ref $fmt->{$name . '_to_' . $o{to}}; } if ($o{from_default} && !$self->{type}->[0]) { return $fmt->{$o{from_default} . '_to_' . $o{to}} if ref $fmt->{$o{from_default} . '_to_' . $o{to}}; } return undef; } sub convert ($%) { my ($self, %o) = @_; my $converter = $self->_get_converter (%o); if ($converter) { ## obsoleted parameters $o{from} = $self->{type}; $o{magic} = $self->{magic}; $o{content} = $self->{content}; return &$converter ($self, bless (\%o, 'SuikaWiki::Plugin')); } else { my $r = SuikaWiki::Markup::XML->new (namespace_uri => 'http://www.w3.org/1999/xhtml', local_name => 'pre'); $r->append_text ($self->{content}); return $r; } } =back =head1 LICENSE Copyright 2003 Wakaba This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # $Date: 2003/07/19 04:45:55 $