Skip to content

Instantly share code, notes, and snippets.

@valerysntx
Created September 20, 2016 12:48
Show Gist options
  • Select an option

  • Save valerysntx/2add9c6454c6b50cd7fbcf0b0db89d4f to your computer and use it in GitHub Desktop.

Select an option

Save valerysntx/2add9c6454c6b50cd7fbcf0b0db89d4f to your computer and use it in GitHub Desktop.
ckeditor pastetext + forcePasteAsPlainText, pasteFromWordRemoveFontStyles
// start new.
var editor = CKEDITOR.replace(element, {
enterMode: CKEDITOR.ENTER_BR,
shiftEnterMode: CKEDITOR.ENTER_BR,
allowedContent: true
});
...
initializeCKEditor: function (ckeditor) {
ckeditor.config.toolbar_Full = [
{ name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'] },
{ name: 'editing', items: ['Find', 'Replace', '-', 'SelectAll'] }, { name: 'links', items: ['Link', 'Unlink', 'Anchor'] },
'/',
{ name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'] },
{
name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', '/',
'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl']
},
'/',
{ name: 'styles', items: ['Format', 'Font', 'FontSize'] },
{ name: 'colors', items: ['TextColor', 'BGColor'] },
];
ckeditor.disableAutoInline = true;
//Force pasted text to be allways plain
ckeditor.config.extraPlugins = 'pastetext,smallerselection';
ckeditor.config.forcePasteAsPlainText = true;
ckeditor.config.pasteFromWordRemoveFontStyles = false; // here is word garbage
ckeditor.config.allowedContent = true;
ckeditor.config.autoParagraph = true;
ckeditor.config.fillEmptyBlocks = true;
//ckeditor.config.font_style =
//{
// element: 'p',
// styles: { 'font-family': '#(family)' },
// overrides: [{ element: 'font', attributes: { 'face': null } }]
//};
//ckeditor.config.fontSize_style = {
// element: 'p',
// styles: { 'font-size': '#(size)' },
// overrides: [{ element: 'font', attributes: { 'size': null } }]
//};
ckeditor.config.forceEnterMode = true;
ckeditor.config.format_div = {
element: 'div',
attributes: { "style": 'display:inline-block' }
};
ckeditor.config.format_p = {
element: 'p',
attributes: { "style": "margin:0; display:inline-block !important;-moz-user-select: text !important;user-select: text !important" }
};
// ckeditor.config.coreStyles_italic = { element: 'p', attributes: { 'class': 'Italic' } };
// ckeditor.config.coreStyles_bold = { element: 'p', attributes: { 'class': 'Bold' } };
CKEDITOR.event.useCapture = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment