From 547df2219ab4b870256f2ed90e36b97d8bf200bf Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Tue, 23 May 2017 00:32:11 +0200 Subject: Replace Mardownify library with html-to-markdown library. --- .../league/html-to-markdown/bin/html-to-markdown | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100755 vendor/league/html-to-markdown/bin/html-to-markdown (limited to 'vendor/league/html-to-markdown/bin') diff --git a/vendor/league/html-to-markdown/bin/html-to-markdown b/vendor/league/html-to-markdown/bin/html-to-markdown new file mode 100755 index 000000000..2815a7cef --- /dev/null +++ b/vendor/league/html-to-markdown/bin/html-to-markdown @@ -0,0 +1,108 @@ +#!/usr/bin/env php + $arg) { + if ($i === 0) { + continue; + } + + if (substr($arg, 0, 1) === '-') { + switch ($arg) { + case '-h': + case '--help': + echo getHelpText(); + exit(0); + default: + fail('Unknown option: ' . $arg); + } + } else { + $src = $argv[1]; + } +} + +if (isset($src)) { + if (!file_exists($src)) { + fail('File not found: ' . $src); + } + + $html = file_get_contents($src); +} else { + $stdin = fopen('php://stdin', 'r'); + stream_set_blocking($stdin, false); + $html = stream_get_contents($stdin); + fclose($stdin); + + if (empty($html)) { + fail(getHelpText()); + } +} + + +$converter = new League\HTMLToMarkdown\HtmlConverter(); +echo $converter->convert($html); + +/** + * Get help and usage info + * + * @return string + */ +function getHelpText() +{ + return << output.md + + Converting from STDIN: + + echo -e '

Hello World!

' | html-to-markdown + + Converting from STDIN and saving the output: + + echo -e '

Hello World!

' | html-to-markdown > output.md + +HELP; +} + +/** + * @param string $message Error message + */ +function fail($message) +{ + fwrite(STDERR, $message . "\n"); + exit(1); +} + +function requireAutoloader() +{ + $autoloadPaths = array( + // Local package usage + __DIR__ . '/../vendor/autoload.php', + // Package was included as a library + __DIR__ . '/../../../autoload.php', + ); + foreach ($autoloadPaths as $path) { + if (file_exists($path)) { + require_once $path; + break; + } + } +} -- cgit v1.2.3