forked from curl/everything-curl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uni.pl
executable file
·56 lines (48 loc) · 1.01 KB
/
uni.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl
my $sum = shift @ARGV;
# Figure out all files in right order
open(F, "<$sum");
while(<F>) {
if($_ =~ /\]\(([^\)]*)\)/) {
my $file = $1;
push @files, $1;
}
}
close(F);
sub dirname {
my ($path) = @_;
if($path =~ /(.*)\//) {
return "$1/";
}
return "";
}
sub include {
my ($f) = @_;
my $line;
open(M, "<$f") || return;
my $dir = dirname($f);
print "\n";
while(<M>) {
$line++;
# strip out links to markdown files
$_ =~ s/\[([^]]*)\]\(.*\.md(|\#(.*))\)/$1/g;
# add path to image links
$_ =~ s/^!\[(.*)\]\(([^)]*)\)/![$1]($dir$2)/g;
if($_ =~ /\]\(.*\.md/) {
print STDERR "$f:$line:line-split markdown link\n";
print STDERR "$_";
$errors++;
}
if($_ =~ /谭/) {
# skip unicode letter pandoc does not like
}
else {
print $_;
}
}
close(M);
}
for my $f (@files) {
include($f);
}
exit $errors;