Existing plugins

If you want to add a plugin, be sure to read the use plugins section of documentation before continue.

Allow tags from paste

Allow tags from paste plugin allows you to filter tags allowed when an user paste some code into the editor.

Try allow tags from paste live demo! View allow tags from paste plugin code on GitHub

How to use it?


<-- Import Trumbowyg plugins... -->
<script src="trumbowyg/dist/plugins/allowtagsfrompaste/trumbowyg.allowtagsfrompaste.min.js"></script>
            

Then you can configure your custom tag whitelist. Any tag pasted which is not in allowedTags list will be unwrap, only the text will be kept.


$('#my-editor').trumbowyg({
    plugins: {
        allowTagsFromPaste: {
            allowedTags: ['h4', 'p', 'br']
        }
    }
});
            

Enabling this plugin will force disable the removeformatPasted core option (set it to false).

Base 64

Base 64 plugin allows you to insert images inline as base64.

Try base64 live demo! View base64 plugin code on GitHub

How to use it?


<-- Import Trumbowyg plugins... -->
<script src="trumbowyg/dist/plugins/base64/trumbowyg.base64.min.js"></script>
            

Then you can use the new button definition base64


$('#my-editor').trumbowyg({
    btns: [
        ['base64']
    ]
});
            

Clean paste

Clean paste plugin handle paste events, clean the HTML code before insert content into the editor.

View cleanpaste plugin code on GitHub

How to use it?


<-- Import Trumbowyg plugins... -->
<script src="trumbowyg/dist/plugins/cleanpaste/trumbowyg.cleanpaste.min.js"></script>
            

Clean paste works now on every new Trumbowyg instance.

Colors

Colors plugin allows you to change foreground and background color of your text.

Try colors live demo! View colors plugin code on GitHub

How to use it?


<-- Import Trumbowyg colors style in <head>... -->
<link rel="stylesheet" href="trumbowyg/dist/plugins/colors/ui/trumbowyg.colors.min.css">
            

<-- Import Trumbowyg colors JS at the end of <body>... -->
<script src="trumbowyg/dist/plugins/colors/trumbowyg.colors.min.js"></script>
            

Then you can use the new button definitions foreColor and backColor


$('#my-editor').trumbowyg({
    btns: [
        ['foreColor', 'backColor']
    ]
});
            

Parameters

colorList array<string>
List of colors available for both foreColor and backColor dropdowns.
Default: check the code or the demo
foreColorList array<string>
List of colors available used in the foreColor dropdown instead of colorList's one.
Default: fallbacks on colorList
backColorList array<string>
List of colors available used in the backColor dropdown instead of colorList's one.
Default: fallbacks on colorList
displayAsList boolean
Switch from square to labelled list view. Default view is the square's one.
Default: false

Example with colorList parameter:


$('#my-editor').trumbowyg({
    btns: [
        ['foreColor', 'backColor']
    ],
    plugins: {
        colors: {
            colorList: [
                '000', '111', '222', 'ffea00'
            ]
        }
    }
});
            

Example with both foreColorList and backColorList, displayed as list:


$('#my-editor').trumbowyg({
    btns: [
        ['foreColor', 'backColor']
    ],
    plugins: {
        colors: {
            foreColorList: [
                'ff0000', '00ff00', '0000ff'
            ],
            backColorList: [
                '000', '333', '555'
            ],
            displayAsList: true
        }
    }
});
            

If both foreColorList and backColorList are set, colorList will be not used at all.

Emoji

Emoji plugin allows you to insert some emojis in your editor.

Try emoji live demo! View emoji plugin code on GitHub

How to use it?


<-- Import Trumbowyg emoji style in <head>... -->
<link rel="stylesheet" href="trumbowyg/dist/plugins/emoji/ui/trumbowyg.emoji.min.css">
            

<-- Import Trumbowyg emoji at the end of <body>... -->
<script src="trumbowyg/dist/plugins/emoji/trumbowyg.emoji.min.js"></script>
            

Then you can use the new button definition emoji


