/** * tinymce/js/tinymce/plugins/perlmonks/plugin.js * 2014-12-14-16:41:12 * based on * tinymce/js/tinymce/plugins/bbcode/plugin.js * tinymce/js/tinymce/plugins/example/plugin.js * * Copyright, Anonymous Monk * Released under the same terms as perl itself */ /*global tinymce:true */ (function() { tinymce.create('tinymce.plugins.PerlMonksPlugin', { init : function(ed) { var self = this; // dialect = ed.getParam('bbcode_dialect', 'punbb').toLowerCase(); ed.on('beforeSetContent', function(e) { e.content = self['_pm2html'](e.content); }); ed.on('postProcess', function(e) { if (e.set) { e.content = self['_pm2html'](e.content); } else if (e.get) { e.content = self['_html2pm'](e.content); } }); ed.addMenuItem('perlmonkscodetags', { text: '', icon: false, context: 'format', /* file menu, views, tools ... */ onclick: function() { // something // ed.windowManager.open({ // TODO toggle add/remove code tags around selection or at cursor } }); ed.addButton('perlmonkscodetags', { text: '', icon: false, onclick: function() { // something // ed.windowManager.open({ // TODO toggle add/remove code tags around selection or at cursor } }); }, getInfo: function() { return { longname: 'PerlMonks Plugin', author: 'Anonymous Monk', authorurl: 'http://www.perlmonks.org/?node_id=961', infourl: 'http://www.perlmonks.org/?node=PerlMonks+FAQ' }; }, _html2pm : function(s) { var codeReplacer = function(match,precode,code, c){ /* function(match, p1, p2, p3, offset, string) */ var repsFun = function(chr){ return { "<" : "<", ">" : ">", "&" : "&", " " : " ", "
" : "\n", "[" : "[", "]" : "]" }[chr]; }; /* repsFun */ if( precode ){ s = precode.replace( /(\&\#91;|\&\#93;|\ |\<|\>|\&|
)/gi, repsFun ); s = "
"+s+"
"; } else if( code ){ s = code.replace( /(\&\#91;|\&\#93;|\ |\<|\>|\&|
)/gi, repsFun ); s = ""+s+""; } else { s = c.replace( /(\&\#91;|\&\#93;|\ |\<|\>|\&|
)/gi, repsFun ); s = ""+s+""; } if( s.match(/\n/) ){ s = "
" + s + "
"; } return s; }; /* end of codeReplacer */ s = s.replace(/
([\w\W]*?)<\/code><\/pre>|([\w\W]*?)<\/code>|([\w\W]*?)<\/c>/gi, codeReplacer );
            
			return s;
		},
        
		_pm2html : function(s) {
/* function(match, p1, p2, p3, offset, string)  */
            var codeReplacer = function(match, precode, code, c ){
                var repsFun = function(chr){
                    return {
                        "<"  : "<",
                        ">"  : ">",
                        "&"  : "&",
                        " "  : " ",
                        "\n" : "
", "[" : "[", "]" : "]" }[ chr ]; }; /* repsFun */ if( precode ){ s = precode.replace( /([\n <>&])/gi, repsFun ); } else if( code ){ s = code.replace( /([\n <>&])/gi, repsFun ); } else { s = c.replace( /([\n <>&])/gi, repsFun ); } s = "" + s + ""; if( s.match(/\n/) ){ s = "
" + s + "
"; } return s; }; /* end of codeReplacer */ s = s.replace(/
([\w\W]*?)<\/code><\/pre>|([\w\W]*?)<\/code>|([\w\W]*?)<\/c>/gi, codeReplacer );
            
			return s;
		}
	});
    
	// Register plugin
	tinymce.PluginManager.add('perlmonks', tinymce.plugins.PerlMonksPlugin);
})();

####



 tinymce perlmonks local editor 





[Toggle WYSIWYG]