-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.min.js
1 lines (1 loc) · 2.71 KB
/
plugin.min.js
1
tinymce.PluginManager.requireLangPack("syntaxHighlight");tinymce.PluginManager.add("syntaxHighlight",function(d,c){var g={},f="html",e=false,b=false;function a(){var k=d.selection,o=d.dom,h=k.getContent(),m,l,j;g={};m=[{text:"Choose Language",value:"0"},{text:"BASH",value:"bash"},{text:"C / C++",value:"c"},{text:"C#",value:"csharp"},{text:"CSS",value:"css"},{text:"DIFF",value:"diff"},{text:"HTML",value:"html"},{text:"Java",value:"java"},{text:"JavaScript",value:"js"},{text:"Perl",value:"perl"},{text:"PHP",value:"php"},{text:"Python",value:"py"},{text:"Ruby",value:"ruby"},{text:"Text",value:"text"},{text:"SQL",value:"sql"},{text:"XML",value:"XML"}];l=m.length;e=k.getNode();try{g=JSON.parse('{"'+o.getAttrib(e,"class").replace(/first-line/g,"firstLine").replace(/: /g,'": "').replace(/; /g,'","').replace(/"true"/g,"true").replace(/"false"/g,"false").replace(/"\[/g,"[").replace(/\]"/g,"]")+"}")}catch(n){g={brush:f,gutter:true,firstLine:1,highlight:[]}}if(e.nodeName=="BODY"&&h.length==0){b=false}else{if(e.nodeName=="PRE"){b=true;g.codebox=o.getParent(e).textContent.replace(/\<\;/g,"<").replace(/\>\;/g,">")}else{b=true;if(e.nodeName=="BODY"){e=k.getSelectedBlocks();g.codebox=h.replace(/<br \/>/g,"\r\n").replace(/(<[^>]*>)/g,"").replace(/ /g,"")}else{e=o.getParent(e);g.codebox=o.getParent(e).textContent.replace(/<br \/>/g,"\r\n").replace(/\<\;/g,"<").replace(/\>\;/g,">")}}}for(j=0;j<l;j++){if(m[j].value==g.brush){m[j].selected=true}}d.windowManager.open({title:"Syntax Highlighter",data:g,body:[{name:"Language",type:"listbox",values:m,onselect:function(){g.brush=this.value()}},{type:"container",layout:"flex",direction:"row",align:"center",spacing:5,items:[{type:"label",text:"Start :"},{name:"firstLine",type:"textbox",tooltip:"Start number"},{type:"label",text:"Highlights :"},{name:"highlight",type:"textbox",tooltip:"Highlights Help"},{type:"checkbox",checked:g.gutter,text:"Show Numbers",onclick:function(){g.gutter=this.value()}}]},{name:"codebox",type:"textbox",minHeight:250,multiline:true}],onsubmit:function(t){var r,p,q,i,s;r=t.data.codebox.replace(/</g,"<").replace(/>/g,">");p=t.data.highlight.replace(/[^0-9,\-]/g,"");q=t.data.firstLine.replace(/[^0-9]/g,"");i=g.brush;s=g.gutter;if(q==""){q=1}if(b==true){setTimeout(function(){d.dom.remove(e)},0)}setTimeout(function(){d.insertContent('<pre style="background-color: #353535; color: #fff; margin: 5px 0; padding: 10px;" class="brush: '+i+"; gutter: "+s+"; first-line: "+q+"; highlight: ["+p+']">'+r+"</pre>",{format:"raw"})},0)}})}d.addButton("syntaxHighlight",{image:c+"/img/syntaxHighlight.gif",tooltip:"Insert Code",onclick:function(){a()}});d.addMenuItem("syntaxHighlight",{text:"code",image:c+"/img/syntaxHighlight.gif",context:"insert",onclick:function(){a()}})});