r109699 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109698‎ | r109699 | r109700 >
Date:22:42, 21 January 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Add some commandline switches to parse.js. Supports switching on/off debug
mode and a selection of html/WikiDom serialization.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/parse.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/parse.js
@@ -6,13 +6,25 @@
77 * @author Gabriel Wicke <gwicke@wikimedia.org>
88 */
99
 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');
1014
1115 ( 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;
1228
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');
1729
1830 var env = new ParserEnv( {
1931 // fetch templates from enwiki by default..
@@ -20,7 +32,7 @@
2133 wgScriptExtension: ".php",
2234 fetchTemplates: true,
2335 // enable/disable debug output using this switch
24 - debug: false
 36+ debug: argv.debug
2537 } ),
2638 parser = new ParserPipeline( env );
2739
@@ -38,18 +50,17 @@
3951 process.stdin.on( 'end', function() {
4052 var input = inputChunks.join('');
4153 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 ),
4356 // Serialize the WikiDom with indentation
4457 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+ }
4663 // add a trailing newline for shell user's benefit
4764 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 - }
5465 process.exit(0);
5566 });
5667 // Kick off the pipeline by feeding the input into the parser pipeline

Status & tagging log