Changeset 274
- Timestamp:
- 02/03/08 12:46:18 (10 months ago)
- Files:
-
- trunk/src/ingy/Document-Tools/lib/Document/AST.pm (modified) (1 diff)
- trunk/src/ingy/Document-Tools/lib/Document/AST/Tree.pm (modified) (1 diff)
- trunk/src/ingy/Document-Tools/lib/Document/AST/Wikibyte.pm (modified) (2 diffs)
- trunk/src/ingy/Document-Tools/lib/Document/Parser.pm (modified) (3 diffs)
- trunk/src/ingy/Document-Tools/lib/Document/Parser/Creole.pm (modified) (2 diffs)
- trunk/src/ingy/Document-Tools/lib/Document/Viewer/HTML.pm (modified) (2 diffs)
- trunk/src/ingy/Document-Tools/t/data/links (modified) (2 diffs)
- trunk/src/ingy/Document-Tools/t/links_html.t (modified) (1 diff)
- trunk/src/ingy/Document-Tools/t/links_wikibyte.t (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/ingy/Document-Tools/lib/Document/AST.pm
r253 r274 1 1 package Document::AST; 2 use strict; 3 use warnings; 2 4 3 5 sub new { trunk/src/ingy/Document-Tools/lib/Document/AST/Tree.pm
r231 r274 11 11 } 12 12 13 # XXX We changed $_[1] to be a hash instead of a tag. Just FYI... 13 14 sub begin_node { 14 15 push @{$_[0]->{output}}, [$_[1], []]; trunk/src/ingy/Document-Tools/lib/Document/AST/Wikibyte.pm
r254 r274 26 26 sub begin_node { 27 27 my $self = shift; 28 my $tag = shift; 28 my $node = shift; 29 my $tag = $node->{type}; 29 30 $tag =~ s/-.*//; 30 $self->{output} .= "+$tag\n"; 31 my $attributes = _get_attributes($node); 32 $self->{output} .= "+$tag$attributes\n"; 31 33 } 32 34 33 35 sub end_node { 34 36 my $self = shift; 35 my $tag = shift; 37 my $node = shift; 38 my $tag = $node->{type}; 36 39 $tag =~ s/-.*//; 37 40 $self->{output} .= "-$tag\n"; … … 45 48 } 46 49 50 sub _get_attributes { 51 my $node = shift; 52 return "" unless exists $node->{attributes}; 53 return join "", map { 54 qq{ $_="${\ $node->{attributes}->{$_}}"} 55 } sort keys %{$node->{attributes}}; 56 } 57 47 58 1; trunk/src/ingy/Document-Tools/lib/Document/Parser.pm
r273 r274 167 167 sub subparse { 168 168 my ($self, $func, $match, $type, $filter) = @_; 169 my $node_type=169 $match->{type} = 170 170 exists $self->{grammar}{$type}{type} 171 171 ? $self->{grammar}{$type}{type} … … 178 178 # attributes are passed as fields in $match. 179 179 180 # TODO: Modify Makefile.PL to indicate change in API181 180 my $parser = $self->new( 182 181 grammar => $self->{grammar}, … … 186 185 : $match->{text}, 187 186 ); 188 $self->{receiver}->begin_node($ node_type, $match)189 if $ node_type;187 $self->{receiver}->begin_node($match) 188 if $match->{type}; 190 189 $parser->$func($type); 191 190 $self->{receiver}->insert($parser->{receiver}); 192 $self->{receiver}->end_node($ node_type)193 if $ node_type;191 $self->{receiver}->end_node($match) 192 if $match->{type}; 194 193 } 195 194 trunk/src/ingy/Document-Tools/lib/Document/Parser/Creole.pm
r273 r274 1 1 package Document::Parser::Creole; 2 2 use base 'Document::Parser'; 3 use XXX;4 3 5 4 sub create_grammar { … … 113 112 }, 114 113 wikilink => { 115 type => 'a',114 # type => 'a', 116 115 match => qr/\[\[(.*?)\]\]/, 117 116 filter => sub { 118 my $match = shift; 119 if (s/(.*?)\s*\|\s*(.*)/$2/) { 120 $match->{href} = $1; 121 } 117 $_[0]->{attributes}{target} = 118 s/(.*?)\s*\|\s*(.*)/$2/ ? $1 : $_; 122 119 }, 123 120 }, trunk/src/ingy/Document-Tools/lib/Document/Viewer/HTML.pm
r273 r274 39 39 sub begin_node { 40 40 my $self = shift; 41 my $tag = shift;42 41 my $node = shift; 43 if ($tag eq "a") { 42 my $tag = $node->{type}; 43 if ($tag eq "wikilink") { 44 44 $self->{output} .= 45 45 '<a href="' . 46 CGI::Util::escape($node->{ href}) .46 CGI::Util::escape($node->{attributes}{target}) . 47 47 '">'; 48 48 return; … … 57 57 sub end_node { 58 58 my $self = shift; 59 my $tag = shift; 59 my $node = shift; 60 my $tag = $node->{type}; 60 61 $tag =~ s/-.*//; 61 62 return if ($tag =~ /^(br|hr)$/); 63 if ($tag eq "wikilink") { 64 $self->{output} .= '</a>'; 65 return; 66 } 62 67 $self->{output} .= "</$tag>" . 63 68 ($tag =~ /^(p|hr|table|ul|ol|h\d)$/ ? "\n" : ""); trunk/src/ingy/Document-Tools/t/data/links
r273 r274 1 1 === Simple Wiki Link 2 --- creole 3 This is a [[Foo Bar]]. 4 5 --- html 6 <p>This is a <a href="Foo%20Bar">Foo Bar</a>.</p> 7 8 --- wikibyte 9 +p 10 This is a 11 +wikilink target="Foo Bar" 12 Foo Bar 13 -wikilink 14 . 15 -p 16 17 18 === Simple Wiki Link With Label 2 19 --- creole 3 20 This is a [[Link Name|Link Text]]. … … 9 26 +p 10 27 This is a 11 +wikilink href="Link%20Name"28 +wikilink target="Link Name" 12 29 Link Text 13 30 -wikilink 31 . 14 32 -p 33 34 trunk/src/ingy/Document-Tools/t/links_html.t
r273 r274 1 use t::TestDocumentTools tests => 1;1 use t::TestDocumentTools tests => 2; 2 2 3 3 #no_diff;
