User:Dixtosa/XMLize.js

// Author : Dixtosa // Known users of this script: User:Dixtosa/minorEdits.js

//Lexemes (tags) are: section, category, splitter, interwikis

if (!window.WikiXmlLoaded) {	window.WikiXmlLoaded = true; function doNotInterpertSpecialCharacters(wikitext) {		//making sure some of the ";				let curLevel = (line.split ("=").length - 1) / 2;				if (curLevel >= oldLevel + 2 && oldLevel != 1)				{					curLevel = oldLevel + 1;					//myalert("something wrong in wikitext:\ncurLevel: " + curLevel + ", oldlevel: " + oldLevel + "\nline: " + line);					//return undefined;				}				if (oldLevel >= curLevel) {					wikixml += Array (oldLevel - curLevel + 2).join(" ");				}				oldLevel = curLevel;				let sectionName = line.replace(/=/g, "");				if (oldLevel == 2) //language sections should have underscores for languages like Old_Georgian.					sectionName = sectionName.replace(/ /g, "_");				wikixml += "";				wikixml += " ";					post = "  ";					post = " ";		let curLevel = 2;		if (oldLevel >= curLevel) {			wikixml += Array (oldLevel - curLevel + 2).join(" ");		}		wikixml += " " + interwikis + " "; wikixml += " "; wikixml = $($.parseXML(wikixml)); if (options.wrapTemplate) {			wikixml = wrapTemplate(wikixml); }		return wikixml; };	window.WikiXml.toWikitext = function(wikixml) {		wikixml.find("section").map(function{ 			var This = $(this);			var header = This.attr("class");			var level = parseInt(This.attr("level"));			if (level == 2)				header = header.replace(/_/g, " ");			level = Array(level + 1).join("=");			This.prepend(level + header + level);		}); return wikixml.text; //commenting out as I do not remember what it did - .slice(0, -1); };	//sanity check window.WikiXml.test = function(options) {		try {			var wpTextbox1 = $("#wpTextbox1"); var new_wpTexbox1 = WikiXml.toWikitext(WikiXml.parseWikitext(wpTextbox1.text, options)); if (new_wpTexbox1 != wpTextbox1.text) {				console.log(new_wpTexbox1); throw "mismatch between original and deXMLized XMLized original wikitext\n"; }			myalert("test #N: XMLization works!"); }		catch(e) {			myalert (e); }	};	if (mw.config.values.wgPageName == "User:Dixtosa/XMLize.js/test" && mw.config.values.wgAction == "edit") {		window.WikiXml.test({}); window.WikiXml.test({wrapInterwikis}); window.WikiXml.test({wrapCategory}); } }