Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CKEditor removing <html> and <body> tags

I using CKEditor, and if I click the Source button and paste HTML code like below :

<html>
<head>
<meta http-equiv="Content-Type" content="text/html" />
</head>
<body>
<p>test</p>
</body>
</html>

and click to Source again and then submit the form, the html , head and , body tags are removed and just stays <p>test</p>!

CKEditor configuration:

CKEDITOR.replace('content', {
            extraPlugins: 'font,panelbutton,colorbutton,colordialog,justify,indentblock,aparat,buyLink',
            autoGrow_onStartup: true,
            enterMode: CKEDITOR.ENTER_BR,
            FullPage : false,
            allowedContent : true,
            ProtectedTags : 'html|head|body'
        });

Can you help me?

like image 840
B. Azizan Avatar asked Dec 05 '22 01:12

B. Azizan


1 Answers

If you want to edit an entire HTML page, with <html>, <head> and <body> elements, you need to set the config.fullPage option to true:

CKEDITOR.replace( 'content', {
    fullPage: true,
    extraPlugins: 'font,panelbutton,colorbutton,colordialog,justify,indentblock,aparat,buyLink',
    // You may want to disable content filtering because if you use full page mode, you probably
    // want to  freely enter any HTML content in source mode without any limitations.
    allowedContent: true,
    autoGrow_onStartup: true,
    enterMode: CKEDITOR.ENTER_BR
} );

Pay attention to using proper case (fullPage is not FullPage) in your configuration. See also the following resources for more information:

  • Editing Complete HTML Pages sample
  • Full Page Editing with Document Properties Plugin

If you want to use the config.autoGrow_onStartup option, you need to include the Auto Grow plugin in your setup.

Last but not least, changing the Enter Mode setting to BR or DIV is not recommended. The default CKEDITOR.ENTER_P mode is fully supported by all editor features and plugins and is also the most correct one in terms of best practices for creating web content.

If you do it to control paragraph spacing, you should use stylesheets instead. Edit the contents.css file and set up a suitable margin value for <p> elements, for example:

p { margin: 0; }
like image 91
Anna Tomanek Avatar answered Dec 21 '22 23:12

Anna Tomanek