/*\ See [[$:/Macros/MediaWiki]] for usage of this macro. Note: source must always be credited, and thus it's not ideal to use this macro directly. Please use the <> wrapper macro instead, as it provides a link to the source automatically. (This feature is implemented in its own non-JS macro to make at least the URL show on static wiki exports.) \*/ (function(){ "use strict"; exports.name = "MediaWikiEmbedInternal"; exports.params = [ {name: "Article"}, {name: "Domain"}, {name: "Sections"}, ]; exports.run = function(Article, Domain, Sections) { try { let Text; Sections = parseInt(Sections) || 0; Domain = $OcttKB.MediaWiki.MkDomain(Domain); const Req = new XMLHttpRequest(); Req.open('GET', Domain + '/w/api.php?action=query&formatversion=2&prop=extracts&format=json&origin=*&titles=' + Article, false); Req.send(); Text = JSON.parse(Req.responseText).query.pages[0].extract; if (!Text) { Text = '

An error occurred while trying to extract the content. Close and reopen this tiddler to retry, or click the link to open the source in a new tab.

' }; Text = Text.replaceAllTxt('\n', '').replaceAllTxt('

', ''); if (Sections != 0) { for (let i=1; i<=6; i++) { Text = Text.replaceAllTxt(`

`, `

\n`); }; Text = Text.replaceAllTxt(`

`, `

`); //Text = Text.split('').slice(0, Max+1).join(''); //Text = Text.split('

').slice(0, Max+1).join('

'); if (Sections < 0) { Sections = 0; }; Text = Text.split('').slice(0, Sections).join(''); //Text += '

[...]

' }; /* Sections = Sections.split(' '); for (let i=0; i