Changeset 223
- Timestamp:
- 04/08/07 01:10:15 (2 years ago)
- Files:
-
- trunk/src/core/Spork/lib/Spork/Emitter/HTML.pm (modified) (3 diffs)
- trunk/src/plugins/ingy/Document-Formatter/lib/Document/AST.pm (modified) (4 diffs)
- trunk/src/plugins/ingy/Document-Formatter/lib/Document/AST/Tree.pm (modified) (1 diff)
- trunk/src/plugins/ingy/Document-Formatter/lib/Document/Parser.pm (modified) (1 diff)
- trunk/test/spork-parser.t (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/core/Spork/lib/Spork/Emitter/HTML.pm
r203 r223 1 1 package Spork::Emitter::HTML; 2 2 use strict; 3 #use XXX;3 use XXX; 4 4 5 5 sub new { bless { output => '' }, shift } … … 35 35 for my $node (@$ast) { 36 36 if (ref $node) { 37 my ($key ) = keys %$node;37 my ($key, $value) = @$node; 38 38 $self->{output} .= $tags{"+$key"}; 39 39 $self->{parent} = $key; 40 $self->emit($ node->{$key});40 $self->emit($value); 41 41 $self->{output} .= $tags{"-$key"}; 42 42 next; … … 44 44 my $text = $node; 45 45 unless ($self->{parent} eq 'pre') { 46 $text =~ s/^( *)/" " x length($1)/gem;46 $text =~ s/^( +)/" " x length($1)/gem; 47 47 $text =~ s/\n/<br \/>\n/g; 48 48 } trunk/src/plugins/ingy/Document-Formatter/lib/Document/AST.pm
r218 r223 3 3 sub new { 4 4 my $class = shift; 5 return bless { output => [], @_ }, ref($class) || $class; 5 my $self = bless { @_ }, ref($class) || $class; 6 } 7 8 sub init { 9 my $self = shift; 10 die "You need to override Document::AST::insert"; 11 # $self->{output} = []; 6 12 } 7 13 … … 14 20 my $self = shift; 15 21 my $ast = shift; 16 die ;22 die "You need to override Document::AST::insert"; 17 23 # $self->{output} .= $ast->{output}; 18 24 } … … 21 27 my $self = shift; 22 28 my $tag = shift; 23 die ;29 die "You need to override Document::AST::begin_node"; 24 30 # $self->{output} .= "+$tag\n"; 25 31 } … … 28 34 my $self = shift; 29 35 my $tag = shift; 30 die ;36 die "You need to override Document::AST::end_node"; 31 37 # $self->{output} .= "-$tag\n"; 32 38 } trunk/src/plugins/ingy/Document-Formatter/lib/Document/AST/Tree.pm
r218 r223 2 2 use base 'Document::AST'; 3 3 4 sub init { 5 my $self = shift; 6 $self->{output} = []; 7 } 8 4 9 sub insert { 5 my $self = shift; 6 my $ast = shift; 7 my $new = $ast->{output}; 8 my $current = $self->{output}[-1]; 9 my ($key) = keys %$current; 10 push @{$current->{$key}}, @$new; 10 push @{$_[0]{output}[-1][-1]}, @{$_[1]->{output}}; 11 11 } 12 12 13 13 sub begin_node { 14 my $self = shift; 15 push @{$self->{output}}, {shift, []}; 14 push @{$_[0]->{output}}, [$_[1], []]; 16 15 } 17 16 18 17 sub text_node { 19 my $self = shift; 20 push @{$self->{output}}, shift; 18 push @{$_[0]->{output}}, $_[1]; 21 19 } 22 20 trunk/src/plugins/ingy/Document-Formatter/lib/Document/Parser.pm
r221 r223 17 17 my $self = shift; 18 18 $self->{input} ||= shift; 19 $self->{grammar} ||= $self->set_grammar; 19 20 $self->{ast} ||= $self->set_ast; 20 $self->{ grammar} ||= $self->set_grammar;21 $self->{ast}->init; 21 22 $self->parse_blocks('top'); 22 my $ast = $self->{ast}->content; 23 delete $self->{ast}; 24 return $ast; 23 return $self->{ast}->content; 25 24 } 26 25 trunk/test/spork-parser.t
r218 r223 1 1 #!/usr/bin/perl 2 2 use lib 'lib'; 3 use Test::Base tests => 1;3 use Test::Base tests => 2; 4 4 use Spork::Parser; 5 5 use Spork::Emitter::HTML; … … 14 14 15 15 __DATA__ 16 === ParseSpork Slide16 === Format Spork Slide 17 17 --- spork format 18 18 == This is a test … … 46 46 </ul> 47 47 </div></div> 48 <p>Cool <b>stuff</b> is <i>here</i>.</p>48 <p>Cool <b>stuff</b> is <i>here</i>.</p> 49 49 <p>xxx<br /> 50 50 xxx</p> … … 59 59 } 60 60 </pre> 61 === Format Another Spork Slide 62 --- spork format 63 This is *bold* 64 65 This *bold* is 66 67 *Bold* is this 68 --- html 69 <p>This is <b>bold</b></p> 70 <p>This <b>bold</b> is</p> 71 <p><b>Bold</b> is this</p> 72
