Debian Codegraph @

resources/src/mediawiki.api/parse.js

raw symbols SCIP
1 ( function () {
2
3 Object.assign( mw.Api.prototype, /** @lends mw.Api.prototype */ {
4 /**
5 * Convenience method for 'action=parse'.
6 *
7 * @param {string|mw.Title} content Content to parse, either as a wikitext string or
8 * a mw.Title.
9 * @param {Object} additionalParams Parameters object to set custom settings, e.g.
10 * `redirects`, `sectionpreview`. `prop` should not be overridden.
11 * @return {jQuery.Promise<string>} Promise that resolves with the parsed HTML of `wikitext`
12 */
13 parse: function ( content, additionalParams ) {
14 const config = Object.assign( {
15 formatversion: 2,
16 action: 'parse',
17 // Minimize the JSON we get back, there is no way to access anything else anyway
18 prop: 'text',
19 contentmodel: 'wikitext'
20 }, additionalParams );
21
22 let apiPromise;
23 if ( mw.Title && content instanceof mw.Title ) {
24 // Parse existing page
25 config.page = content.getPrefixedDb();
26 apiPromise = this.get( config );
27 } else {
28 // Parse wikitext from input
29 config.text = String( content );
30 apiPromise = this.post( config );
31 }
32
33 return apiPromise
34 .then( ( data ) => data.parse.text )
35 .promise( { abort: apiPromise.abort } );
36 }
37 } );
38
39 }() );