$('#my-editor').trumbowyg({
    btns: [
        ['emoji']
    ]
});
            

Font family

This plugin allows user to custom font family.

Try font family live demo! View font family plugin code on GitHub

How to use it?


<-- Import Trumbowyg fontfamily JS at the end of <body>... -->
<script src="trumbowyg/dist/plugins/fontfamily/trumbowyg.fontfamily.min.js"></script>
            

Then you can use the new button definition fontfamily


$('#my-editor').trumbowyg({
    btns: [
        ['fontfamily']
    ]
});
            

You can also choose custom font list:


$('#my-editor').trumbowyg({
    btns: [
        ['fontfamily']
    ],
    plugins: {
        fontfamily: {
            fontList: [
                {name: 'Arial', family: 'Arial, Helvetica, sans-serif'},
                {name: 'Open Sans', family: '\'Open Sans\', sans-serif'}
            ]
        }
    }
});
            

Font size

This plugin allows user to custom font size.

Try font size live demo! View font size plugin code on GitHub

How to use it?


<-- Import Trumbowyg font size JS at the end of <body>... -->
<script src="trumbowyg/dist/plugins/fontsize/trumbowyg.fontsize.min.js"></script>
            

Then you can use the new button definition fontsize


$('#my-editor').trumbowyg({
    btns: [
        ['fontsize']
    ]
});
            

You can also choose custom size list:


$('#my-editor').trumbowyg({
    btns: [
        ['fontsize']
    ],
    plugins: {
        fontsize: {
            sizeList: [
                '12px',
                '14px',
                '16px'
            ]
        }
    }
});
            

If you want to disable the custom font size option, use the allowCustomSize option:


$('#my-editor').trumbowyg({
    btns: [
        ['fontsize']
    ],
    plugins: {
        fontsize: {
            allowCustomSize: false
        }
    }
});
            

Default allowCustomSize value is true.

Giphy

User can search and pick gif to insert from Giphy

Try Giphy plugin live demo! View Giphy plugin code on GitHub

How to use it?


<-- Import Trumbowyg Giphy style in <head>... -->
<link rel="stylesheet" href="trumbowyg/dist/plugins/giphy/ui/trumbowyg.giphy.min.css">
            

<-- Import Trumbowyg Giphy JS at the end of <body>... -->
<script src="trumbowyg/dist/plugins/giphy/trumbowyg.giphy.min.js"></script>
            

Then, you need to create a Giphy App to get an API Key.

Use the new button definition giphy and your newly created Giphy API Key:


$('#my-editor').trumbowyg({
    btns: [
        ['giphy']
    ],
    plugins: {
        giphy: {
            apiKey: 'yourVeryOwnApiKey'
        }
    }
});
            

Parameters

apiKey string (required)
Giphy API Key of your application. Create a Giphy App to get an API Key.
rating string
Giphy image rating filter. See Giphy documentation for allowed rating value details.
Default: g
throttleDelay number (in milliseconds)
It's the delay between each Giphy API requests while user is typing his query.
Default: 300
noResultGifUrl string
The image URL shown when there is no result.
Default: https://media.giphy.com/media/2Faz9FbRzmwxY0pZS/giphy.gif

Example with parameters:


$('#my-editor').trumbowyg({
    btns: [
        ['giphy']
    ],
    plugins: {
        giphy: {
            apiKey: 'yourVeryOwnApiKey',
            rating: 'pg',
            throttleDelay: 500,
            noResultGifUrl: 'http://example.com/yourimage.gif'
        }
    }
});
            

Code Highlight

This plugin allows user to add code highlight parts.

Try highlight plugin live demo! View highlight plugin code on GitHub

How to use it?

This plugin require prismjs which can be installed with: npm install prismjs


<-- Import prismjs style in <head>... -->
<link rel="stylesheet" href="node_modules/prismjs/themes/prism.css">
<-- Import highlight plugin style in <head>... -->
<link rel="stylesheet" href="trumbowyg/dist/plugins/highlight/ui/trumbowyg.highlight.min.css">
<-- Import prismjs and Trumbowyg highlight at the end of <body>... -->
<script src="node_modules/prismjs/prism.js"></script>
<script src="trumbowyg/dist/plugins/highlight/trumbowyg.highlight.min.js"></script>
            

You also can add another prism language syntaxes for example:


<-- Import prismjs and Trumbowyg highlight at the end of <body>... -->
<script src="node_modules/prismjs/prism.js"></script>
<script src="node_modules/prismjs/components/prism-csharp.js"></script>
<script src="node_modules/prismjs/components/prism-go.js"></script>
<script src="node_modules/prismjs/components/prism-markdown.js"></script>
<script src="trumbowyg/dist/plugins/highlight/trumbowyg.highlight.min.js"></script>
            

Also on your website you must connect prismjs styles to lighting code worked. For example connect prism.css in head:


<-- Import prismjs style in <head>... on your site -->
<link rel="stylesheet" href="node_modules/prismjs/themes/prism.css">
            

History

History plugin is an enhanced implementation of the undo and redo functionality. It tracks changes of the editor and will add each change to a history stack. If a word is typed in or text was pasted, it counts as a single stack entry.

Try history plugin live demo! View history plugin code on GitHub

How to use it?


<-- Import Trumbowyg history JS at the end of <body>... -->
<script src="trumbowyg/dist/plugins/history/trumbowyg.history.min.js"></script>
            

Then you can use the new button definitions historyUndo and historyRedo


$('#my-editor').trumbowyg({
    btns: [
        ['historyUndo', 'historyRedo']
    ]
});
            

Insert audio

Do the same as insert image, but for audio.

Try insert audio live demo! View insertAudio plugin code on GitHub

How to use it?


<-- Import Trumbowyg insertAudio at the end of <body>... -->
<script src="trumbowyg/dist/plugins/insertaudio/trumbowyg.insertaudio.min.js"></script>
            

Then you can use the new button definition insertAudio


$('#my-editor').trumbowyg({
    btns: [
        ['insertAudio']
    ]
});
            

Line height

This plugin allows user to custom line height.

Try line height live demo! View line height plugin code on GitHub

How to use it?


<-- Import Trumbowyg lineheight at the end of <body>... -->
<script src="trumbowyg/dist/plugins/lineheight/trumbowyg.lineheight.min.js"></script>
            

Then you can use the new button definition lineheight


$('#my-editor').trumbowyg({
    btns: [
        ['lineheight']
    ]
});
            

You can also choose custom size list:


$('#my-editor').trumbowyg({
    btns: [
        ['lineheight']
    ],
    plugins: {
        fontsize: {
            sizeList: [
                '12px',
                '14px',
                '16px'
            ]
        }
    }
});
            

MathML

This plugin allows user to use MathML.

Try MathML live demo! View MathML plugin code on GitHub

How to use it?


<-- Import Trumbowyg MathML style in <head>... -->
<link rel="stylesheet" href="trumbowyg/dist/plugins/mathml/ui/trumbowyg.mathml.min.css">
            

<-- Import Trumbowyg MathJax at the end of <body>... -->
<script src="//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<-- Import Trumbowyg MathML plugin at the end of <body>... -->
<script src="trumbowyg/dist/plugins/mathml/trumbowyg.mathml.min.js"></script>
            

Then you can use the new button definition mathml


// MathJax inline configuration
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [
            ['$', '$'],
            ['\\(', '\\)']
        ]
    }
});

// Trumbowyg initialization with MathML button
$('#editor')
.trumbowyg({
    btns: [
        'mathml'
    ]
});
            

Mention

This plugin allows to mention an user from a source list.

Try mention live demo! View mention plugin code on GitHub

How to use it?


<-- Import Trumbowyg plugins... -->
<script src="trumbowyg/dist/plugins/mention/trumbowyg.mention.min.js"></script>
            

Then you can use the new button definition mention


