3

I set up a Redactor config to add h3 headings only. If I copy-paste texts from a text edition software like Microsoft Word and uses h1 or h2 for example in his document, these un-wanted headings will be pasted in the rich text field. In another way, if I add an heading tag like <h1> in the source code mode of Redactor, this unwanted heading will also be added.

How can I prevent this and set a list of unwanted tags that could be dynamically deleted or converted in <p> ?

There are pasteBlockTags and pasteInlineTags options in the Redactor doc (https://imperavi.com/redactor/docs/settings/paste/#setting-pasteBlockTags), but it doesn't seems possible to add these options inside the JSON file stored in craft/config/redactor.

I also tried to add a new formattingAdd option, which I called Remove format, and replace unwanted tags by <p>, but this is an annoying solution because it needs to review each pieces of texts.

4

Not a "real" answer because it won't fix your actual content, but I wrote a plugin that would make it easy to remedy your issue on the front end (i.e. in the template) –

To remove all <h1> and <h2> tags (content inside tags will not be removed):

{{ entry.someRedactorField|retconChange(['h1','h2'], false) }}

To change <h1> and <h2> tags into <p> tags:

{{ entry.someRedactorField|retconChange(['h1','h2'], 'p') }}

You can read more about the rectonChange filter used in the two examples above here.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.