in Web & Tech

Prevent CKEditor from creating empty paragraphs upon pasting rich text

When using CKEditor with Drupal more often than not annoying empty paragraphs <p>&nbsp;</p> slip into your article when pasting formatted text. To prevent this stupid behavior it turns out you can set config.autoParagraph = false in CKEditor’s configuration at sites/all/modules/ckeditor/ckeditor.config.js. Of course it’s not a good idea to hack this part of the module directly, so I’m still gonna have to look for a way to set that option independently (I guess there even is an option available on the CKEdtior configuration page that allows to load a customized config file).

Anyways, I needed to get rid of those pesky paragraphs ASAP so here’s the relevant part of my ckeditor.config.js

CKEDITOR.editorConfig = function(config) {
    config.autoParagraph = false;

In case you’re worried: this does not keep CKEditor from inserting paragraphs upon hitting the enter key.


If you don’t want to be evil and hack ckeditor.config.js (and you don’t want!) directly in the modules directory you can provide your ckeditor settings with the path to a custom configuration file:

config.customConfig = '/sites/all/themes/mytheme/ckeditor.config.js';

If you don’t use an admin theme you can alternativly simply set the option LOAD CKEDITOR.CONFIG.JS FROM THE THEME PATH to yes, but keep in mind that this option won’t work with an admin theme!

Write a Comment