$('#my-editor').trumbowyg({
    btns: [
        ['mention']
    ],
    plugins: {
        mention: {
            source: [
                {login: 'lucy'},
                {login: 'jdoe'},
                {login: 'mlisa'},
                {login: 'jcesar'},
            ]
        }
    }
});
            

Parameters

source array<object>
List of mentionable users. Must contains login key if you do not override two other parameters.
Default: []
formatDropdownItem function
Custom format items in mention dropdown: function (item) {}. Must return a string.
Default output: item.login
formatResult function
The string which will be inserted in editor: function (item) {}. Must return a string.
Default output: '@' + item.login + ' '

Example with parameters:


$('#my-editor').trumbowyg({
    btns: [
        ['mention']
    ],
    plugins: {
        mention: {
            source: [
                {login: 'lucy', name: 'Lucy'},
                {login: 'jdoe', name: 'John Doe'},
                {login: 'mlisa', name: 'Mona Lisa'},
                {login: 'jcesar', name: 'Julius Cesarius'},
            ],
            formatDropdownItem: function (item) {
                return item.name + ' (' + item.login + ')';
            },
            formatResult: function (item) {
                return '@"' + item.name + '" ';
            }
        }
    }
});
            

Noembed

Allows you to embed any content from a link using noembed.com API.

Try noembed live demo! View noembed plugin code on GitHub

How to use it?


<-- Import Trumbowyg plugins... -->
<script src="trumbowyg/dist/plugins/noembed/trumbowyg.noembed.min.js"></script>
            

Then you can use the new button definition noembed


$('#my-editor').trumbowyg({
    btns: [
        ['noembed']
    ]
});
            

Paste embed

Paste embed plugin handles paste events. It looks for paste event, checks if it's a url and uses noembed and MAXmade APIs to retrieve an iframe from that url. If it can't retrieve an iframe, it will put an anchor tag around the url. It doesn't do anything on text or HTML paste.

Try paste embed live demo! View pasteembed plugin code on GitHub

How to use it?


<-- Import Trumbowyg plugins... -->
<script src="trumbowyg/dist/plugins/pasteembed/trumbowyg.pasteembed.min.js"></script>
            

Paste embed now works on every new Trumbowyg instance.

Paste image

Paste image plugin handle paste events, check if you have image files in your clipboard, then paste them into the editor as base64. It do nothing on text or HTML paste.

Try paste image live demo! View paste image plugin code on GitHub

How to use it?


<-- Import Trumbowyg plugins... -->
<script src="trumbowyg/dist/plugins/pasteimage/trumbowyg.pasteimage.min.js"></script>
            

Paste image works now on every new Trumbowyg instance.

Preformatted

Wraps your code with <pre> tags.

Try preformatted live demo! View preformatted plugin code on GitHub

How to use it?


<-- Import Trumbowyg plugins... -->
<script src="trumbowyg/dist/plugins/preformatted/trumbowyg.preformatted.min.js"></script>
            

Then you can use the new button definition preformatted


$('#my-editor').trumbowyg({
    btns: [
        ['preformatted']
    ]
});
            

Resizimg

Allows you to resize images (preserving aspect ratio) by dragging their bottom-right corner.

Try resizimg live demo! View resizimg plugin code on GitHub

Dependencies

This plugin depends on the jquery-resizable plugin, which must be loaded beforehand.

If in your project use the JQuery UI library with resizable interaction you need to include this script to avoid issue before load jquery-resizable.

How to use it?


<-- Import this only if you use jQuery UI with resizable extension -->
<script src="trumbowyg/dist/plugins/resizimg/resolveconflict-resizable.min.js"></script>
<-- Import jQuery resizimg plugin -->
<script src="jquery-resizable/dist/jquery-resizable.min.js"></script>
<-- Import Trumbowyg plugins... -->
<script src="trumbowyg/dist/plugins/resizimg/resize.with.canvas.min.js"></script>
<script src="trumbowyg/dist/plugins/resizimg/trumbowyg.resizimg.min.js"></script>
            

Parameters

minSize number
Minimal size of image and also of draggable right-bottom corner.
Default: 32
step number
Increment when increasing / decreasing image height.
Default: 4

