Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use twitter bootstrap css class in the ckeditor

I want to use the bootstrap class in the ckeditor 4. But I found the ckeditor will remove the class if I input the class in the source mode. And I want to allow user to select the class from the ckedtior css dropdown list and then show the style directly. Can anybody tell me how to solve this issue?

like image 785
Tony Woo Avatar asked Jul 10 '13 05:07

Tony Woo


3 Answers

The solution is actually a combination of two of these answers by Andrey Nelubin and user3250006.

Firstly, in order to force CKEditor to keep your custom HTML and class attributes, you need the allowedContent = true configuration. After that, in order to actually see the formatting in the editor, you need to add an extra path to contentsCss (perhaps your main CSS file, or a subset that just includes Bootstrap).

So, the following works for me:

        CKEDITOR.replace('editor1', {
            contentsCss: [CKEDITOR.basePath + 'contents.css', '/path/to/custom.css'],
            allowedContent: true,
        });
like image 83
BoffinBrain Avatar answered Jan 01 '23 09:01

BoffinBrain


You need to set extra css:

$(function () {
    CKEDITOR.config.contentsCss = [CKEDITOR.basePath + 'contents.css', '/path/to/your/css']
    CKEDITOR.replace('editor1'); // or another instance
});
like image 30
Andrey Nelubin Avatar answered Jan 01 '23 07:01

Andrey Nelubin


user3250006 is half right, then you need to add CKEDITOR.config.extraAllowedContent = 'p,span,h1,h2,h3(class1,class2),img,strong,em(class3)';

like image 38
jessie james jackson taylor Avatar answered Jan 01 '23 07:01

jessie james jackson taylor