Turn off enclosing <p> tags in CKEditor 3.0
CKEDITOR.config.enterMode = CKEDITOR.ENTER_BR;
- this works perfectly for me.
Have you tried clearing your browser cache - this is an issue sometimes.
You can also check it out with the jQuery adapter:
<script type="text/javascript" src="/js/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/js/ckeditor/adapters/jquery.js"></script>
<script type="text/javascript">
$(function() {
$('#your_textarea').ckeditor({
toolbar: 'Full',
enterMode : CKEDITOR.ENTER_BR,
shiftEnterMode: CKEDITOR.ENTER_P
});
});
</script>
UPDATE according to @Tomkay's comment:
Since version 3.6 of CKEditor you can configure if you want inline content to be automatically wrapped with tags like <p></p>
. This is the correct setting:
CKEDITOR.config.autoParagraph = false;
Source:
http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.autoParagraph
CKEditor prevent the <p> at the beginning
Was looking for the answer to this question also and found this link helped: http://cksource.com/forums/viewtopic.php?f=11&t=15467&hilit=prevent+%3Cp%3E
So adding this to your config.js file works:
CKEDITOR.editorConfig = function( config )
{
config.enterMode = CKEDITOR.ENTER_BR;
};
Preventing CKEditor from adding <p> tags to content
This one is helpful to solve Your Problem
CKEDITOR.editorConfig = function( config )
{
config.enterMode = CKEDITOR.ENTER_BR;
};
The "config.enterMode = CKEDITOR.ENTER_BR" will be Changed "p" tag into "br" tag.
remove p tag having br tag in php
I have try this one for removing the tags you required, please check is it working for you preg_replace('#<p\sstyle=".*?"\sid=".*?">(<br\sid=".*?" ?>)</?p>+#
','',$string);
How to configure ckeditor to not wrap content in <p> block?
Add the following to your config.js file for CKEditor:
config.enterMode = CKEDITOR.ENTER_BR;
Example:
...
CKEDITOR.editorConfig = function (config)
{
config.enterMode = CKEDITOR.ENTER_BR;
...
};
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:
qwer
tyui
Will be rendered as:
qwer tyui
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.enterMode
and it offers three options:
1 - Insert paragraph
The default setting creates a paragraph element each time Enter is pressed:
config.enterMode = CKEDITOR.ENTER_P; // inserts `<p>...</p>`
2 - Insert 'div'
You can choose to create a div
element instead of a paragraph:
config.enterMode = CKEDITOR.ENTER_DIV; // inserts `<div></div>`
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:
config.enterMode = CKEDITOR.ENTER_BR; // inserts `<br />`
The CKEditor documentation indicates that using the ENTER_BR
setting is not recommended:
Note: It is recommended to use the
CKEDITOR.ENTER_P
setting because of its semantic value and correctness. The editor is optimized for this setting.
Another related setting 'autoParagraph'
There is a second setting that controls a similar situation –config.autoParagraph
. How it functions depends on the config.enterMode
setting discussed above.
autoParagraph
determines whether inline elements such as span
are wrapped in the block element (p
or div
) specified by the enterMode
setting. The default is to wrap inline elements, so if you enter a span like this (as HTML):
<span>asdfg</span>
It will be wrapped in a p or div element like this:
<p><span>asdfg</span></p>
or this:
<div><span>asdfg</span></div>
The inline element won't be wrapped if you set this to false
or if you set enterMode
to CKEDITOR.ENTER_BR
.
The CKEditor documentation includes this note about config.autoParagraph
:
Note: Changing the default value might introduce unpredictable usability issues.
Even more settings
There are three more settings that are somewhat related to this subject:
config.fillEmptyBlocks
config.forceEnterMode
config.ignoreEmptyParagraph
Reference
A complete list of the available configuration options can be found here:
- CKEDITOR.config - CKEditor 3 JavaScript API Documentation
- CKEDITOR.config - CKEditor 4 Documentation
How to remove Ck editor tag in django rest framework
You can try overriding to_representation
method in your serializer class and use strip_tags
:
from django.utils.html import strip_tags
class LessonSerializer(serializers.ModelSerializer):
class Meta:
model = Lesson
fields = (...,'lesson_content',...)
def to_representation(self, instance):
data = super().to_representation(instance)
data['lesson_content'] = strip_tags(instance.lesson_content)
return data
Related Topics
Make Floating Divs The Same Height
How Can Change Width of Dropdown List
How to Make a 45 Degree Responsive Ribbon with Folded Corner
How to Center and Crop an Image to Always Appear in Square Shape with CSS
How to Make HTML Open a Hyperlink in Another Window or Tab
Check If a Browser Has Built-In HTML5 Form Validation
Random Querystring to Avoid Ie Caching
Clear Canvas Rect (But Keep Background)
How to Display an Image Inside Svg Circle in HTML5
Making a Flex Item Float Right
A True Sticky Footer with a Fixed Header
How to Transform Each Side of a Shape Separately
<H1>, <H2>, <H3>... Tags, Inline Within Paragraphs (<P>)
Put Search Icon Near Textbox Using Bootstrap
CSS Changes Are Not Getting Reflected. Why
How to Open Native iOS App (Calendar, Notes...) from a Link on Website