kemsky
kemsky

Reputation: 15271

Remove <br> tags when RemoveFormat is executed

I'm trying to extend RemoveFormat command to make it remove <br> tags.

I've tried altering removefromat format:

            formats: {
                removeformat: [
                    {
                        selector: 'br',
                        remove: 'all'
                    }
                ]
            }

The code above for some reason removes &nbsp; from blank lines <p>&nbsp;</p>, this is not acceptable.

My second try was adding plugin and using editor.selection.getContent/editor.selection.setContent, but I can not find information how to restore selection with this approach.

Upvotes: 4

Views: 415

Answers (1)

Jonas Weinhardt
Jonas Weinhardt

Reputation: 1046

When I configure my TinyMCE Editor like this it works for me:

  valid_elements : '*[*]',
  remove_trailing_brs: false,
  formats: {
    removeformat: [
      { selector: 'br', remove: 'all' }
    ]
  }

Here is a codepen example for this: https://codepen.io/jonas_weinhardt/pen/oNwmpaz

Maybe its helps you with your problem.

Upvotes: 2

Related Questions