Basics
A Plugin is simply a plain JavaScript object containing a couple deeper nested objects or functions e.g.
const customPlugin = {
blockStyleFn: (contentBlock) => {
if (contentBlock.getType() === 'blockquote') {
return 'superFancyBlockquote';
}
},
customStyleMap: {
'STRIKETHROUGH': {
textDecoration: 'line-through',
},
},
};
As most plugins take some kind of configuration we recommend you to always export a function that creates this object. This is aligned with all the core plugins and leads to a consistent developer experience.
export default createCustomPlugin = (config) => {
const blockStyleFn = (contentBlock) => {
if (contentBlock.getType() === 'blockquote') {
return 'superFancyBlockquote';
}
};
const customStyleMap = {
'STRIKETHROUGH': {
textDecoration: 'line-through',
},
};
return {
blockStyleFn: blockStyleFn,
customStyleMap: customStyleMap,
};
};