0

Is it possible to toggle class on ANY tag in Redactor? This is my current code but it also switches tag to <p> (I guess that's default tag if no "tag" argument is set) when class toggles:

{
    "buttons": [
        "html",
        "formatting",
        "bold",
        "italic"
    ],
    "formattingAdd": {
        "class-name": {
            "title": "class-name",
            "api": "module.block.format",
            "args": {
                "attr": {
                    "class": "class-name"
                },
                "type": "toggle"
            }
        }
    }
}

When I use this 'class-name' paragraph style on this:

<h1>Lorem ipsum</h1>

class will be added but <h1> tag will be replaced with <p>, so I will get this result:

<p class="class-name">Lorem ipsum</p>

The result I'm expecting is:

<h1 class="class-name">Lorem ipsum</h1>

Instead of h1 I can also have h2, h3, p... I understand I can set tag to h1 in redactor settings but I don't want to add separate option for every possible heading tag, I'm looking for some general solution where class can be added regardless of tag used, simply add class name to any tag selected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.