carlcs / craft-redactorcustomstyles

Redactor Custom Styles plugin for Craft CMS
MIT License
61 stars 13 forks source link

Add class to any block #22

Closed Visiluna closed 2 years ago

Visiluna commented 5 years ago

Is there any way to add/remove a class from the current block element without specifying an element tag?

In your example, If I use one of the alignment options (e.g. - Align Center), the current block element, whatever it may have been, is converted to a <p> tag. What if I want to Center Align an <h1> tag? Am I out of luck?

The same seems to go for removing a class. In the example, it appears the only way to Align Left is to explicitly set the block element to <p> when all I really want to do is remove the align-center class from the current block element, regardless of whether that happens to be a <p>, <h1>, or <blockquote>.

jmverges commented 5 years ago

Hi, I'm asking the same here

carlcs commented 2 years ago

I have tried to get this working with Redactor APIs which are better documented now. https://imperavi.com/redactor/docs/api-modules/#s-format.

This seems to do what you were after I think.

{
  "customStyles": {
    "align": {
      "dropdown": {
        "alignLeft": {
          "api": "module.block.remove",
          "args": {
            "class": "align-right align-center align-justify"
          }
        },
        "alignRight": {
          "api": "module.block.set",
          "args": {
            "class": "align-right"
          }
        },
        "alignCenter": {
          "api": "module.block.set",
          "args": {
            "class": "align-center"
          }
        },
        "alignJustify": {
          "api": "module.block.set",
          "args": {
            "class": "align-justify"
          }
        }
      }
    }
  }
}