Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6876339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:27:54+00:00 2026-05-27T04:27:54+00:00

I’m new to CKEditor , writing my first plugin and i just can’t find

  • 0

I’m new to CKEditor, writing my first plugin and i just can’t find the answer to this one anywhere.

I have a plugin which creates a div element in the source containing just the text !!!!!NEWSTABLE!!!!!. The class attribute is set to newsDiv. On the WYSIWYG editor, I just want it to display a fake placeholder element. This works fine, the problem is that when I switch back to WYSIWYG mode after having been in source mode, it inserts blank paragraph tags above and below the inserted div.
Switching enterMode to CKEDITOR.ENTER_BR fixes this, but I would still like the enter key to make a paragraph rather than a break-space.

My plugin code (inspired by the flash plugin source code) is as follows:

(function() {

    function isNewsEmbed(element) {
        return (element.attributes.class == 'newsDiv');
    }

    function createFakeElement(editor, realElement) {
        return editor.createFakeParserElement(realElement, 'cke_news', 'div', false);
    }

    CKEDITOR.plugins.add('newsTable', {
        init: function(editor) {
            var pluginName = 'newsTable';
            editor.ui.addButton('NewsTable', {
                label: 'Add News Section',
                icon: 'https://d26h7uo9h7bqnn.cloudfront.net/famfamfam/newspaper_add.png',
                command: pluginName
            });
            editor.addCommand(pluginName, {
                exec: function(editor) {
                    var node = new CKEDITOR.dom.element('div');
                    node.setAttribute('class', 'newsDiv');
                    node.setHtml('!!!!!NEWSTABLE!!!!!');
                    elem = editor.createFakeElement(node, 'cke_news', 'div', false)
                    editor.insertElement(elem);
                }
            }); 
            var css = 'img.cke_news{' +
                'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/placeholder.png' ) + ');' +
                'background-position: center center;' +
                'background-repeat: no-repeat;' +
                'border: 1px solid #a9a9a9;' +
                'width: 80px;' +
                'height: 80px;' +
            '}';
            editor.addCss(css);
        },
        afterInit: function(editor) {
            var dataProcessor = editor.dataProcessor,
                dataFilter = dataProcessor && dataProcessor.dataFilter;

            if (dataFilter) {
                dataFilter.addRules({
                    elements: {
                        'div' : function( element ) {
                            var attributes = element.attributes,
                            classId = attributes.classid && String( attributes.classid ).toLowerCase();
                            if (!classId && isNewsEmbed(element)){
                                return createFakeElement( editor, element );
                            }
                            return null;
                        }
                    }
                });
            }
        },
        requires : [ 'fakeobjects' ]
    });

})();

After pressing the button that activates this plugin, I press ‘Source’ and it is as expected…

<p>
<div class="newsDiv">
    !!!!!NEWSTABLE!!!!!</div>
</p>

However, if from there ones goes into WYSIWYG mode and back again (without doing anything else) the code has changed to the following, which i dont expect.

<p>
&nbsp;</p>
<div class="newsDiv">
!!!!!NEWSTABLE!!!!!</div>
<p>
&nbsp;</p>

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:27:54+00:00Added an answer on May 27, 2026 at 4:27 am

    I know it’s a rather late answer (I was searching to solve another issue, and stumbled upon this question), but the reason you can’t do this, is because both the <p> and <div> tags are “block level” elements, and you can’t put a block level element in another block level element. (It’s just invalid HTML).

    CKEditor automatically repairs this, in the way you’re seeing above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.