Log in or register to post comments
Last post
sina's picture
Joined: 24/08/2009
Posts: 7
Prevent first <p> tags in CKeditor
Hi everyone,

I got stuck with the problem of <p> </p> tags being added to the whole text.(the start and end of the writing).
I can do shift+enter, but it only puts <br> inside the text and I can find no way to remove the <p> tags from the beginning of the input.

Please help or develop a function to make this part customizable.
Thanks a lot :)
Sina
cs1
cs1's picture
Joined: 25/08/2009
Posts: 3
Re: Prevent first &lt;p&gt; tags in CKeditor
I'm interested on an answer in this question too, because I don't need this global <p>-tag in the content.
Thanks!
ericsaboia's picture
Joined: 09/09/2009
Posts: 2
Re: Prevent first &lt;p&gt; tags in CKeditor
I have the same question... plaese, can anyone help us?
sina's picture
Joined: 24/08/2009
Posts: 7
Re: Prevent first &lt;p&gt; tags in CKeditor
Can anyone on this forum answer us?

I think the developers must know why they put the <p> </p> tags at the beginning and end of the codes! and surely there must be some way to prevent it from happening !!!

Please help guys ...
eggbert's picture
Joined: 09/09/2009
Posts: 16
Re: Prevent first &lt;p&gt; tags in CKeditor
Try this, works for me

