11 |
use HTTP::Date; |
use HTTP::Date; |
12 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
13 |
|
|
14 |
my $max = 5; |
my $max = 999; |
15 |
|
|
16 |
my $page; |
my $page; |
17 |
my $page_date; |
my $page_date; |
42 |
|
|
43 |
$page->{ $name } = [ $data, $date ]; |
$page->{ $name } = [ $data, $date ]; |
44 |
|
|
45 |
|
# strip path from page name |
46 |
|
$name =~ s,^.+/([^/]+)$,$1,; |
47 |
|
push @page_names, $name; |
48 |
|
|
49 |
#warn dump( $ref ); |
#warn dump( $ref ); |
50 |
}, |
}, |
51 |
}, shift @ARGV || '.'); |
}, shift @ARGV || '.'); |
52 |
|
|
53 |
my @pages = ( keys %$page ); |
my @pages = ( keys %$page ); |
54 |
|
|
55 |
warn "found following pages: ", join(", ", @pages),"\n"; |
warn "found following pages: ", join(", ", @page_names),"\n"; |
56 |
|
|
57 |
|
my $page_link_re = '\b(' . join('|', @page_names) . ')\b'; |
58 |
|
|
59 |
my $Rester = Socialtext::Resting->new( |
my $Rester = Socialtext::Resting->new( |
60 |
username => 'tamtam', |
username => 'tamtam', |
70 |
my $level = length($1); |
my $level = length($1); |
71 |
return "\n" . ( '^' x $level ) . " $2\n"; |
return "\n" . ( '^' x $level ) . " $2\n"; |
72 |
} else { |
} else { |
73 |
die "can't parse header: $h"; |
return $h; |
74 |
} |
} |
75 |
} |
} |
76 |
|
|
79 |
return $with . $what . $with; |
return $with . $what . $with; |
80 |
} |
} |
81 |
|
|
82 |
|
sub pre { |
83 |
|
my $text = shift; |
84 |
|
$text =~ s/^{{{//; |
85 |
|
$text =~ s/}}}$//; |
86 |
|
return '.pre' . $text . '.pre'; |
87 |
|
} |
88 |
|
|
89 |
my $count = 0; |
my $count = 0; |
90 |
|
|
91 |
foreach my $name ( keys %$page ) { |
foreach my $name ( keys %$page ) { |
100 |
$body =~ s/''''(.+?)''''/surround('`',$1)/gse; |
$body =~ s/''''(.+?)''''/surround('`',$1)/gse; |
101 |
$body =~ s/'''(.+?)'''/surround('*',$1)/gse; |
$body =~ s/'''(.+?)'''/surround('*',$1)/gse; |
102 |
$body =~ s/''(.+?)''/surround('_',$1)/gse; |
$body =~ s/''(.+?)''/surround('_',$1)/gse; |
103 |
|
$body =~ s/$RE{balanced}{-begin => "{{{"}{-end => "}}}"}{-keep}/pre($1)/gse; |
104 |
|
|
105 |
# fix bullets |
# fix bullets |
106 |
$body =~ s/^\s+([\*])/$1/gm; |
$body =~ s/^\s+([\*])/$1/gm; |
107 |
|
|
108 |
# fix links |
# fix links |
109 |
$body =~ s/\["([^"]+)"\]/[$1]/gs; |
$body =~ s/\["([^"]+)"\]/[$1]/gs; |
110 |
|
$body =~ s,\[(http://\S+)\s+([^\]]+)\],"$2"<$1>,gs; |
111 |
|
$body =~ s,\[(http://[^\]]+)\],$1,gs; |
112 |
|
$body =~ s,$page_link_re,[$1],gs; |
113 |
|
|
114 |
Encode::_utf8_off( $body ); |
Encode::_utf8_off( $body ); |
115 |
|
|