import Plugin from "@ckeditor/ckeditor5-core/src/plugin";

export class KeepBrTags extends Plugin {
    init() {
      const editor = this.editor;

      editor.model.schema.register( 'br', {
        allowWhere: '$block',
        allowContentOf: '$root'
      });

      editor.model.schema.addAttributeCheck( context => {
        if ( context.endsWith( 'br' ) ) {
            return true;
        }
    } );

      editor.conversion.for( 'upcast' ).elementToElement( {
        view: 'br',
        model: ( viewElement, modelWriter ) => {
            return modelWriter.createElement( 'br', viewElement.getAttributes() );
        }
    } );

    editor.conversion.for( 'downcast' ).elementToElement( {
        model: 'br',
        view: 'br'
    } );
    }
  }