Search code examples
javascripttinymcetinymce-4page-break

How to allow comment tags using valid_elements in TinyMCE


I'm trying to use the pagebreak plugin with TinyMCE whilst restricting the allowed elements using valid_elements. However, I can't figure out how to allow comment tags in my valid_elements setting. I've tried using !-- but this doesn't work, although this doesn't surprise me as ! has a special meaning in the valid_elements value (it makes an attribute required).

Is it possible to allow comment tags using valid_elements? I want to use pagebreak whilst still filtering content.

My code looks like this:-

tinymce.init({
    selector: 'textarea',
    plugins: 'pagebreak',
    valid_elements: 'p,br,a[title|target|href],strong,em,ul,ol,li,!--'
});

Solution

  • I was able to solve my own question. To allow comments in the valid_elements you need to use --[*]. Presumably TinyMCE interprets the actual comment text as the tags attributes, so we need to include the attributes wildcard.

    The code in the question needs updating to be:-

    tinymce.init({
        selector: 'textarea',
        plugins: 'pagebreak',
        valid_elements: 'p,br,a[title|target|href],strong,em,ul,ol,li,--[*]'
    });