diff --git a/api/ParserService.js b/api/ParserService.js index c3403ebc26..8cd599eec0 100644 --- a/api/ParserService.js +++ b/api/ParserService.js @@ -143,15 +143,18 @@ app.get(/\/_roundtrip\/(.*)/, function(req, res){ tpr.once('src', function ( src ) { var parser = parserPipelineFactory.makePipeline( 'text/x-mediawiki/full' ); parser.on('document', function ( document ) { + res.write(''); var out = new WikitextSerializer({env: env}).serializeDOM( document.body ); - // TODO: diff with original input - var patch = jsDiff.createPatch('wikitext.txt', src, out, 'before', 'after'); - res.write(out); - res.write("\n===================================================================\n"); - res.end(patch); + var patch = jsDiff.convertChangesToXML( jsDiff.diffWords( out, src ) ); + res.write( '

Wikitext parsed to HTML DOM


' ); + res.write(document.body.innerHTML + '
'); + res.write( '

HTML DOM converted back to Wikitext


' ); + res.write('
' + htmlSpecialChars( out ) + '

'); + res.write( '

Diff between original Wikitext (green) and round-tripped wikitext (red)


' ); + res.end( '
' + patch);
 		});
 		try {
-			res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
+			res.setHeader('Content-Type', 'text/html; charset=UTF-8');
 			console.log('starting parsing of ' + req.params[0]);
 			// FIXME: This does not handle includes or templates correctly
 			parser.process( src );