add man page, refactor cli, change package.json

This commit is contained in:
Christopher Jeffrey 2012-01-27 15:53:57 -06:00
parent 60f0d2b9f2
commit 623f71a6b9
3 changed files with 64 additions and 34 deletions

View File

@ -2,39 +2,30 @@
/** /**
* Marked CLI * Marked CLI
* Copyright (c) 2011, Christopher Jeffrey (MIT License) * Copyright (c) 2011-2012, Christopher Jeffrey (MIT License)
*/ */
var fs = require('fs') var fs = require('fs')
, util = require('util') , util = require('util')
, marked = require('../'); , marked = require('../');
var usage = function() { var help = function() {
console.log('marked - a markdown parser'); var spawn = require('child_process').spawn;
console.log('');
console.log('Usage:'); var options = {
console.log(' marked [-oih] [input]'); cwd: process.cwd(),
console.log(''); env: process.env,
console.log('Options:'); setsid: false,
console.log(' -o, --output: Specify output file. If none is'); customFds: [0, 1, 2]
console.log(' specified, write to stdout.'); };
console.log(' -i, --input: Specify input file, otherwise use last');
console.log(' argument as input file. If no input'); var man = spawn('man',
console.log(' file is specified, read from stdin.'); [__dirname + '/../man/marked.1'],
console.log(' -t, --tokens: Output a token stream instead of html.'); options);
console.log(' -h, --help: Display this message.');
console.log(''); // man.on('exit', function(code) {
console.log('Examples:'); // if (code !== 0) console.error('no man page');
console.log(' cat in.md | marked > out.html'); // });
console.log(' echo "hello *world*" | marked');
console.log(' marked -o out.html in.md');
console.log(' marked --output="hello world.html" -i in.md');
console.log('');
console.log(' $ marked');
console.log(' > hello __world__\\n^D');
console.log(' <p>hello <strong>world</strong></p>');
console.log('');
process.exit(0);
}; };
var main = function(argv) { var main = function(argv) {
@ -49,7 +40,7 @@ var main = function(argv) {
var arg = argv.shift(); var arg = argv.shift();
arg = arg.split('='); arg = arg.split('=');
if (arg.length > 1) { if (arg.length > 1) {
argv.unshift(arg.sice(1).join('=')); argv.unshift(arg.slice(1).join('='));
} }
return arg[0]; return arg[0];
}; };
@ -71,8 +62,7 @@ var main = function(argv) {
break; break;
case '-h': case '-h':
case '--help': case '--help':
usage(); return help();
break;
default: default:
files.push(arg); files.push(arg);
break; break;

39
man/marked.1 Normal file
View File

@ -0,0 +1,39 @@
.ds q \N'34'
.TH marked 1
.SH NAME
marked \- a javascript markdown parser
.SH SYNOPSIS
.nf
.B marked [\-o output] [\-i input] [\-th]
.fi
.SH DESCRIPTION
.B marked
is a full-featured javascript markdown parser, built for speed. It also includes
multiple GFM features.
.SH OPTIONS
.TP
.BI \-o,\ \-\-output\ [output]
Specify file output. If none is specified, write to stdout.
.TP
.BI \-i,\ \-\-input\ [input]
Specify file input, otherwise use last argument as input file. If no input file
is specified, read from stdin.
.TP
.BI \-t,\ \-\-tokens
Output a token stream instead of html.
.TP
.BI \-h,\ \-\-help
Display help information.
.SH EXAMPLES
.TP
cat in.md | marked > out.html
.TP
echo "hello *world*" | marked
.TP
marked -o out.html in.md
.TP
marked --output="hello world.html" -i in.md
.SH BUGS
Please report any bugs to https://github.com/chjj/marked.
.SH LICENSE
Copyright (c) 2011-2012, Christopher Jeffrey (MIT License)

View File

@ -4,11 +4,12 @@
"author": "Christopher Jeffrey", "author": "Christopher Jeffrey",
"version": "0.1.8", "version": "0.1.8",
"main": "./lib/marked.js", "main": "./lib/marked.js",
"bin": { "marked": "./bin/marked" }, "bin": "./bin/marked",
"man": "./man/marked.1",
"preferGlobal": false,
"repository": "git://github.com/chjj/marked.git", "repository": "git://github.com/chjj/marked.git",
"bugs" : { "homepage": "https://github.com/chjj/marked",
"url": "http://github.com/chjj/marked/issues" "bugs": "http://github.com/chjj/marked/issues",
},
"keywords": [ "markdown", "markup", "html" ], "keywords": [ "markdown", "markup", "html" ],
"tags": [ "markdown", "markup", "html" ] "tags": [ "markdown", "markup", "html" ]
} }