Skip to content

Instantly share code, notes, and snippets.

@carlodaniele
Created December 3, 2016 08:55
Show Gist options
  • Save carlodaniele/7ffcd63b33c01d4284b52ad0866a4045 to your computer and use it in GitHub Desktop.
Save carlodaniele/7ffcd63b33c01d4284b52ad0866a4045 to your computer and use it in GitHub Desktop.
A TinyMCE plugin which adds a custom dropdown menu.
(function() {
var languages = ['css', 'php', 'html', 'javascript'];
tinymce.PluginManager.add( 'prism', function( editor ){
var items = [];
tinymce.each( languages, function( languageName ){
items.push({
text: languageName,
onclick: function(){
var content = tinyMCE.activeEditor.selection.getContent();
editor.insertContent( '<pre><code class="language-' + languageName + '">' + content + '</code></pre>' );
}
});
});
editor.addButton( 'prism', {
type: 'menubutton',
text: 'Prism',
icon: 'code',
menu: items
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment