Changeset 244


Ignore:
Timestamp:
May 4, 2006, 5:04:22 PM (14 years ago)
Author:
nick
Message:

Create a parent for Formatters that work on Wiki Links

Location:
wiki-toolkit/trunk/lib/Wiki/Toolkit/Formatter
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Formatter/Default.pm

    r235 r244  
    33use strict;
    44
    5 use vars qw( $VERSION @_links_found );
     5use vars qw( $VERSION @ISA @_links_found );
    66$VERSION = '0.02';
     7
     8use Wiki::Toolkit::Formatter::WikiLinkFormatterParent;
    79
    810use CGI ":standard";
     
    1012use Text::WikiFormat as => 'wikiformat';
    1113use HTML::PullParser;
     14
     15@ISA = qw( Wiki::Toolkit::Formatter::WikiLinkFormatterParent );
    1216
    1317=head1 NAME
     
    136140}
    137141
    138 =item B<rename_links>
    139 
    140   $formatter->rename_links( $from, $to, $content );
    141 
    142 Renames all the links to a certain page in the supplied content.
    143 (Obviously this is dependent on object properties such as
    144 C<extended_links> etc.)
    145 
    146 =cut
    147 
    148 sub rename_links {
    149     my ($self, $from, $to, $content) = @_;
    150 
    151         # If we support extended (square bracket) links, update those
    152         if($self->{_extended_links}) {
    153                 $content =~ s/\[$from\]/\[$to\]/g;
    154                 $content =~ s/\[$from(\s*|.*?)\]/\[$to$1\]/g;
    155         }
    156 
    157         # If we support implicit (camelcase) links, update those
    158         if($self->{_implicit_links}) {
    159                 $content =~ s/\b$from\b/$to/g;
    160                 $content =~ s/^$from\b/$to/gm;
    161                 $content =~ s/\b$from$/$to/gm;
    162         }
    163 
    164         return $content;
    165 }
    166 
    167 =item B<find_internal_links>
    168 
    169   my @links_to = $formatter->find_internal_links( $content );
    170 
    171 Returns a list of all nodes that the supplied content links to.
    172 (Obviously this is dependent on object properties such as
    173 C<extended_links> etc.)
    174 
    175 =cut
    176 
    177 sub find_internal_links {
    178     my ($self, $raw) = @_;
    179 
    180     @_links_found = ();
    181 
    182     my $foo = wikiformat($raw,
    183                         { link => sub {
    184                                         my ($link, $opts) = @_;
    185                                         $opts ||= {};
    186                                         my $title;
    187                                         ($link, $title) = split(/\|/, $link, 2)
    188                                                 if $opts->{extended};
    189                                         push @Wiki::Toolkit::Formatter::Default::_links_found,
    190                                                 $link;
    191                                         return ""; # don't care about output
    192                                 }
    193                         },
    194                         {
    195                                 extended       => $self->{_extended_links},
    196                                 prefix         => $self->{_node_prefix},
    197                                 implicit_links => $self->{_implicit_links}
    198                         }
    199         );
    200 
    201     my @links = @_links_found;
    202     @_links_found = ();
    203     return @links;
    204 }
    205 
    206142=back
    207143
    208144=head1 SEE ALSO
    209145
     146L<Wiki::Toolkit::Formatter::WikiLinkFormatterParent>
    210147L<Wiki::Toolkit>
    211148
Note: See TracChangeset for help on using the changeset viewer.