Index: trunk/extensions/VisualEditor/modules/parser/parse.js |
— | — | @@ -6,13 +6,25 @@ |
7 | 7 | * @author Gabriel Wicke <gwicke@wikimedia.org> |
8 | 8 | */ |
9 | 9 | |
| 10 | +var ParserPipeline = require('./mediawiki.parser.js').ParserPipeline, |
| 11 | + ParserEnv = require('./mediawiki.parser.environment.js').MWParserEnvironment, |
| 12 | + DOMConverter = require('./mediawiki.DOMConverter.js').DOMConverter, |
| 13 | + optimist = require('optimist'); |
10 | 14 | |
11 | 15 | ( function() { |
| 16 | + var argv = optimist.usage( 'Usage: $0', { |
| 17 | + 'html': { |
| 18 | + description: 'Produce html output instead of WikiDom', |
| 19 | + 'boolean': true, |
| 20 | + 'default': false |
| 21 | + }, |
| 22 | + 'debug': { |
| 23 | + description: 'Debug mode', |
| 24 | + 'boolean': true, |
| 25 | + 'default': false |
| 26 | + } |
| 27 | + }).argv; |
12 | 28 | |
13 | | - var ParserPipeline = require('./mediawiki.parser.js').ParserPipeline, |
14 | | - ParserEnv = require('./mediawiki.parser.environment.js').MWParserEnvironment, |
15 | | - DOMConverter = require('./mediawiki.DOMConverter.js').DOMConverter, |
16 | | - optimist = require('optimist'); |
17 | 29 | |
18 | 30 | var env = new ParserEnv( { |
19 | 31 | // fetch templates from enwiki by default.. |
— | — | @@ -20,7 +32,7 @@ |
21 | 33 | wgScriptExtension: ".php", |
22 | 34 | fetchTemplates: true, |
23 | 35 | // enable/disable debug output using this switch |
24 | | - debug: false |
| 36 | + debug: argv.debug |
25 | 37 | } ), |
26 | 38 | parser = new ParserPipeline( env ); |
27 | 39 | |
— | — | @@ -38,18 +50,17 @@ |
39 | 51 | process.stdin.on( 'end', function() { |
40 | 52 | var input = inputChunks.join(''); |
41 | 53 | parser.on('document', function ( document ) { |
42 | | - var wikiDom = new DOMConverter().HTMLtoWiki( document.body ), |
| 54 | + if ( ! argv.html ) { |
| 55 | + var wikiDom = new DOMConverter().HTMLtoWiki( document.body ), |
43 | 56 | // Serialize the WikiDom with indentation |
44 | 57 | output = JSON.stringify( wikiDom, null, 2 ); |
45 | | - process.stdout.write( output ); |
| 58 | + process.stdout.write( output ); |
| 59 | + } else { |
| 60 | + // Print out the html |
| 61 | + process.stdout.write( document.body.innerHTML ); |
| 62 | + } |
46 | 63 | // add a trailing newline for shell user's benefit |
47 | 64 | process.stdout.write( "\n" ); |
48 | | - |
49 | | - if ( env.debug ) { |
50 | | - // Also print out the html |
51 | | - process.stderr.write( document.body.innerHTML ); |
52 | | - process.stderr.write( "\n" ); |
53 | | - } |
54 | 65 | process.exit(0); |
55 | 66 | }); |
56 | 67 | // Kick off the pipeline by feeding the input into the parser pipeline |