User:Ais523/formatedit.js

// addOnloadHook(function  {  if(document.getElementById('wpTextbox1')!=null)  {    var ef=document.getElementById('editform');    ef.innerHTML=      "Preview"+      ef.innerHTML;  } }); function alternatetag(b,s,t) { var i=1; var a=b.split(s); while(i"); for(i in a) if(a[i].indexOf("")!=-1) {   var b=""; while(a[i].indexOf("")!=0) {      b+="&#"+a[i].charCodeAt(0)+";"; a[i]=a[i].substr(1); }   a[i]=b+a[i].substr(9); } a=a.join(""); // Temporarily transform all plus signs to (+(*)+). a=a.split("+").join("(+(*)+)"); // Process comments a=a.split("")!=-1) a[i]=a[i].substr(a[i].indexOf("-->")+3); a=a.join("");  // Process bold and italic (parsing bold first to prevent it being read as ')  a=alternatetag(a,"'","B");  a=alternatetag(a,"","I");  // Line breaks  a=a.split("\r\n").join("\n");  a=a.split("\n\r").join("\n");  a=a.split("\r").join("\n");  a=a.split("\n\n").join("(+(BR /)+)\n"); //to work within a pre tag  // 'Safe' tags; this list copied from m:Help:HTML in wikitext revision 426235  var safetags=new Array( "b","big","blockquote","br","caption","center","cite","code","dd","div","dl","dt", "em","font","h1","h2","h3","h4","h5","h6","hr","i","li","ol","p","pre","rb","rp", "rt","ruby","s","small","strike","strong","sub","sup","table","td","th","tr","tt", "u","ul","var"); // Safe tags with no arguments:  //   Opening  for(i in safetags) a=a.split("<"+safetags[i]+">").join("(+("+safetags[i]+")+)");  //   Closing  for(i in safetags) a=a.split("").join("(+(/"+safetags[i]+")+)");  //   Self-closing  for(i in safetags) a=a.split("<"+safetags[i]+" />").join("(+("+safetags[i]+" /)+)");  for(i in safetags) a=a.split("<"+safetags[i]+"/>").join("(+("+safetags[i]+" /)+)");  // Internal wikilinks  a=a.split("");  for(i in a) if(a[i].indexOf("")!=-1)  {    var b='(+(a href="/wiki/';    if(a[i].indexOf("|")1)    { //piped      b+=encodeURI(a[i].substr(0,a[i].indexOf("|")));      a[i]=a[i].substr(a[i].indexOf("|")+1);      b+='")+)';      b+=a[i].substr(0,a[i].indexOf("]]"));    }    else    { //not piped      b+=encodeURI(a[i].substr(0,a[i].indexOf("]]")));      b+='")+)';      b+=a[i].substr(0,a[i].indexOf("]]")); }   a[i]=b+"(+(/a)+)"+a[i].substr(a[i].indexOf("]]")+2); } a=a.join(""); // Lists: ol, ul, dl, written with wikimarkup a=a.split("\n"); var liststack=new Array; var listtypes=new Array; var listitems=new Array; listtypes['*']="ul"; listtypes['#']="ol"; listtypes[':']="dl"; listtypes[';']="dl"; listitems['*']="li"; listitems['#']="li"; listitems[':']="dd"; listitems[';']="dt"; var lsl=0; var temp; var litype=''; for(i in a) { temp=0; litype=''; if(a[i].substr(0,1)!="*"&&a[i].substr(0,1)!=":"&&      a[i].substr(0,1)!="#"&&a[i].substr(0,1)!=";") while(lsl>0) a[i-1]+="(+(/"+listtypes[liststack[--lsl]]+")+)"; while(a[i].substr(0,1)=="*"||a[i].substr(0,1)==":"||         a[i].substr(0,1)=="#"||a[i].substr(0,1)==";") {     if(liststack[temp]==a[i].substr(0,1)&&temptemp) a[i-1]+="(+(/"+listtypes[liststack[--lsl]]+")+)"; liststack[temp++]=a[i].substr(0,1); a[i-1]+="(+("+listtypes[a[i].substr(0,1)]+")+)"; }     litype=listitems[a[i].substr(0,1)]; a[i]=a[i].substr(1); }   while(lsl>temp) a[i-1]+="(+(/"+listtypes[liststack[--lsl]]+")+)"; lsl=temp; if(litype!='') a[i]='(+('+litype+')+)'+a[i]+'(+(/'+litype+')+)'; } // pre on lines starting with a space (a is still split into lines) temp=0; for(i in a) { if(a[i].substr(0,1)==' '&&temp==0) {temp=1; a[i-1]+="(+(pre)+)";} else if(a[i].substr(0,1)!=' '&&temp==1) {temp=0; a[i-1]+="(+(/pre)+)";} } a=a.join("\n"); // Escape all unparsed HTML. a=a.split("<").join("&lt;").split(">").join("&gt;"); // Convert the ++ markers into tags. a=a.split("(+(").join("<").split(")+)").join(">"); // Finally, transform lone + signs back. a=a.split("<*>").join("+"); fef.innerHTML=a; } // /* Tests

This is not WikiMarkup, but this is.

italicbothboldnormal same line as last line

There was a comment earlier this line.

Some examples of 'safe' tags are em s tt, but a is dangerous.


 * a
 * b
 * c
 * d
 * e
 * f
 * g


 * h
 * i
 * j


 * k
 * l

Example of Wikimarkup: * This is a bulleted list End of Wikimarkup example

User:ais523 Sandbox the