Stop CKEditor 4 from adding additional HTML tags

I have a problem with CKEditor 4 adding additional HTML tags. I've been using v3 for a few years without any problems, and I've built my own plug-ins, so I'm not a complete novice but this has me stumped. For instance the following block of HTML:

<section class="component2">
    <div class="">
        <div class="component2__row">
            <a class="component2__item component2__item--primary" href="#">
                <img class="component2__item__image" src="http://MyServer/webmedia/Images/Components/component2/image-1.jpg" alt="IMG"/>
                <h4 class="component2__item__title">Light Vehicle</h4>
            </a>
        </div>
    </div>
</section>

Gets saved as:

<section class="component2">
    <div>
        <div class="component2__row">
            <a class="component2__item component2__item--primary" href="#">
                <img alt="IMG" class="component2__item__image" src="http://MyServer/webmedia/Images/Components/component2/image-1.jpg" />
            </a>
            <h4 class="component2__item__title">
                <a class="component2__item component2__item--primary" href="#">Light Vehicle</a>
            </h4>
            <a class="component2__item component2__item--primary" href="#"> </a>
        </div>
    </div>
</section>

Any ideas? (Note for example the additional anchor tags!) Is there something in the HTML it doesn't like? Is there a setting in config.js that I can use?

Thanks

Upvotes: 0

Views: 435

Answers (1)

If someone else stumbles across this I worked round it. As it was already my default (from v3) I'd already tried:

config.allowedContent = true;

I went through the documentation in detail, and even tried editing the dtd to allow headers to be in divs and anchors:

CKEDITOR.dtd['div']['h'] = 1;
CKEDITOR.dtd['a']['h'] = 1;

All to no avail. Eventually I gave up and replaced the <h4> tag in my sample with a <span> and styled it accordingly. That worked and CKEDITOR now leaves my source HTML untouched. Irritating that there isn't a feature whereby you can tell the Editor "Look, I know my HTML is valid, leave it alone and I'll deal with any consequences."

Upvotes: 0

Related Questions