--- tamtam/tamtam2socialtext.pl 2007/12/12 13:17:15 8 +++ tamtam/tamtam2socialtext.pl 2007/12/12 14:10:37 12 @@ -11,11 +11,13 @@ use HTTP::Date; use Data::Dump qw/dump/; -my $max = 5; +my $max = 999; my $page; my $page_date; +my @page_names; + find({ wanted => sub { my $path = $File::Find::name; @@ -40,13 +42,19 @@ $page->{ $name } = [ $data, $date ]; + # strip path from page name + $name =~ s,^.+/([^/]+)$,$1,; + push @page_names, $name; + #warn dump( $ref ); }, }, shift @ARGV || '.'); my @pages = ( keys %$page ); -warn "found following pages: ", join(", ", @pages),"\n"; +warn "found following pages: ", join(", ", @page_names),"\n"; + +my $page_link_re = '\b(' . join('|', @page_names) . ')\b'; my $Rester = Socialtext::Resting->new( username => 'tamtam', @@ -62,7 +70,7 @@ my $level = length($1); return "\n" . ( '^' x $level ) . " $2\n"; } else { - die "can't parse header: $h"; + return $h; } } @@ -71,6 +79,13 @@ return $with . $what . $with; } +sub pre { + my $text = shift; + $text =~ s/^{{{//; + $text =~ s/}}}$//; + return '.pre' . $text . '.pre'; +} + my $count = 0; foreach my $name ( keys %$page ) { @@ -85,9 +100,17 @@ $body =~ s/''''(.+?)''''/surround('`',$1)/gse; $body =~ s/'''(.+?)'''/surround('*',$1)/gse; $body =~ s/''(.+?)''/surround('_',$1)/gse; + $body =~ s/$RE{balanced}{-begin => "{{{"}{-end => "}}}"}{-keep}/pre($1)/gse; + # fix bullets $body =~ s/^\s+([\*])/$1/gm; + # fix links + $body =~ s/\["([^"]+)"\]/[$1]/gs; + $body =~ s,\[(http://\S+)\s+([^\]]+)\],"$2"<$1>,gs; + $body =~ s,\[(http://[^\]]+)\],$1,gs; + $body =~ s,$page_link_re,[$1],gs; + Encode::_utf8_off( $body ); my @tags = ( 'TamTam' );