Changeset 332
- Timestamp:
- 11/09/06 12:13:20 (2 years ago)
- Files:
-
- library/perl/trunk/Text-Trac (modified) (1 prop)
- library/perl/trunk/Text-Trac/Changes (modified) (1 diff)
- library/perl/trunk/Text-Trac/MANIFEST (modified) (2 diffs)
- library/perl/trunk/Text-Trac/Makefile.PL (modified) (1 diff)
- library/perl/trunk/Text-Trac/inc (added)
- library/perl/trunk/Text-Trac/inc/.author (added)
- library/perl/trunk/Text-Trac/inc/Module (added)
- library/perl/trunk/Text-Trac/inc/Module/AutoInstall.pm (added)
- library/perl/trunk/Text-Trac/inc/Module/Install (added)
- library/perl/trunk/Text-Trac/inc/Module/Install.pm (added)
- library/perl/trunk/Text-Trac/inc/Module/Install/AutoInstall.pm (added)
- library/perl/trunk/Text-Trac/inc/Module/Install/Base.pm (added)
- library/perl/trunk/Text-Trac/inc/Module/Install/Can.pm (added)
- library/perl/trunk/Text-Trac/inc/Module/Install/Fetch.pm (added)
- library/perl/trunk/Text-Trac/inc/Module/Install/Include.pm (added)
- library/perl/trunk/Text-Trac/inc/Module/Install/Makefile.pm (added)
- library/perl/trunk/Text-Trac/inc/Module/Install/Metadata.pm (added)
- library/perl/trunk/Text-Trac/inc/Module/Install/Win32.pm (added)
- library/perl/trunk/Text-Trac/inc/Module/Install/WriteAll.pm (added)
- library/perl/trunk/Text-Trac/lib/TestMacro.pm (deleted)
- library/perl/trunk/Text-Trac/lib/Text/Trac.pm (modified) (5 diffs)
- library/perl/trunk/Text-Trac/lib/Text/Trac/AutoLinkHttp.pm (deleted)
- library/perl/trunk/Text-Trac/lib/Text/Trac/BlockNode.pm (modified) (3 diffs)
- library/perl/trunk/Text-Trac/lib/Text/Trac/Bold.pm (deleted)
- library/perl/trunk/Text-Trac/lib/Text/Trac/BoldItalic.pm (deleted)
- library/perl/trunk/Text-Trac/lib/Text/Trac/Br.pm (deleted)
- library/perl/trunk/Text-Trac/lib/Text/Trac/Context.pm (modified) (1 diff)
- library/perl/trunk/Text-Trac/lib/Text/Trac/Heading.pm (modified) (1 diff)
- library/perl/trunk/Text-Trac/lib/Text/Trac/InlineNode.pm (modified) (1 diff)
- library/perl/trunk/Text-Trac/lib/Text/Trac/Italic.pm (deleted)
- library/perl/trunk/Text-Trac/lib/Text/Trac/LinkResolver (added)
- library/perl/trunk/Text-Trac/lib/Text/Trac/LinkResolver.pm (added)
- library/perl/trunk/Text-Trac/lib/Text/Trac/LinkResolver/Attachment.pm (added)
- library/perl/trunk/Text-Trac/lib/Text/Trac/LinkResolver/Changeset.pm (added)
- library/perl/trunk/Text-Trac/lib/Text/Trac/LinkResolver/Log.pm (added)
- library/perl/trunk/Text-Trac/lib/Text/Trac/LinkResolver/Milestone.pm (added)
- library/perl/trunk/Text-Trac/lib/Text/Trac/LinkResolver/Report.pm (added)
- library/perl/trunk/Text-Trac/lib/Text/Trac/LinkResolver/Source.pm (added)
- library/perl/trunk/Text-Trac/lib/Text/Trac/LinkResolver/Ticket.pm (added)
- library/perl/trunk/Text-Trac/lib/Text/Trac/LinkResolver/Wiki.pm (added)
- library/perl/trunk/Text-Trac/lib/Text/Trac/Macro.pm (modified) (1 diff)
- library/perl/trunk/Text-Trac/lib/Text/Trac/Monospace.pm (deleted)
- library/perl/trunk/Text-Trac/lib/Text/Trac/Ol.pm (modified) (3 diffs)
- library/perl/trunk/Text-Trac/lib/Text/Trac/P.pm (modified) (1 diff)
- library/perl/trunk/Text-Trac/lib/Text/Trac/Strike.pm (deleted)
- library/perl/trunk/Text-Trac/lib/Text/Trac/Sub.pm (deleted)
- library/perl/trunk/Text-Trac/lib/Text/Trac/Sup.pm (deleted)
- library/perl/trunk/Text-Trac/lib/Text/Trac/Table.pm (modified) (1 diff)
- library/perl/trunk/Text-Trac/lib/Text/Trac/TracLinks.pm (deleted)
- library/perl/trunk/Text-Trac/lib/Text/Trac/Ul.pm (modified) (2 diffs)
- library/perl/trunk/Text-Trac/lib/Text/Trac/Underline.pm (deleted)
- library/perl/trunk/Text-Trac/t/01-text-trac.t (modified) (2 diffs)
- library/perl/trunk/Text-Trac/t/02-macros.t (modified) (1 diff)
- library/perl/trunk/Text-Trac/t/03-trac-links.t (modified) (6 diffs)
- library/perl/trunk/Text-Trac/t/04-list.t (added)
- library/perl/trunk/Text-Trac/t/05-disable_links.t (added)
- library/perl/trunk/Text-Trac/t/06-enable_links.t (added)
- library/perl/trunk/Text-Trac/t/07-custom_url.t (added)
- library/perl/trunk/Text-Trac/t/08-regression.t (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
library/perl/trunk/Text-Trac
- Property svn:ignore set to
META.yml
Makefile
Makefile.old
blib
pm_to_blib
*.bak
- Property svn:ignore set to
library/perl/trunk/Text-Trac/Changes
r323 r332 1 1 Revision history for Text-Trac 2 2 3 0.06 Wed Nov 9 4 Fix list handling(Ul.pm and Ol.pm). 5 Refactor inline node parsers wholly. 6 Add supports for TracLinks and WikiMacros. 7 3 8 0.05 Fri Oct 27 4 9 Using Test::Base instead of Test::More in 01-text-trac.t. library/perl/trunk/Text-Trac/MANIFEST
r331 r332 1 1 Changes 2 MANIFEST 3 META.yml # Will be created by "make dist" 4 Makefile.PL 5 README 2 inc/Module/AutoInstall.pm 3 inc/Module/Install.pm 4 inc/Module/Install/AutoInstall.pm 5 inc/Module/Install/Base.pm 6 inc/Module/Install/Can.pm 7 inc/Module/Install/Fetch.pm 8 inc/Module/Install/Include.pm 9 inc/Module/Install/Makefile.pm 10 inc/Module/Install/Metadata.pm 11 inc/Module/Install/Win32.pm 12 inc/Module/Install/WriteAll.pm 6 13 lib/Text/Trac.pm 7 lib/Text/Trac/AutoLinkHttp.pm8 14 lib/Text/Trac/BlockNode.pm 9 15 lib/Text/Trac/Blockquote.pm 10 lib/Text/Trac/BoldItalic.pm11 lib/Text/Trac/Bold.pm12 lib/Text/Trac/Br.pm13 16 lib/Text/Trac/Context.pm 14 17 lib/Text/Trac/Dl.pm … … 16 19 lib/Text/Trac/Hr.pm 17 20 lib/Text/Trac/InlineNode.pm 18 lib/Text/Trac/Italic.pm 19 lib/Text/Trac/Monospace.pm 21 lib/Text/Trac/LinkResolver.pm 22 lib/Text/Trac/LinkResolver/Attachment.pm 23 lib/Text/Trac/LinkResolver/Changeset.pm 24 lib/Text/Trac/LinkResolver/Log.pm 25 lib/Text/Trac/LinkResolver/Milestone.pm 26 lib/Text/Trac/LinkResolver/Report.pm 27 lib/Text/Trac/LinkResolver/Source.pm 28 lib/Text/Trac/LinkResolver/Ticket.pm 29 lib/Text/Trac/LinkResolver/Wiki.pm 30 lib/Text/Trac/Macro.pm 31 lib/Text/Trac/Macro/HelloWorld.pm 32 lib/Text/Trac/Macro/Timestamp.pm 20 33 lib/Text/Trac/Node.pm 21 34 lib/Text/Trac/Ol.pm 22 35 lib/Text/Trac/P.pm 23 36 lib/Text/Trac/Pre.pm 24 lib/Text/Trac/Strike.pm25 lib/Text/Trac/Sub.pm26 lib/Text/Trac/Sup.pm27 37 lib/Text/Trac/Table.pm 28 38 lib/Text/Trac/Text.pm 29 39 lib/Text/Trac/Ul.pm 30 lib/Text/Trac/Underline.pm 31 lib/Text/Trac/Macro.pm 32 lib/Text/Trac/Macro/Timestamp.pm 33 lib/Text/Trac/Macro/HelloWorld.pm 34 lib/Text/Trac/TracLinks.pm 40 Makefile.PL 41 MANIFEST This list of files 42 META.yml 43 README 35 44 t/00-load.t 36 45 t/01-text-trac.t 37 46 t/02-macros.t 38 47 t/03-trac-links.t 48 t/04-list.t 49 t/05-disable_links.t 50 t/06-enable_links.t 51 t/07-custom_url.t 52 t/08-regression.t 39 53 t/boilerplate.t 40 54 t/pod-coverage.t 41 55 t/pod.t 56 t/TestTextTrac.pm library/perl/trunk/Text-Trac/Makefile.PL
r323 r332 1 use strict; 2 use warnings; 3 use ExtUtils::MakeMaker; 1 use inc::Module::Install; 4 2 5 WriteMakefile( 6 NAME => 'Text::Trac', 7 AUTHOR => 'Gosuke Miyashita <gosukenator@gmail.com>', 8 VERSION_FROM => 'lib/Text/Trac.pm', 9 ABSTRACT_FROM => 'lib/Text/Trac.pm', 10 PL_FILES => {}, 11 PREREQ_PM => { 12 'Test::Base' => 0, 13 'UNIVERSAL::require' => 0, 14 'Class::Accessor::Fast' => 0, 15 'Class::Data::Inheritable' => 0, 16 }, 17 dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, 18 clean => { FILES => 'Text-Trac-*' }, 19 ); 3 name('Text-Trac'); 4 all_from('lib/Text/Trac.pm'); 5 6 requires('Test::Base'); 7 requires('UNIVERSAL::require'); 8 requires('Class::Accessor::Fast'); 9 requires('Class::Data::Inheritable'); 10 requires('Tie::IxHash'); 11 requires('List::MoreUtils'); 12 13 no_index( package => 'TestMacro' ); 14 15 auto_include; 16 auto_install; 17 18 WriteAll; library/perl/trunk/Text-Trac/lib/Text/Trac.pm
r328 r332 6 6 use Text::Trac::BlockNode; 7 7 8 our $VERSION = '0.0 5';8 our $VERSION = '0.06'; 9 9 10 10 my %Defaults = ( … … 28 28 my $self = shift; 29 29 my $text = shift or return; 30 31 $self->{trac_url} = '/' unless defined $self->{trac_url}; 32 for ( keys %$self ) { 33 if ( $_ =~ /^trac.+url$/ ) { 34 $self->{$_} .= '/' if $self->{$_} !~ m!/$!; 35 } 36 } 37 30 38 my $c = Text::Trac::Context->new({ 31 text => $text, 32 permalink => $self->{permalink}, 33 min_heading_level => $self->{min_heading_level}, 34 trac_url => $self->{trac_url}, 39 %$self, 40 text => $text, 35 41 }); 36 42 … … 56 62 =head1 VERSION 57 63 58 Version 0.0 564 Version 0.06 59 65 60 66 =head1 SYNOPSIS … … 62 68 use Text::Trac; 63 69 64 my $parser = Text::Trac->new(); 70 my $parser = Text::Trac->new( 71 trac_url => 'http://trac.mizzy.org/public/', 72 disable_links => [ qw( changeset ticket ) ], 73 ); 65 74 66 75 $parser->parse($text); … … 77 86 78 87 Constructs Text::Trac object. 88 89 Available arguments are: 90 91 =over 92 93 =item trac_url 94 95 Base URL for TracLinks.Default is /. You can specify each type of URL individually. 96 Available URLs are: 97 98 =over 99 100 =item trac_attachment_url 101 102 =item trac_changeset_url 103 104 =item trac_log_url 105 106 =item trac_milestone_url 107 108 =item trac_report_url 109 110 =item trac_source_url 111 112 =item trac_ticket_url 113 114 =item trac_wiki_url 115 116 =back 117 118 =item disable_links 119 120 Specify TracLink types you want to disable. 121 All types are enables if you don't specify this option. 122 123 my $parser = Text::Trac->new( 124 disable_links => [ qw( changeset ticket ) ], 125 ); 126 127 =item enable_links 128 129 Specify TracLink types you want to enable.Other types are disabled. 130 You cannot use both disable_links and enable_links at once. 131 132 my $parser = Text::Trac->new( 133 enable_links => [ qw( changeset ticket ) ], 134 ); 135 136 137 =back 79 138 80 139 =head2 parse library/perl/trunk/Text-Trac/lib/Text/Trac/BlockNode.pm
r330 r332 4 4 use base qw( Class::Accessor::Fast Class::Data::Inheritable ); 5 5 use UNIVERSAL::require; 6 use Text::Trac::InlineNode; 6 7 7 8 __PACKAGE__->mk_classdata( 8 9 block_nodes => [ qw( heading hr p ul ol blockquote pre table dl ) ] 9 10 ); 10 __PACKAGE__->mk_classdata( 11 inline_nodes => [ qw( bold_italic bold italic underline monospace strike sup sub br 12 auto_link_http macro trac_links ) ] 13 ); 11 12 #__PACKAGE__->mk_classdata( 13 # inline_nodes => [ qw( bold_italic bold italic underline monospace strike sup sub br 14 # auto_link_http macro trac_links ) ] 15 #); 14 16 __PACKAGE__->mk_classdata( 15 17 block_parsers => [] 16 18 ); 17 __PACKAGE__->mk_classdata( 18 inline_parsers => [] 19 ); 20 __PACKAGE__->mk_accessors( qw( context pattern) ); 19 20 #__PACKAGE__->mk_classdata( 21 # inline_parsers => [] 22 #); 23 24 __PACKAGE__->mk_accessors( qw( context pattern inline_parser ) ); 21 25 22 26 sub new { 23 27 my ( $class, $params ) = @_; 24 my $self = { %$params }; 28 my $self = { 29 %$params, 30 }; 25 31 bless $self, $class; 26 32 $self->init; 33 $self->inline_parser( Text::Trac::InlineNode->new($self->context)); 27 34 return $self; 28 35 } … … 38 45 39 46 $self->block_parsers( $self->_get_parsers('block') ); 40 $self->inline_parsers( $self->_get_parsers('inline') );47 #$self->inline_parsers( $self->_get_parsers('inline') ); 41 48 42 49 while ( defined ( my $l = $c->shiftline ) ) { … … 46 53 } 47 54 } 55 } 56 57 sub replace { 58 my ( $self, $l ) = @_; 59 return $self->inline_parser->parse($l); 48 60 } 49 61 library/perl/trunk/Text-Trac/lib/Text/Trac/Context.pm
r328 r332 6 6 7 7 my %Defaults = ( 8 text => '', 9 html => '', 10 htmllines => [], 11 ul => {}, 12 ol => {}, 13 shift_count => 0, 14 in_block_of => [], 8 text => '', 9 html => '', 10 htmllines => [], 11 ul => {}, 12 ol => {}, 13 shift_count => 0, 14 in_block_of => [], 15 disable_links => [], 16 enable_links => [], 15 17 ); 16 18 library/perl/trunk/Text-Trac/lib/Text/Trac/Heading.pm
r324 r332 18 18 $l = qq(<h$level id="$id">$2</h$level>); 19 19 20 my $parsers = $self->_get_matched_parsers('inline', $l); 21 for ( @{$parsers} ){ 22 $l = $_->parse($l); 23 } 20 $l = $self->replace($l); 24 21 $c->htmllines($l); 25 22 } library/perl/trunk/Text-Trac/lib/Text/Trac/InlineNode.pm
r176 r332 2 2 3 3 use strict; 4 5 use base qw( Class::Accessor::Fast ); 6 __PACKAGE__->mk_accessors( qw( context pattern) ); 4 use Tie::IxHash; 5 use Text::Trac::Macro; 6 use UNIVERSAL::require; 7 use Text::Trac::LinkResolver; 8 9 tie my %token_table, 'Tie::IxHash'; 10 11 #my $handler = $token_table{'!?\\[\\d+\\]|(?:\\b|!)r\\d+\\b(?!:\\d)'}; 12 #$handler->format_link('test'); 13 14 my $link_scheme = '[\w.+-]+'; 15 my $quoted_string = q{'[^']+'|"[^"]+"}; 16 my $shref_target_first = '[\w/?!#@]'; 17 my $shref_target_middle = '(?:\|(?=[^|\s])|[^|<>\s])'; 18 my $shref_target_last = '[a-zA-Z0-9/=]'; 19 my $shref = "!?$link_scheme: 20 (?: 21 $quoted_string 22 |$shref_target_first(?:$shref_target_middle*$shref_target_last)? 23 ) 24 "; 25 26 my $macro = '\[\[[\w/+-]+(?:\(.*\))?\]\]'; 27 28 my $lhref_relative_target = '[/.][^\s[\]]*'; 29 my $lhref = "!?\\[ 30 (?: 31 $link_scheme: 32 (?:$quoted_string|[^\\[\\]\\s]*) 33 |(?:$lhref_relative_target|[^\\[\\]\\s]) 34 ) 35 (?: 36 \\s+ 37 $quoted_string 38 |[^\\]]+ 39 )? 40 \\] 41 "; 42 43 my $img_re = qr/\.(gif|jpg|jpeg|png)(\?.*)?$/i; 44 45 46 my $rules = join '|', ( map { "($_)" } ( keys %token_table ) ); 47 $rules = qr/$rules/x; 48 49 map { $_ =~ s/^\!\?// } ( values %token_table ); 50 map { $_ =~ s/^\\// } ( values %token_table ); 7 51 8 52 sub new { 9 my ( $class, $params ) = @_; 10 my $self = { %$params }; 53 my ( $class, $c ) = @_; 54 55 # external link resolvers 56 my %external_handler; 57 for ( @Text::Trac::LinkResolver::handlers ) { 58 my $class = 'Text::Trac::LinkResolver::' . ucfirst($_); 59 $class->require; 60 my $handler = $class->new($c); 61 $token_table{ $handler->{pattern} } = $handler if defined $handler->{pattern}; 62 $external_handler{$_} = $handler; 63 } 64 65 %token_table = ( 66 q{'''''} => 'bolditalic', 67 q{'''} => 'bold', 68 q{''} => 'italic', 69 '!?__' => 'underline', 70 '!?~~' => 'strike', 71 '!?,,' => 'subscript', 72 '!?\^' => 'superscript', 73 '`|{{{|}}}' => 'inline', 74 $macro => 'macro', 75 %token_table, 76 $lhref => 'lhref', 77 $shref => 'shref', 78 ); 79 80 my $rules = join '|', ( map { "($_)" } ( keys %token_table ) ); 81 $rules = qr/$rules/x; 82 83 map { $_ =~ s/^\!\?// } ( values %token_table ); 84 map { $_ =~ s/^\\// } ( values %token_table ); 85 86 my $self = { 87 context => $c, 88 open_tags => [], 89 rules => $rules, 90 external_handler => \%external_handler, 91 }; 11 92 bless $self, $class; 12 $self->init;13 93 return $self; 14 94 } 15 95 96 sub parse { 97 my ( $self, $l ) = @_; 98 $l =~ s/$self->{rules}/$self->_replace($&, $`, $')/xmseg; 99 return $l; 100 } 101 102 sub _replace { 103 my ( $self, $match, $pre_match, $post_match ) = @_; 104 if ( $match =~ s/^!// ) { 105 return $match; 106 } 107 else { 108 TOKEN: 109 for my $token ( keys %token_table ) { 110 if ( $match =~ /$token/x ) { 111 my $formatter = $token_table{$token}; 112 if ( ref $formatter ) { 113 for ( qw/ log source attachment http / ) { 114 next TOKEN if $match =~ /^\[?$_/; 115 } 116 return $formatter->format_link($match); 117 } 118 else { 119 my $method = "_${formatter}_formatter"; 120 return $self->$method($match, $pre_match, $post_match); 121 } 122 } 123 } 124 } 125 } 126 127 sub _simple_tag_handler { 128 my ( $self, $open_tag, $close_tag ) = @_; 129 130 if ( $self->_is_open($open_tag) ) { 131 $self->_close_tag($open_tag); 132 return $close_tag; 133 } 134 else { 135 $self->_open_tag($open_tag); 136 return $open_tag; 137 } 138 } 139 140 sub _is_open { 141 my ( $self, $tag ) = @_; 142 return grep { $tag eq $_ } @{ $self->{open_tags} }; 143 } 144 145 sub _open_tag { 146 my ( $self, $tag ) = @_; 147 push @{ $self->{open_tags} }, $tag; 148 } 149 150 sub _close_tag { 151 my ( $self, $tag ) = @_; 152 153 my $index = 0; 154 for ( @{ $self->{open_tags} } ) { 155 last if $tag eq $_; 156 $index++; 157 } 158 splice @{ $self->{open_tags} }, $index; 159 } 160 161 sub _bolditalic_formatter { 162 my $self = shift; 163 164 my $is_open = $self->_is_open('<i>'); 165 166 my $tmp; 167 if ( $is_open ) { 168 $tmp .= '</i>'; 169 $self->_close_tag('<i>'); 170 } 171 172 $tmp .= $self->_bold_formatter; 173 174 unless ( $is_open ) { 175 $tmp .= '<i>'; 176 $self->_open_tag('<i>'); 177 } 178 179 return $tmp; 180 } 181 182 sub _bold_formatter { 183 my $self = shift; 184 return $self->_simple_tag_handler('<strong>', '</strong>'); 185 } 186 187 sub _italic_formatter { 188 my $self = shift; 189 return $self->_simple_tag_handler('<i>', '</i>'); 190 } 191 192 sub _underline_formatter { 193 my ( $self, $match, $pre_match, $post_match ) = @_; 194 return $self->_simple_tag_handler('<span class="underline">', '</span>') 195 } 196 197 sub _strike_formatter { 198 my ( $self, $match, $pre_match, $post_match ) = @_; 199 return $self->_simple_tag_handler('<del>', '</del>') 200 } 201 202 sub _superscript_formatter { 203 my ( $self, $match, $pre_match, $post_match ) = @_; 204 return $self->_simple_tag_handler('<sup>', '</sup>') 205 } 206 207 sub _subscript_formatter { 208 my ( $self, $match, $pre_match, $post_match ) = @_; 209 return $self->_simple_tag_handler('<sub>', '</sub>') 210 } 211 212 sub _inline_formatter { 213 my ( $self, $match, $pre_match, $post_match ) = @_; 214 return $self->_simple_tag_handler('<tt>', '</tt>') 215 } 216 217 sub _shref_formatter { 218 my ( $self, $match ) = @_; 219 220 my ( $ns, $target ) = ( $match =~ m/($link_scheme): 221 ( 222 $quoted_string 223 |$shref_target_first 224 (?: 225 $shref_target_middle* 226 $shref_target_last 227 )? 228 ) 229 /x ); 230 return $self->_make_link($ns, $target, $match, $match); 231 } 232 233 sub _lhref_formatter { 234 my ( $self, $match ) = @_; 235 236 my ( $ns, $target, $label ) = 237 ( $match =~ m/\[ 238 ($link_scheme): 239 ( 240 (?:$quoted_string|[^\]\s]*) 241 |(?:$lhref_relative_target|[^\]\s]) 242 ) 243 (?: 244 \s+ 245 ($quoted_string|[^\]]+) 246 )? 247 \] 248 /x ); 249 if ( !$label ) { # e.g. `[http://target]` or `[wiki:target]` 250 if ( $target ) { 251 if ( $target =~ m!^//! ) { 252 $label = $ns . ':' . $target; 253 } 254 else { 255 $label = $target; 256 } 257 } 258 else { # e.g. `[search:]` 259 $label = $ns; 260 } 261 } 262 return $self->_make_link($ns, $target, $match, $label); 263 } 264 265 sub _make_link { 266 my ( $self, $ns, $target, $match, $label ) = @_; 267 if ( $target =~ m!^//! or $target eq 'mailto' ) { 268 return $self->_make_ext_link($ns . ':' . $target, $label); 269 } 270 else { 271 my $handler = $self->{external_handler}->{$ns}; 272 return $handler ? $handler->format_link($match, $target, $label) : $match; 273 } 274 } 275 276 sub _make_ext_link { 277 my ( $self, $url, $text, $title ) = @_; 278 279 my $title_attr = $title ? qq{title="$title"} : ''; 280 281 $title ||= $text; 282 if ( $url =~ $img_re ) { 283 return qq{<img src="$url" alt="$title" />}; 284 } 285 286 my $local = $self->{context}->{local} || ''; 287 if ( $url !~ /^$local/ or !$local ) { 288 return qq{<a class="ext-link" href="$url"$title_attr><span class="icon"></span>$text</a>}; 289 } 290 } 291 292 sub _macro_formatter { 293 my ( $self, $match ) = @_; 294 295 my ( $name, $args ) = ( $match =~ m!\[\[ ([\w/+-]+) (?:\( (.*) \))? \]\]!x ); 296 297 if ( $name =~ /br/i ) { 298 return '<br />'; 299 } 300 else { 301 return Text::Trac::Macro->new->parse($name, $args, $match); 302 } 303 } 304 305 package Text::Trac::InlineNode::Initializer; 306 307 308 16 309 1; library/perl/trunk/Text-Trac/lib/Text/Trac/Macro.pm
r329 r332 1 1 package Text::Trac::Macro; 2 2 use strict; 3 use base qw(Text::Trac::InlineNode );3 use base qw(Text::Trac::InlineNode Class::Accessor::Fast); 4 4 use UNIVERSAL::require; 5 5 use Text::ParseWords qw(quotewords); 6 6 7 sub init { 8 my $self = shift; 9 $self->pattern(qr/\[\[(\w+) (?:\((.+?)\))? \]\]/x); 7 __PACKAGE__->mk_accessors( 'pattern' ); 8 9 sub new { 10 my $class = shift; 11 my $self = {}; 12 bless $self, $class; 10 13 return $self; 11 14 } 12 15 13 16 sub parse { 14 my ( $self, $ l) = @_;17 my ( $self, $name, $args, $match ) = @_; 15 18 my $c = $self->{context}; 16 my $pattern = $self->pattern;17 $l =~ $pattern or return $l;18 19 19 my $macro = $1; 20 my @args = quotewords( ',\s*', 0, $2 ) if $2; 20 my @args = quotewords( ',\s*', 0, $args ) if $args; 21 21 map { s/^\s+|\s+$//g } @args; 22 22 23 foreach my $class ("Text::Trac::Macro::$ macro", $macro) {23 foreach my $class ("Text::Trac::Macro::$name", $name) { 24 24 if ( $class->require ) { 25 my $result = $class->process( $c, @args ) || ''; 26 $l =~ s{$pattern}{$result}xmsg; 25 $match = $class->process( $c, @args ) || ''; 27 26 last; 28 27 } 29 28 } 30 29 31 return $ l;30 return $match; 32 31 } 33 32 library/perl/trunk/Text-Trac/lib/Text/Trac/Ol.pm
r324 r332 18 18 19 19 my $space = length($1); 20 my $level = $c->ol->{level} ;20 my $level = $c->ol->{level} || 0; 21 21 $c->ol->{space} ||= 0; 22 22 … … 39 39 40 40 if ( $space > $c->ol->{space} ){ 41 $l = $start_tag . $l; 42 $level++; 41 for ( 1 .. ( $space + 1 ) / 2 - $level ) { 42 $l = $start_tag . $l; 43 $level++; 44 } 43 45 } 44 46 elsif ( $space < $c->ol->{space} ){ 45 $l = '</ol>' . $l; 46 $level--; 47 for ( 1 .. ( $c->ol->{space} - $space ) / 2 ) { 48 $l = '</ol>' . $l; 49 $level--; 50 } 47 51 } 48 52 … … 62 66 63 67 # parse inline nodes 64 my $parsers = $self->_get_matched_parsers('inline', $l); 65 for ( @{$parsers} ){ 66 $l = $_->parse($l); 67 } 68 68 $l = $self->replace($l); 69 69 $c->htmllines($l); 70 70 library/perl/trunk/Text-Trac/lib/Text/Trac/P.pm
r324 r332 33 33 34 34 # parse inline nodes 35 $parsers = $self->_get_matched_parsers('inline', $l); 36 for ( @{$parsers} ){ 37 $l = $_->parse($l); 38 } 35 #$parsers = $self->_get_matched_parsers('inline', $l); 36 #for ( @{$parsers} ){ 37 # $l = $_->parse($l); 38 #} 39 $l = $self->replace($l); 39 40 $c->htmllines($l); 40 41 } library/perl/trunk/Text-Trac/lib/Text/Trac/Table.pm
r324 r332 25 25 26 26 # parse inline nodes 27 my $inline_parsers = $self->_get_matched_parsers('inline', $l) if $l; 28 for my $parser ( @{$inline_parsers} ){ 29 $l = $parser->parse($l); 30 } 31 27 $l = $self->replace($l); 32 28 $c->htmllines($l); 33 29 } library/perl/trunk/Text-Trac/lib/Text/Trac/Ul.pm
r324 r332 16 16 17 17 my $space = length($1); 18 my $level = $c->ul->{level} ;18 my $level = $c->ul->{level} || 0; 19 19 $c->ul->{space} ||= 0; 20 20 21 21 if ( $space > $c->ul->{space} ) { 22 $l = '<ul>' . $l; 23 $level++; 22 for ( 1 .. ( $space + 1 ) / 2 - $level ) { 23 $l = '<ul>' . $l; 24 $level++; 25 } 24 26 } 25 27 elsif ( $space < $c->ul->{space} ) { 26 $l = '</ul>' . $l; 27 $level--; 28 for ( 1 .. ( $c->ul->{space} - $space ) / 2 ) { 29 $l = '</ul>' . $l; 30 $level--; 31 } 28 32 } 29 33 30 $c->ul({ level => $level, space => $space });34 $c->ul({ level => $level, space => $space }); 31 35 32 36 $l =~ s{ $pattern }{<li>$2</li>}xmsg; … … 43 47 44 48 # parse inline nodes 45 my $parsers = $self->_get_matched_parsers('inline', $l); 46 for ( @{$parsers} ){ 47 $l = $_->parse($l); 48 } 49 49 $l = $self->replace($l); 50 50 $c->htmllines($l); 51 51 library/perl/trunk/Text-Trac/t/01-text-trac.t
r330 r332 217 217 --- expected 218 218 <p> 219 <a class="ext-link" href="http://mizzy.org/"> http://mizzy.org/</a>220 <a class="ext-link" href="http://mizzy.org/"> Title</a>219 <a class="ext-link" href="http://mizzy.org/"><span class="icon"></span>http://mizzy.org/</a> 220 <a class="ext-link" href="http://mizzy.org/"><span class="icon"></span>Title</a> 221 221 </p> 222 222 … … 323 323 </dl> 324 324 325 ### unknown short link 326 --- input 327 unknown:target 328 --- expected 329 <p> 330 unknown:target 331 </p> 332 333 ### unknown long link 334 --- input 335 [unknown:target label] 336 --- expected 337 <p> 338 [unknown:target label] 339 </p> library/perl/trunk/Text-Trac/t/02-macros.t
r328 r332 45 45 [[TheUnknownMacro]] 46 46 </p> 47 48 ### macros outside of Text::Trac::Macro:: are ok too49 --- input50 [[TestMacro]]51 --- expected52 <p>53 testing, testing, one, two, three...54 </p>55 library/perl/trunk/Text-Trac/t/03-trac-links.t
r330 r332 11 11 --- expected 12 12 <p> 13 <a class=" newticket" href="http://trac.mizzy.org/public/ticket/1">#1</a>13 <a class="ticket" href="http://trac.mizzy.org/public/ticket/1">#1</a> 14 14 </p> 15 15 … … 19 19 --- expected 20 20 <p> 21 <a class=" newticket" href="http://trac.mizzy.org/public/ticket/1">ticket:1</a>21 <a class="ticket" href="http://trac.mizzy.org/public/ticket/1">ticket:1</a> 22 22 </p> 23 23 … … 43 43 --- expected 44 44 <p> 45 <a class=" newticket" href="http://trac.mizzy.org/public/ticket/1">1</a>45 <a class="ticket" href="http://trac.mizzy.org/public/ticket/1">1</a> 46 46 </p> 47 47 … … 51 51 --- expected 52 52 <p> 53 <a class=" newticket" href="http://trac.mizzy.org/public/ticket/1">ticket 1</a>53 <a class="ticket" href="http://trac.mizzy.org/public/ticket/1">ticket 1</a> 54 54 </p> 55 55 … … 243 243 ### wiki link test 2 244 244 --- input 245 wiki:trac_links 246 --- expected 247 <p> 248 <a class="wiki" href="http://trac.mizzy.org/public/wiki/trac_links">wiki:trac_links</a> 249 </p> 250 251 ### wiki link test 3 252 --- input 253 !TracLinks 254 --- expected 255 <p> 256 TracLinks 257 </p> 258 259 ### wiki link test 4 260 --- input 261 !wiki:TracLinks 262 --- expected 263 <p> 245 264 wiki:TracLinks 246 --- expected247 <p>248 <a class="wiki" href="http://trac.mizzy.org/public/wiki/TracLinks">wiki:TracLinks</a>249 </p>250 251 ### wiki link test 3252 --- input253 !TracLinks254 --- expected255 <p>256 TracLinks257 </p>258 259 ### wiki link test 4260 --- input261 !wiki:TracLinks262 --- expected263 <p>264 wiki:TracLinks265 265 </p> 266 266 … … 419 419 420 420 ### source link test 8 421 --- input 421 --- inputx 422 422 !source:trunk/COPYING#200 423 423 --- expected
