mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
support for stdin
This commit is contained in:
parent
b433d7cd50
commit
4c529f83f0
|
@ -34,6 +34,9 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha ./test/run.js"
|
"test": "mocha ./test/run.js"
|
||||||
},
|
},
|
||||||
|
"bin": {
|
||||||
|
"showdown": "src/cli.js"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"angular": "^1.3.2",
|
"angular": "^1.3.2",
|
||||||
"grunt": "^0.4.5",
|
"grunt": "^0.4.5",
|
||||||
|
|
|
@ -1,16 +1,23 @@
|
||||||
var Showdown = require('./showdown');
|
var Showdown = require('./showdown');
|
||||||
|
var cli = require('cli');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
var converter = new Showdown.converter();
|
var converter = new Showdown.converter();
|
||||||
|
|
||||||
|
/*
|
||||||
|
If an argument is given, treat it as the file to be read.
|
||||||
|
Otherwise, read from stdin.
|
||||||
|
*/
|
||||||
if(process.argv.length > 2) {
|
if(process.argv.length > 2) {
|
||||||
fs.readFile(process.argv[2], function(err, data) {
|
fs.readFile(process.argv[2], function(err, data) {
|
||||||
if(err) {
|
if(err) {
|
||||||
console.log("Error: Invalid file");
|
console.error("Error: Invalid file");
|
||||||
} else {
|
} else {
|
||||||
console.log(converter.makeHtml(data.toString()));
|
console.log(converter.makeHtml(data.toString()));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
console.log("Error: No file given");
|
cli.withStdin(function(data) {
|
||||||
|
this.output(converter.makeHtml(data.toString()));
|
||||||
|
})
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user