Search code examples
javascriptckeditorwysiwyg

ckeditor allowedExtraContent with closing html tag


I have issues to configure my ckEditor.

The configuration looks like that :

<script>
  $( document ).ready( function() {
    var ckeditor = CKEDITOR.replace( 'myTest', {
            allowedContent: true
            extraAllowedContent : 'foo[*]{*}'
</script>

And the HTML is :

<textarea id="myTest">
  <foo>balabalabal</foo>
  <foo attr="value"/>
</textarea>

When I looked at the result in my browser the second foo tag if missing, how can I keep both of them ?


Solution

  • You need to remember that CKEditor is an HTML editor and there's no <foo> tag. Additionally, you created one closed <foo></foo> tag and one self-closing <foo />. You cannot load such content into CKEditor.

    Note that it is possible to tune CKEditor a little bit to accept non-HTML tags. This can be achieved by extending the CKEDITOR.dtd object.

    CKEDITOR.dtd.foo = { '#': 1 };
    CKEDITOR.dtd.body.foo = 1;
    CKEDITOR.dtd.$block.foo = 1;
    

    This will allow foo tags as children of body. foo tag will be allowed to have text content only ('#') and will be treated as a block tag.