Cscott has uploaded a new change for review.
https://gerrit.wikimedia.org/r/57398
Change subject: API for a clean conversion from wikitext to parsoid-format HTML.
......................................................................
API for a clean conversion from wikitext to parsoid-format HTML.
Just add 'format=html' to the parameters on your POST if you don't
want the textarea, etc in the response.
Change-Id: I49a3abb34e5c4ccbcfc3e7b41684b8d9adbc1c18
---
M js/api/ParserService.js
1 file changed, 13 insertions(+), 7 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid
refs/changes/98/57398/1
diff --git a/js/api/ParserService.js b/js/api/ParserService.js
index dd711cf..284aa34 100644
--- a/js/api/ParserService.js
+++ b/js/api/ParserService.js
@@ -427,17 +427,23 @@
var parser = Util.getParser(env, 'text/x-mediawiki/full'),
src = req.body.content.replace(/\r/g, '');
parser.on('document', function ( document ) {
- res.write('<pre style="white-space: pre-wrap;
white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap;
word-wrap: break-word;">');
- res.write(htmlSpecialChars(document.body.innerHTML));
- res.write('</pre>');
- res.write('<hr/>');
- res.write(document.body.innerHTML);
- res.write('<hr style="clear:both;"/>Your wikitext:');
- textarea( res, src );
+ if (req.body.format==='html') {
+ res.write(Util.serializeNode(document));
+ } else {
+ res.write('<pre style="white-space: pre-wrap;
white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap;
word-wrap: break-word;">');
+
res.write(htmlSpecialChars(document.body.innerHTML));
+ res.write('</pre>');
+ res.write('<hr/>');
+ res.write(document.body.innerHTML);
+ res.write('<hr style="clear:both;"/>Your
wikitext:');
+ textarea( res, src );
+ }
res.end('');
});
try {
res.setHeader('Content-Type', 'text/html;
charset=UTF-8');
+ // [CSA] allow cross-domain requests (CORS)
+ res.setHeader('Access-Control-Allow-Origin', '*');
console.log('starting parsing of ' + req.params[0]);
// FIXME: This does not handle includes or templates
correctly
env.page.src = src;
--
To view, visit https://gerrit.wikimedia.org/r/57398
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I49a3abb34e5c4ccbcfc3e7b41684b8d9adbc1c18
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits