-
Notifications
You must be signed in to change notification settings - Fork 0
/
html2markdown.php
39 lines (28 loc) · 1.03 KB
/
html2markdown.php
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
<?php
echo "\n";
if (isset($argv[1])){
$path = $argv[1];
$glob = array_merge(glob($path.'/*.html'), glob($path.'/*/*.html'), glob($path.'/*/*/*.html'));
if (empty($glob)){
echo 'Sorry, HTML not found.'."\n";
exit(1);
}
foreach ($glob as $key => $value) {
$pathinfo = pathinfo($value);
$html = $pathinfo['dirname'].'/'.$pathinfo['filename'].'.md';
$cmd = 'html2text '.$value.' sjis > '.$html;
exec($cmd, $opt, $return);
if ($return === 0){
file_put_contents($html, str_replace('.html', '.md', file_get_contents($html)));
echo 'Successful convert '.$value."\n".
' --> '.$html."\n\n";
} else {
echo 'Failed to convert '.$value."\n".
' --> '.$html."\n\n";
}
}
echo 'Comverted.'."\n";
} else {
echo 'Sorry, Not Args.'."\n";
}
echo "\n";