-
Notifications
You must be signed in to change notification settings - Fork 0
/
html-to-md.pl
54 lines (48 loc) · 1.22 KB
/
html-to-md.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
#!/usr/bin/perl
my ($title);
my ($url) = $ARGV[0];
my ($tflag) = 1;
$url =~ s!/mnt/cephfs/ie-web/ie/!!;
$url =~ s!index.html!!;
$url =~ s/%([0-9A-Fa-f]{2})/pack('C', hex($1))/ge;
while (<>) {
if (/\<title\>(.*)\<\/title\>/) {
next if (! $tflag);
$tflag = 0;
$title = $1;
$title =~ s/\&\#8211\;/-/g;
$title =~ s/\&\#8212\;/—/g;
$title =~ s/\<\;/</g;
$title =~ s/\>\;/>/g;
$title =~ s/\&smp\;/&/g;
$title =~ s/\ \;//g;
print <<"EOFEOF";
---
title: "$title"
url: /ja/$url
paginate: 0
---
EOFEOF
print "# $title\n\n";
}
if (/\<section class\=\"wrapper wrap-detail-page\"\>|\<main id=\"main\" class=\"post-main-content\" role=\"main\"\>/ .. /\<div id=\"wp-browsing-history-title\" style\="display\:none\;\"\>/) {
next if (/wp-browsing-history-title/);
if (/\<h2\>(.*)\<\/h2\>/) {
print "\n# $1\n\n";
} else {
s/\<li\>/- /g;
s/\&\#8211\;/-/g;
s/\&\#8212\;/—/g;
s/\<\;/</g;
s/\>\;/>/g;
s/\&smp\;/&/g;
s/\ \;//g;
if (s/\<a href=\"([^"]*?)\"[^>]*?\>(.*?)\<\/a\>/[$2]($1)/) {
s/%([0-9A-Fa-f]{2})/pack('C', hex($1))/ge;
}
s/\<img[^>]* src=\"([^"]*?)\"[^>]*?\>/![image]($1)/;
s/\<[^\>]*\>//g;
print;
}
}
}