Changeset 273
- Timestamp:
- 02/03/08 01:32:04 (10 months ago)
- Files:
-
- trunk/src/ingy/Document-Tools/lib/Document/Parser.pm (modified) (2 diffs)
- trunk/src/ingy/Document-Tools/lib/Document/Parser/Creole.pm (modified) (4 diffs)
- trunk/src/ingy/Document-Tools/lib/Document/Viewer/HTML.pm (modified) (4 diffs)
- trunk/src/ingy/Document-Tools/t/data/hr (added)
- trunk/src/ingy/Document-Tools/t/data/links (added)
- trunk/src/ingy/Document-Tools/t/data/lists (modified) (1 diff)
- trunk/src/ingy/Document-Tools/t/hr_html.t (added)
- trunk/src/ingy/Document-Tools/t/links_html.t (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/ingy/Document-Tools/lib/Document/Parser.pm
r255 r273 98 98 my $container_type = shift; 99 99 my $types = $self->{grammar}{$container_type}{phrases}; 100 while ( length $self->{input}) {100 while ($self->{input} and length $self->{input}) { 101 101 my $match; 102 102 for my $type (@$types) { … … 171 171 ? $self->{grammar}{$type}{type} 172 172 : $type; 173 $self->{receiver}->begin_node($node_type) 174 if $node_type; 173 # The matched text gets passed to &$filter as $_. In most cases, 174 # this will be enough. However, $match is also passed as a parameter 175 # to &$filter. This allows us to pass more structured data to the 176 # receiver. For example, you might use this when parsing links in 177 # WikiText, where the link text is passed as $_ and additional 178 # attributes are passed as fields in $match. 179 180 # TODO: Modify Makefile.PL to indicate change in API 175 181 my $parser = $self->new( 176 182 grammar => $self->{grammar}, 177 183 receiver => $self->{receiver}->new, 178 184 input => $filter 179 ? do { $_ = $match->{text}; &$filter( ); $_ }185 ? do { $_ = $match->{text}; &$filter($match); $_ } 180 186 : $match->{text}, 181 187 ); 188 $self->{receiver}->begin_node($node_type, $match) 189 if $node_type; 182 190 $parser->$func($type); 183 191 $self->{receiver}->insert($parser->{receiver}); trunk/src/ingy/Document-Tools/lib/Document/Parser/Creole.pm
r272 r273 1 1 package Document::Parser::Creole; 2 2 use base 'Document::Parser'; 3 use XXX; 3 4 4 5 sub create_grammar { … … 9 10 10 11 my $all_phrases = [ 11 'b', 'i', 'tt', 'br', 12 'b', 'i', 'tt', 'br', 'wikilink', 12 13 ]; 13 14 … … 94 95 }, 95 96 hr => { 96 match => qr/ \ *----\*\n/,97 match => qr/^ *----\s*\n/, 97 98 }, 98 99 … … 111 112 match => qr/\\\\/, 112 113 }, 114 wikilink => { 115 type => 'a', 116 match => qr/\[\[(.*?)\]\]/, 117 filter => sub { 118 my $match = shift; 119 if (s/(.*?)\s*\|\s*(.*)/$2/) { 120 $match->{href} = $1; 121 } 122 }, 123 }, 124 113 125 }; 114 126 } trunk/src/ingy/Document-Tools/lib/Document/Viewer/HTML.pm
r268 r273 4 4 5 5 use base 'Document::AST'; 6 use CGI::Util; 6 7 7 8 #sub view { … … 30 31 } 31 32 33 sub uri_escape { 34 $_ = shift; 35 s/ /\%20/g; 36 return $_; 37 } 38 32 39 sub begin_node { 33 40 my $self = shift; 34 41 my $tag = shift; 35 $tag =~ s/-.*//; 36 $self->{output} .= "<$tag>"; 42 my $node = shift; 43 if ($tag eq "a") { 44 $self->{output} .= 45 '<a href="' . 46 CGI::Util::escape($node->{href}) . 47 '">'; 48 return; 49 } 50 # XXX For tables. 51 # $tag =~ s/-.*//; 52 $self->{output} .= ($tag =~ /^(br|hr)$/) 53 ? "<$tag />\n" 54 : "<$tag>"; 37 55 } 38 56 … … 41 59 my $tag = shift; 42 60 $tag =~ s/-.*//; 43 $self->{output} .= "</$tag>"; 61 return if ($tag =~ /^(br|hr)$/); 62 $self->{output} .= "</$tag>" . 63 ($tag =~ /^(p|hr|table|ul|ol|h\d)$/ ? "\n" : ""); 44 64 } 45 65 … … 47 67 my $self = shift; 48 68 my $text = shift; 49 $text =~ s/\n/\n /g;50 69 $self->{output} .= "$text"; 51 70 } trunk/src/ingy/Document-Tools/t/data/lists
r270 r273 14 14 -li 15 15 -ul 16 --- html chomp 17 <ul><li>Item one.<ul><li>Subitem one.</li></ul></li></ul> 16 --- html 17 <ul><li>Item one.<ul><li>Subitem one.</li></ul> 18 </li></ul> 18 19 === Sublists are well formed XHTML 19 20 --- creole
