contentmodel: 'wikitext'
}, additionalParams );
- if ( typeof content === 'string' ) {
- // Wikitext
- config.text = content;
- } else {
- // mw.Title
+ if ( mw.Title && content instanceof mw.Title ) {
+ // Parse existing page
config.page = content.getPrefixedDb();
+ } else {
+ // Parse wikitext from input
+ config.text = String( content );
}
apiPromise = this.get( config );
} ) );
QUnit.test( 'Hello world', function ( assert ) {
- QUnit.expect( 2 );
+ QUnit.expect( 3 );
var api = new mw.Api();
api.parse( '\'\'\'Hello world\'\'\'' ).done( function ( html ) {
- assert.equal( html, '<p><b>Hello world</b></p>' );
+ assert.equal( html, '<p><b>Hello world</b></p>', 'Parse wikitext by string' );
+ } );
+
+ api.parse( {
+ toString: function () {
+ return '\'\'\'Hello world\'\'\'';
+ }
+ } ).done( function ( html ) {
+ assert.equal( html, '<p><b>Hello world</b></p>', 'Parse wikitext by toString object' );
} );
this.server.respondWith( /action=parse.*&text='''Hello\+world'''/, function ( request ) {
} );
api.parse( new mw.Title( 'Earth' ) ).done( function ( html ) {
- assert.equal( html, '<p><b>Earth</b> is a planet.</p>' );
+ assert.equal( html, '<p><b>Earth</b> is a planet.</p>', 'Parse page by Title object' );
} );
this.server.respondWith( /action=parse.*&page=Earth/, function ( request ) {