Merge "Whitelist the <wbr> element."
[mediawiki.git] / resources / mediawiki.api / mediawiki.api.parse.js
blob08bb17130b272fd69cd4d6eca9d8443a03e514d5
1 /**
2  * @class mw.Api.plugin.parse
3  */
4 ( function ( mw, $ ) {
6         $.extend( mw.Api.prototype, {
7                 /**
8                  * Convinience method for 'action=parse'.
9                  *
10                  * @param {string} wikitext
11                  * @param {Function} [ok] Success callback (deprecated)
12                  * @param {Function} [err] Error callback (deprecated)
13                  * @return {jQuery.Promise}
14                  * @return {Function} return.done
15                  * @return {string} return.done.data Parsed HTML of `wikitext`.
16                  */
17                 parse: function ( wikitext, ok, err ) {
18                         var d = $.Deferred(),
19                                 apiPromise;
20                         // Backwards compatibility (< MW 1.20)
21                         d.done( ok );
22                         d.fail( err );
24                         apiPromise = this.get( {
25                                         action: 'parse',
26                                         contentmodel: 'wikitext',
27                                         text: wikitext
28                                 } )
29                                 .done( function ( data ) {
30                                         if ( data.parse && data.parse.text && data.parse.text['*'] ) {
31                                                 d.resolve( data.parse.text['*'] );
32                                         }
33                                 } )
34                                 .fail( d.reject );
36                         return d.promise( { abort: apiPromise.abort } );
37                 }
38         } );
40         /**
41          * @class mw.Api
42          * @mixins mw.Api.plugin.parse
43          */
45 }( mediaWiki, jQuery ) );