views:

497

answers:

2

Ckeditor : How can i make few tags like h3 , h4 , h5 non editable in ckeditor

open to js solution or css any will do

A: 

The protectedSource configuration setting is the setting of choice for that.

{Array} CKEDITOR.config.protectedSource

List of regular expressions to be executed over the input HTML, indicating code that must stay untouched.

I'm no expert on regular expressions but something like this should do the trick:

config.protectedSource.push(/[^<]*(<h1>([^<]+)<\/h1>)/g);

you may have to play around with it a bit. Caveat: The regex in that form will catch only <h1>...</h1> tags, not for example deviations like < h1 >...< /h1>.

Pekka
Question: if I enable the button to see the source (HTML), can I also prevent a user from making edits?
Upper Stage
@Upper Stage: Good question. I don't know. I'll try out later if I find the time.
Pekka
But it doesnt shows the text between h1 tag in the editorIshould be able to see it in the editor but not update it
Ashish Mehra
A: 

In config.js, use the following code to define which elements you want to allow in CKEditor (I removed h1) :

config.format_tags = 'p;h2;h3;h4;h5;h6;pre;address;div'
Matthieu