Example with parameters:


$('#editor').trumbowyg({
    plugins: {
        resizimg: {
            minSize: 64,
            step: 16,
        }
    }
});
            

The resulting image size is currently absolute: CSS height in pixels (style attribute).

Ruby

Allows you to support ruby markup.

Try ruby live demo! View ruby plugin code on GitHub

How to use it?


<-- Import Trumbowyg ruby style in <head>... -->
<link rel="stylesheet" href="trumbowyg/dist/plugins/ruby/ui/trumbowyg.ruby.min.css">
            

<-- Import Trumbowyg ruby at the end of <body>... -->
<script src="trumbowyg/dist/plugins/ruby/trumbowyg.ruby.min.js"></script>
            

Then you can use the new button definition ruby


$('#my-editor').trumbowyg({
    btns: [
        ['specialChars']
    ]
});
            

Special Chars

Special Chars plugin allows you to insert some special characters in your editor.

Try special chars live demo! View specialChars plugin code on GitHub

How to use it?


<-- Import Trumbowyg specialchars style in <head>... -->
<link rel="stylesheet" href="trumbowyg/dist/plugins/specialchars/ui/trumbowyg.specialchars.min.css">
            

<-- Import Trumbowyg specialchars at the end of <body>... -->
<script src="trumbowyg/dist/plugins/specialchars/trumbowyg.specialchars.min.js"></script>
            

Then you can use the new button definition specialchars


$('#my-editor').trumbowyg({
    btns: [
        ['specialChars']
    ]
});
            

Parameters

symbolList array<string>
List of special chars displayed in the dropdown.
To force next char to be on a new line in dropdown, add a null entry.
Default: check in the code.

Example with parameters:


$('#editor-custom-list')
.trumbowyg({
    btns: [
        ['specialChars']
    ],
    plugins: {
        specialchars: {
            symbolList: [
                '00A2', '00A5', '00A4', '2030',  null,
                '00A9', '00AE',  '2122',  null,
                '2023', '25B6', '2B29', '25C6', null,
                '2211', '2243', '2264', '2265'
            ]
        }
    }
});
            

Table

Table plugin allows users to create and manage tables.

Try table live demo! View table plugin code on GitHub

How to use it?


<-- Import Trumbowyg Table style in <head>... -->
<link rel="stylesheet" href="trumbowyg/dist/plugins/table/ui/trumbowyg.table.min.css">
            

<-- Import Trumbowyg plugins... -->
<script src="trumbowyg/dist/plugins/table/trumbowyg.table.min.js"></script>
            

Then you can use the new button definition table


$('#my-editor').trumbowyg({
    btns: [
        ['table']
    ],
    plugins: {
        table: {
            // Some table plugin options, see details below
        }
    }
});
            

Parameters

rows number
The count of rows which should be used for table building in the table grid dropdown.
Default: 8
columns number
The count of columns which should be used for table building in the table grid dropdown.
Default: 8
styler string
The class which should be assigned to each table by default
Default: 'table'

The table plugin provides a button with two different dropdowns depending on current selection. If the current cursor is not placed within a table, the dopdown renders a table grid where you can build the table.
Otherwise the dropdown will render a few options for the current table like:

  • Add row to table
  • Add column to table
  • Delete row from table
  • Delete column from table
  • Delete table

Template

Manage a set of HTML templates to insert fast.

Try template live demo! View template plugin code on GitHub

How to use it?


<-- Import Trumbowyg plugins... -->
<script src="trumbowyg/dist/plugins/template/trumbowyg.template.min.js"></script>
            

Then you can use the new button definition template and can add your template code.


$('#my-editor').trumbowyg({
    btns: [
        ['template']
    ],
    plugins: {
        templates: [
            {
                name: 'Template 1',
                html: '<p>I am a template!</p>'
            },
            {
                name: 'Template 2',
                html: '<p>I am a different template!</p>'
            }
        ]
    }
});
            

Upload

