mirror of
https://github.com/erusev/parsedown.git
synced 2024-09-20 03:51:29 +02:00
Add a CLI
- Super simple CLI with the ability to read from files and STDIN. - Add [vendor binary to `composer.json`](https://getcomposer.org/doc/articles/vendor-binaries.md). - Add CLI usage to README. Closes #76.
This commit is contained in:
parent
6ddb6b2b33
commit
1cf48bb582
13
README.md
13
README.md
@ -25,6 +25,19 @@ $Parsedown = new Parsedown();
|
||||
echo $Parsedown->text('Hello _Parsedown_!'); # prints: <p>Hello <em>Parsedown</em>!</p>
|
||||
```
|
||||
|
||||
Or as a command line tool:
|
||||
|
||||
``` bash
|
||||
# from a file
|
||||
./parsedown README.md
|
||||
|
||||
# redirect HTML to a file:
|
||||
./parsedown README.md > README.html
|
||||
|
||||
# or from standard input
|
||||
curl https://raw.githubusercontent.com/erusev/parsedown/master/README.md | ./parsedown
|
||||
```
|
||||
|
||||
More examples in [the wiki](https://github.com/erusev/parsedown/wiki/Usage) and in [this video tutorial](http://youtu.be/wYZBY8DEikI).
|
||||
|
||||
### Questions
|
||||
|
@ -14,5 +14,8 @@
|
||||
],
|
||||
"autoload": {
|
||||
"psr-0": {"Parsedown": ""}
|
||||
}
|
||||
}
|
||||
},
|
||||
"bin": [
|
||||
"parsedown"
|
||||
]
|
||||
}
|
||||
|
24
parsedown
Executable file
24
parsedown
Executable file
@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
require(dirname(__FILE__).'/Parsedown.php');
|
||||
|
||||
// From a file
|
||||
if (isset($argv[1])) {
|
||||
|
||||
if ( ! is_readable($argv[1])) {
|
||||
throw new RuntimeException(sprintf(
|
||||
'Could not read "%s"',
|
||||
$argv[1]
|
||||
));
|
||||
}
|
||||
|
||||
$markdown = file_get_contents($argv[1]);
|
||||
} else {
|
||||
// From standard input
|
||||
$markdown = file_get_contents('php://stdin');
|
||||
}
|
||||
|
||||
$Parsedown = new Parsedown();
|
||||
|
||||
echo $Parsedown->text($markdown);
|
Loading…
Reference in New Issue
Block a user