2011-12-28 01:37:06 +00:00
|
|
|
/**
|
|
|
|
* Command line wikidom parse utility.
|
|
|
|
* Read from STDIN, write to STDOUT.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
( function() {
|
|
|
|
|
2012-01-04 08:39:45 +00:00
|
|
|
var ParserPipeline = require('./mediawiki.parser.js').ParserPipeline,
|
2011-12-28 01:37:06 +00:00
|
|
|
optimist = require('optimist');
|
|
|
|
|
2012-01-04 08:39:45 +00:00
|
|
|
var parser = new ParserPipeline();
|
2011-12-28 01:37:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
process.stdin.resume();
|
|
|
|
process.stdin.setEncoding('utf8');
|
|
|
|
|
|
|
|
var inputChunks = [];
|
|
|
|
process.stdin.on( 'data', function( chunk ) {
|
|
|
|
inputChunks.push( chunk );
|
|
|
|
} );
|
|
|
|
|
|
|
|
process.stdin.on( 'end', function() {
|
|
|
|
var input = inputChunks.join('');
|
2012-01-04 08:39:45 +00:00
|
|
|
parser.parse( input );
|
|
|
|
var output = parser.getWikiDom();
|
2011-12-28 01:37:06 +00:00
|
|
|
process.stdout.write( output );
|
2012-01-04 08:42:53 +00:00
|
|
|
// add a trailing newline for shell user's benefit
|
|
|
|
process.stdout.write( "\n" );
|
2011-12-28 01:37:06 +00:00
|
|
|
process.exit(0);
|
|
|
|
} );
|
|
|
|
|
|
|
|
} )();
|