/** * 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; 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('perlmonks_pre_code', { text: "\u003Ccode\u003E\n\n\u003C/code\u003E", tooltip: "multiline, toggle add/remove code tags around selectuion or at cursor", icon: false, context: 'format', /* file menu, views, tools ... */ onclick: function() { ed.execCommand('mceToggleFormat', false, 'perlmonks_pre_code' ); } }); ed.addButton('perlmonks_pre_code', { text: "\u003Ccode\u003E\n\n\u003C/code\u003E", tooltip: "multiline, toggle add/remove code tags around selectuion or at cursor", icon: false, onclick: function() { ed.execCommand('mceToggleFormat', false, 'perlmonks_pre_code' ); } }); ed.addMenuItem('perlmonks_c_code', { text: "\u003Cc\u003E\u003C/c\u003E", tooltip: "oneline, toggle add/remove code tags around selectuion or at cursor", icon: false, context: 'format', /* file menu, views, tools ... */ onclick: function() { ed.execCommand('mceToggleFormat', false, 'perlmonks_c_code' ); } }); ed.addButton('perlmonks_c_code', { text: "\u003Cc\u003E\u003C/c\u003E", tooltip: "oneline, toggle add/remove code tags around selectuion or at cursor", icon: false, onclick: function() { ed.execCommand('mceToggleFormat', false, 'perlmonks_c_code' ); } }); }, /* end of init */ 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; } else if( code ){ s = code; } s = '' + s.replace( /(\&\#91;|\&\#93;|\ |\<|\>|\&|
)/gi, repsFun ) + '
'; return s; }; /* end of codeReplacer */ s = s.replace(/([\w\W]*?)<\/pre>|([\w\W]*?)<\/tt>/gi, codeReplacer ); return s; }, /* end of _html2pm */ _pm2html : function(s) { /* function(match, p1, p2, p3, offset, string) */ var codeReplacer = function(match, precode, ttcode, code, c ){ var repsFun = function(chr){ return { "<" : "<", ">" : ">", "&" : "&", " " : " ", "\n" : "
", "[" : "[", "]" : "]" }[ chr ]; }; /* repsFun */ if( precode ){ s = precode; } else if( ttcode ){ s = ttcode; } else if( code ){ s = code; } else { s = c; } if( s.match(/\n/) ){ s = '
' + s.replace( /([\n <>&])/gi, repsFun ); + '
'; } else { s = '' + s.replace( /([\n <>&])/gi, repsFun ); + ''; } return s; }; /* end of codeReplacer */ s = s.replace(/()()\u003Ccode\u003E([\w\W]*?)\u003C\/code\u003E|\u003Cc\u003E([\w\W]*?)\u003C\/c\u003E/gi, codeReplacer ); return s; } /* end of _pm2html */ }); //~ tinymce.PluginManager.add('perlmonks', tinymce.plugins.PerlMonksPlugin, 'legacyoutput'); tinymce.PluginManager.add('perlmonks', tinymce.plugins.PerlMonksPlugin ); })(); #### tinymce perlmonks local editor [Toggle WYSIWYG]