I am using ckeditor on my website to make it easier for users to input HTML.
However, the data I get back from ckeditor is wrapped in <p></p> blocks. (Which I don’t want.)
Is there some configuration setting that forces the editor to not wrap the text in anything?
Add the following to your config.js file for CKEditor:
Example:
Details
The configuration setting that controls this behavior is based on what you want to happen when the user presses Enter.
Just in case someone who’s new to working with HTML reads this, I’m including some basic explanation of the concepts involved and why a tag will need to be inserted when the Enter key is pressed.
We know that if we enter some text into an HTML document and then put additional text on a new line, the browser won’t display the text as two lines, it will ignore any carriage returns and will condense multiple spaces between characters to a single space.
The following HTML:
Will be rendered as:
So the editor needs to insert an HTML tag to tell the browser that it should display the second group of text on a new line.
The configuration setting that controls this is
config.enterModeand it offers three options:1 – Insert paragraph
The default setting creates a paragraph element each time Enter is pressed:
2 – Insert ‘div’
You can choose to create a
divelement instead of a paragraph:3 – Insert break (the setting you’re looking for)
If you prefer to not wrap the text in anything, you can choose to insert a line break tag:
The CKEditor documentation indicates that using the
ENTER_BRsetting is not recommended:Another related setting ‘autoParagraph’
There is a second setting that controls a similar situation –
config.autoParagraph. How it functions depends on theconfig.enterModesetting discussed above.autoParagraphdetermines whether inline elements such asspanare wrapped in the block element (pordiv) specified by theenterModesetting. The default is to wrap inline elements, so if you enter a span like this (as HTML):It will be wrapped in a p or div element like this:
or this:
The inline element won’t be wrapped if you set this to
falseor if you setenterModetoCKEDITOR.ENTER_BR.The CKEditor documentation includes this note about
config.autoParagraph:Even more settings
There are three more settings that are somewhat related to this subject:
config.fillEmptyBlocksconfig.forceEnterModeconfig.ignoreEmptyParagraphReference
A complete list of the available configuration options can be found here: