6 ini_set('display_errors', 'stderr');
8 foreach ($argv as $i => $arg) {
13 if (substr($arg, 0, 1) === '-') {
20 fail('Unknown option: ' . $arg);
28 if (!file_exists($src)) {
29 fail('File not found: ' . $src);
32 $html = file_get_contents($src);
34 $stdin = fopen('php://stdin', 'r');
35 stream_set_blocking($stdin, false);
36 $html = stream_get_contents($stdin);
45 $converter = new League\HTMLToMarkdown\HtmlConverter();
46 echo $converter->convert($html);
49 * Get help and usage info
53 function getHelpText()
58 Usage: html-to-markdown [OPTIONS] [FILE]
60 -h, --help Shows help and usage information
62 If no file is given, input will be read from STDIN
66 Converting a file named document.html:
68 html-to-markdown document.html
70 Converting a file and saving its output:
72 html-to-markdown document.html > output.md
74 Converting from STDIN:
76 echo -e '<h1>Hello World!</h1>' | html-to-markdown
78 Converting from STDIN and saving the output:
80 echo -e '<h1>Hello World!</h1>' | html-to-markdown > output.md
86 * @param string $message Error message
88 function fail($message)
90 fwrite(STDERR, $message . "\n");
94 function requireAutoloader()
96 $autoloadPaths = array(
97 // Local package usage
98 __DIR__ . '/../vendor/autoload.php',
99 // Package was included as a library
100 __DIR__ . '/../../../autoload.php',
102 foreach ($autoloadPaths as $path) {
103 if (file_exists($path)) {