GWicke has submitted this change and it was merged.
Change subject: Fix HTML output in several places in ParserService.
......................................................................
Fix HTML output in several places in ParserService.
* Emit base href in /_rt/ output of the server in api/.
- /_rt/* urls had broken image display because of
missing base href in the document header.
* Fix up missing closing tags in a few places.
* Added linebreaks in the output so the html seen via
'View Source' is readable.
* Fixed and verified.
Change-Id: I72140a4b4f69f9982fb457768f7d904a2145735e
---
M js/api/ParserService.js
1 file changed, 35 insertions(+), 17 deletions(-)
Approvals:
GWicke: Verified; Looks good to me, approved
jenkins-bot: Checked
diff --git a/js/api/ParserService.js b/js/api/ParserService.js
index 434fa26..ad5f69d 100644
--- a/js/api/ParserService.js
+++ b/js/api/ParserService.js
@@ -199,9 +199,23 @@
res.send( out, 500 );
return;
}
- res.write('<html><head><script type="text/javascript"
src="/jquery.js"></script><script type="text/javascript"
src="/scrolling.js"></script><style>ins { background: #ff9191; text-decoration:
none; } del { background: #99ff7e; text-decoration: none };
</style></head><body>');
+ res.write('<html><head>\n');
+ res.write('<script type="text/javascript"
src="/jquery.js"></script><script type="text/javascript"
src="/scrolling.js"></script><style>ins { background: #ff9191; text-decoration:
none; } del { background: #99ff7e; text-decoration: none }; </style>\n');
+ // Emit base href so all relative urls resolve properly
+ var headNodes = document.firstChild.firstChild.childNodes;
+ for (var i = 0; i < headNodes.length; i++) {
+ if (headNodes[i].nodeName.toLowerCase() === 'base') {
+ res.write(Util.serializeNode(headNodes[i]));
+ break;
+ }
+ }
+ res.write('</head><body>\n');
res.write( '<h2>Wikitext parsed to HTML DOM</h2><hr>\n' );
- res.write(document.body.innerHTML + '\n<hr>');
+ var bodyNodes = document.body.childNodes;
+ for (var i = 0; i < bodyNodes.length; i++) {
+ res.write(Util.serializeNode(bodyNodes[i]));
+ }
+ res.write('\n<hr>');
res.write( '<h2>HTML DOM converted back to Wikitext</h2><hr>\n'
);
res.write('<pre>' + htmlSpecialChars( out ) + '</pre><hr>\n');
res.write( '<h2>Diff between original Wikitext (green) and
round-tripped wikitext (red)</h2><p>(use shift+alt+n and shift+alt+p to
navigate forward and backward)<hr>\n' );
@@ -210,16 +224,17 @@
//console.log(JSON.stringify( jsDiff.diffLines( out, src ) ));
patch = jsDiff.convertChangesToXML( jsDiff.diffLines( src, out
) );
//patch = jsDiff.convertChangesToXML( refineDiff(
jsDiff.diffLines( src, out ) ) );
- res.write( '<pre>' + patch);
+ res.write( '<pre>\n' + patch + '\n</pre>');
// Add a 'report issue' link
- res.end('<hr><h2>'+
+ res.write('<hr>\n<h2>'+
'<a style="color: red" ' +
'href="http://www.mediawiki.org/w/index.php?title=Talk:Parsoid/Todo' +
- '&action=edit§ion=new&preloadtitle=' +
+
'&action=edit&section=new&preloadtitle=' +
'Issue%20on%20http://parsoid.wmflabs.org' +
req.url + '">' +
'Report a parser issue in this page</a> at ' +
'<a
href="http://www.mediawiki.org/wiki/Talk:Parsoid/Todo">'+
- '[[:mw:Talk:Parsoid/Todo]]</a></h2><hr>');
+ '[[:mw:Talk:Parsoid/Todo]]</a></h2>\n<hr>');
+ res.end('\n</body></html>');
};
new Serializer({env: env}).serializeDOM( document.body,
@@ -255,19 +270,22 @@
app.use(express.bodyParser());
app.get('/', function(req, res){
- res.write('<body><h3>Welcome to the alpha test web service for the ' +
- '<a href="http://www.mediawiki.org/wiki/Parsoid">Parsoid
project<a>.</h3>');
+ res.write('<html><body>\n');
+ res.write('<h3>Welcome to the alpha test web service for the ' +
+ '<a href="http://www.mediawiki.org/wiki/Parsoid">Parsoid
project</a>.</h3>\n');
res.write( '<p>Usage: <ul><li>GET /title for the DOM. ' +
- 'Example: <strong><a href="/en/Main_Page">Main
Page</a></strong>');
- res.write('<li>POST a DOM as parameter "content" to /title for the
wikitext</ul>');
- res.write('<p>There are also some tools for experiments:<ul>');
+ 'Example: <strong><a href="/en/Main_Page">Main
Page</a></strong></li>\n');
+ res.write('<li>POST a DOM as parameter "content" to /title for the
wikitext</li>\n');
+ res.write('</ul>\n');
+ res.write('<p>There are also some tools for experiments:\n<ul>\n');
res.write('<li>Round-trip test pages from the English Wikipedia: ' +
- '<strong><a
href="/_rt/en/Help:Magic">/_rt/Help:Magic</a></strong></li>');
- res.write('<li><strong><a href="/_rtform/">WikiText -> HTML DOM
-> WikiText round-trip form</a></strong></li>');
- res.write('<li><strong><a href="/_wikitext/">WikiText -> HTML DOM
form</a></strong></li>' +
- '<li><strong><a href="/_html/">HTML DOM -> WikiText
form</a></strong></li>');
- res.write('</ul>');
- res.end('<p>We are currently focusing on round-tripping of basic
formatting like inline/bold, headings, lists, tables and links. Templates,
citations and thumbnails are not expected to round-trip properly yet.
<strong>Please report issues you see at <a
href="http://www.mediawiki.org/w/index.php?title=Talk:Parsoid/Todo&action=edit§ion=new">:mw:Talk:Parsoid/Todo</a>.
Thanks!</strong></p>');
+ '<strong><a
href="/_rt/en/Help:Magic">/_rt/Help:Magic</a></strong></li>\n');
+ res.write('<li><strong><a href="/_rtform/">WikiText -> HTML DOM
-> WikiText round-trip form</a></strong></li>\n');
+ res.write('<li><strong><a href="/_wikitext/">WikiText -> HTML DOM
form</a></strong></li>\n');
+ res.write('<li><strong><a href="/_html/">HTML DOM -> WikiText
form</a></strong></li>\n');
+ res.write('</ul>\n');
+ res.write('<p>We are currently focusing on round-tripping of basic
formatting like inline/bold, headings, lists, tables and links. Templates,
citations and thumbnails are not expected to round-trip properly yet.
<strong>Please report issues you see at <a
href="http://www.mediawiki.org/w/index.php?title=Talk:Parsoid/Todo&action=edit§ion=new">:mw:Talk:Parsoid/Todo</a>.
Thanks!</strong></p>\n');
+ res.write('</body></html>');
});
--
To view, visit https://gerrit.wikimedia.org/r/50018
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I72140a4b4f69f9982fb457768f7d904a2145735e
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits