Remove <br> tags when RemoveFormat is executed

Viewed 211

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.

1 Answers

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.

Related