CKEDITOR.replace( 'editor1' ,
{
enterMode : Number(2),
eggbert's picture
Joined: 09/09/2009
Posts: 16
Re: Prevent first &lt;p&gt; tags in CKeditor
enterMode : CKEDITOR.ENTER_BR

is probably more correct - that also works.

it is set in the config.js file

/**
* Sets the behavior for the ENTER key. It also dictates other behaviour
* rules in the editor, like whether the &lt;br&gt; element is to be used
* as a paragraph separator when indenting text.
* The allowed values are the following constants, and their relative
* behavior:
* <ul>
* <li>{@link CKEDITOR.ENTER_P} (1): new &lt;p&gt; paragraphs are created;</li>
* <li>{@link CKEDITOR.ENTER_BR} (2): lines are broken with &lt;br&gt; elements;</li>
* <li>{@link CKEDITOR.ENTER_DIV} (3): new &lt;div&gt; blocks are created.</li>
* </ul>
* <strong>Note</strong>: It's recommended to use the
* {@link CKEDITOR.ENTER_P} value because of its semantic value and
* correctness. The editor is optimized for this value.
* @type Number
* @default {@link CKEDITOR.ENTER_P}
* @example
* // Not recommended.
* config.enterMode = CKEDITOR.ENTER_BR;
*/
enterMode : CKEDITOR.ENTER_P,

so you can override it with your own setting
ericsaboia's picture
Joined: 09/09/2009
Posts: 2
Re: Prevent first &lt;p&gt; tags in CKeditor
Works for me.. thanks!!
sina's picture
Joined: 24/08/2009
Posts: 7
Re: Prevent first &lt;p&gt; tags in CKeditor
Eggbert, can you describe a little more?

Should I add enterMode : CKEDITOR.ENTER_BR to the end of config.js file?
And everything will get fine?

I did so, but its still not working.

Please tell me what exactly I should do.
Thank you
Sina
sina's picture
Joined: 24/08/2009
Posts: 7
Re: Prevent first &lt;p&gt; tags in CKeditor
my config.js looks like this:
/*
Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/

CKEDITOR.editorConfig = function( config )
{
// Define changes to default configuration here. For example:
// config.language = 'fr';
// config.uiColor = '#AADC6E';
config.uiColor = '#949AAA';

};

I added enterMode : CKEDITOR.ENTER_BR; , but it didn't work.

Please help guys.
thanks
eggbert's picture
Joined: 09/09/2009
Posts: 16
Re: Prevent first &lt;p&gt; tags in CKeditor
if you're using a config file try

CKEDITOR.editorConfig = function( config )
{
// Define changes to default configuration here. For example:
// config.language = 'fr';
// config.uiColor = '#AADC6E';
config.uiColor = '#949AAA';
config.enterMode = CKEDITOR.ENTER_BR;
};
eggbert's picture
Joined: 09/09/2009
Posts: 16
Re: Prevent first &lt;p&gt; tags in CKeditor
The required syntax is slightly different depending on whether you define your configurations "in page" or in a config file ...

Setting Configurations http://docs.fckeditor.net/CKEditor_3.x/ ... igurations

Defining Configurations In-Page

CKEDITOR.replace( 'editor1',
{
toolbar : 'basic',
uiColor : '# 9AB8F3',
enterMode : CKEDITOR.ENTER_BR
});

Using the config.js File

CKEDITOR.editorConfig = function( config )
{
config.language = 'fr';
config.uiColor = '#AADC6E';
config.enterMode = CKEDITOR.ENTER_BR;
};
sina's picture
Joined: 24/08/2009
Posts: 7
Re: Prevent first &lt;p&gt; tags in CKeditor
Yeah, I tried same exact thing, but it didn't work!

I'm wondering how your's work.
Even the enter mode is with <p>.
Its so Sad. Someone pleaaase help :(
sina's picture
Joined: 24/08/2009
Posts: 7
Re: Prevent first &lt;p&gt; tags in CKeditor
Oh, Just saw your second reply :)

It works now. But one problem!

How to put <p> tags now ?:D I thought shift-enter will put <p> now, but shift+enter puts <br> too!
Any help with this?
sina's picture
Joined: 24/08/2009
Posts: 7
Re: Prevent first &lt;p&gt; tags in CKeditor
Guys Found the Solutions.

Enter(default): BR
Shift Enter: P

replace this with your config.js:

/*
Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/

CKEDITOR.editorConfig = function( config )
{
   // Define changes to default configuration here. For example:
   // config.language = 'fr';
   // config.uiColor = '#AADC6E';
   config.enterMode = CKEDITOR.ENTER_BR;
   config.shiftEnterMode = CKEDITOR.ENTER_P;
};


Hope it help everyone here :)
eggbert's picture
Joined: 09/09/2009
Posts: 16
Re: Prevent first &lt;p&gt; tags in CKeditor
I think this should set enter to use <br> tags and shift-enter to use <P> tags

I use the "in page" method, ... I find I have to clear the browser cache after each change - else the old version of the file is used and the changes don't appear.

Defining Configurations In-Page

CKEDITOR.replace( 'editor1',
{
toolbar : 'basic',
uiColor : '# 9AB8F3',
enterMode : CKEDITOR.ENTER_BR,
shiftEnterMode : CKEDITOR.ENTER_P
});

Using the config.js File

CKEDITOR.editorConfig = function( config )
{
config.language = 'fr';
config.uiColor = '#AADC6E';
config.enterMode = CKEDITOR.ENTER_BR;
config.shiftEnterMode = CKEDITOR.ENTER_P;
};
eggbert's picture
Joined: 09/09/2009
Posts: 16
Re: Prevent first &lt;p&gt; tags in CKeditor
sina wrote:Guys Found the Solutions.


you beat me to it :D
lecter255's picture
Joined: 15/11/2009
Posts: 28
Re: Prevent first &lt;p&gt; tags in CKeditor
hey guys I am on Safari, and if I have config.enterMode = CKEDITOR.ENTER_BR; in my config file, when I am typing in the editor, I need to hit enter TWICE to get to a new line. why is this and how can I fix it? thanks!
betang's picture
Joined: 09/06/2010
Posts: 1
Re: Prevent first &lt;p&gt; tags in CKeditor
in my config.js

please set
config.enterMode = 2

it s worked
orthelius's picture
Joined: 21/01/2011
Posts: 1
Re: Prevent first &lt;p&gt; tags in CKeditor
i have a solution to the problem with the preceding <p> and ending</P>
when you just type
"test"

you get
<p>  
    test</p>


as it seems in the querystring which sends the output from the editor the following when your textarea is named "editortext" you get:

editortext=<p>%OA%09%0Dtest</p>%0A%0D

which means <p> CR TAB LF test </p> CR LF

so i just filtered the non-printables (my thing is ASP)

string=replace(string, vbcr,"")
string=replace(string, vblf,"")
string=replace(string, vbtab,"")


then the normal <p> and </p> remain which you can easily filter also

if ucase(left(string,3))="<P>" then string= mid(string,4,len(string))
 if Ucase(right(string,4))="</P>" then string= left(string,len(string)-4)


and all that remains to be saved in your database is
test
chiappa's picture
Joined: 08/07/2011
Posts: 1
Re: Prevent first &lt;p&gt; tags in CKeditor
orthelius:

where do you put those lines?