Add an upload front-end allowing users to select an image, upload it with progress bar and then insert the uploaded image in the editor.

Try upload live demo! View upload plugin code on GitHub

How to use it?


<-- Import Trumbowyg plugins... -->
<script src="trumbowyg/dist/plugins/upload/trumbowyg.upload.min.js"></script>
            

Then you can use the new button definition upload


$('#my-editor').trumbowyg({
    btns: [
        ['upload']
    ],
    plugins: {
        upload: {
            // Some upload plugin options, see details below
        }
    }
});
            

Parameters

serverPath string
The URL to the server which catch the upload request
Default: ''
fileFieldName string
The POST property key associated to the upload file
Default: 'fileToUpload'
data array<Object>
Additional data for ajax. jQuery.ajax data option
Example: [{name: 'myKey1', value: 'myValue1'}, {name: 'username', value: 'myUsername'}]
Default: []
headers Object
Additional headers. Check jQuery.ajax headers option
Example: {headerKey: 'headerValue', Authorization: 'Client-ID xxxxxxxxx'}
Default: {}
xhrFields Object
Additional xhrFields. Check jQuery.ajax xhrFields option
Default: {}
urlPropertyName string
How to get image URL in the JSON response.
Example: 'url' for {url: 'https://example.com/myimage.jpg', success: true}
Default: 'file'
statusPropertyName string
How to get status from the json response.
Example: 'success' for {success: true, url: 'https://example.com/myimage.jpg'}
Default: 'success'
success function
Success callback: function (data, trumbowyg, $modal, values) {}
Default: null
error function
Error callback: function () {}
Default: null
imageWidthModalEdit boolean
Add a field allowing user to set image width
Default: false

Server side

Server side receives a POST request with the image in the fileFieldName field and alt which contains image description:


alt: 'Image description'
fileToUpload: // The image file
            

It must save this image, then return a JSON response like that:


{
    success: true, // Must be false if upload fails
    file: 'https://example.com/myimage.jpg'
}
            

Create your own

Introduction

A plugin can be a button, a paste handler or whatever you want. If you want add a plugin myplugin to the official Trumbowyg list, your should follow this tree:


plugins
 └── myplugin
     ├── ui
     │   ├── icons
     │   │   └── myplugin.svg
     │   └── sass
     │       └── trumbowyg.myplugin.scss
     └── trumbowyg.myplugin.js
            

As plugin can be something other than a button, icons and scss are optional depending on your feature.

In a plugin, you get access to all Trumbowyg core and you can extends all things as you wish.

Skeleton

To create a new plugin, you should start your trumbowyg.myplugin.js with this code:


(function ($) {
    'use strict';

    // Plugin default options
    var defaultOptions = {
    };

    // If the plugin is a button
    function buildButtonDef (trumbowyg) {
        return {
            fn: function () {
                // Plugin button logic
            }
        }
    }

    $.extend(true, $.trumbowyg, {
        // Add some translations
        langs: {
            en: {
                myplugin: 'My plugin'
            }
        },
        // Register plugin in Trumbowyg
        plugins: {
            myplugin: {
                // Code called by Trumbowyg core to register the plugin
                init: function (trumbowyg) {
                    // Fill current Trumbowyg instance with the plugin default options
                    trumbowyg.o.plugins.myplugin = $.extend(true, {},
                        defaultOptions,
                        trumbowyg.o.plugins.myplugin || {}
                    );

                    // If the plugin is a paste handler, register it
                    trumbowyg.pasteHandlers.push(function(pasteEvent) {
                        // My plugin paste logic
                    });

                    // If the plugin is a button
                    trumbowyg.addBtnDef('myplugin', buildButtonDef(trumbowyg));
                },
                // Return a list of button names which are active on current element
                tagHandler: function (element, trumbowyg) {
                    return [];
                },
                destroy: function (trumbowyg) {
                }
            }
        }
    })
})(jQuery);
            

Interact with content

To interact with editor and its content, you should use Trumbowyg core API. You can also check existing plugins source code to see how it works!

Go to the core API documentation