summaryrefslogtreecommitdiff
path: root/resources/src/mediawiki.api/mediawiki.api.parse.js
blob: bc3d44f946750a3e59415f7d07873fd44cc91f5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
 * @class mw.Api.plugin.parse
 */
( function ( mw, $ ) {

	$.extend( mw.Api.prototype, {
		/**
		 * Convenience method for 'action=parse'.
		 *
		 * @param {string} wikitext
		 * @return {jQuery.Promise}
		 * @return {Function} return.done
		 * @return {string} return.done.data Parsed HTML of `wikitext`.
		 */
		parse: function ( wikitext ) {
			var apiPromise = this.get( {
				action: 'parse',
				contentmodel: 'wikitext',
				text: wikitext
			} );

			return apiPromise
				.then( function ( data ) {
					return data.parse.text[ '*' ];
				} )
				.promise( { abort: apiPromise.abort } );
		}
	} );

	/**
	 * @class mw.Api
	 * @mixins mw.Api.plugin.parse
	 */

}( mediaWiki, jQuery ) );