mediawiki-extensions-Visual.../modules/parser/parse.js

35 lines
803 B
JavaScript
Raw Normal View History

/**
* Command line wikidom parse utility.
* Read from STDIN, write to STDOUT.
*/
( function() {
var ParserPipeline = require('./mediawiki.parser.js').ParserPipeline,
ParserEnv = require('./mediawiki.parser.environment.js').MWParserEnvironment,
optimist = require('optimist');
var parser = new ParserPipeline( new ParserEnv({}) );
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('');
parser.parse( input );
var output = parser.getWikiDom();
process.stdout.write( output );
// add a trailing newline for shell user's benefit
process.stdout.write( "\n" );
process.exit(0);
} );
} )();