Snazzy html word diff for roundtrip view

Also show the HTML DOM, Wikitext output and diff.

Change-Id: Ibe744fbc895239f4e48f6e0e2f2b2f345c0845bd
This commit is contained in:
Gabriel Wicke 2012-06-03 01:36:56 +02:00
parent 4cf74497b7
commit 7c18891504

View file

@ -143,15 +143,18 @@ app.get(/\/_roundtrip\/(.*)/, function(req, res){
tpr.once('src', function ( src ) { tpr.once('src', function ( src ) {
var parser = parserPipelineFactory.makePipeline( 'text/x-mediawiki/full' ); var parser = parserPipelineFactory.makePipeline( 'text/x-mediawiki/full' );
parser.on('document', function ( document ) { parser.on('document', function ( document ) {
res.write('<html><head><style>del { background: #ff9191; text-decoration: none; } ins { background: #99ff7e; text-decoration: none }; </style></head><body>');
var out = new WikitextSerializer({env: env}).serializeDOM( document.body ); var out = new WikitextSerializer({env: env}).serializeDOM( document.body );
// TODO: diff with original input var patch = jsDiff.convertChangesToXML( jsDiff.diffWords( out, src ) );
var patch = jsDiff.createPatch('wikitext.txt', src, out, 'before', 'after'); res.write( '<h2>Wikitext parsed to HTML DOM</h2><hr>' );
res.write(out); res.write(document.body.innerHTML + '<hr>');
res.write("\n===================================================================\n"); res.write( '<h2>HTML DOM converted back to Wikitext</h2><hr>' );
res.end(patch); res.write('<pre>' + htmlSpecialChars( out ) + '</pre><hr>');
res.write( '<h2>Diff between original Wikitext (green) and round-tripped wikitext (red)</h2><hr>' );
res.end( '<pre>' + patch);
}); });
try { 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]); console.log('starting parsing of ' + req.params[0]);
// FIXME: This does not handle includes or templates correctly // FIXME: This does not handle includes or templates correctly
parser.process( src ); parser.process( src );