diff --git a/src/ckeditor/mail/MailPlugin.js b/src/ckeditor/mail/MailPlugin.js new file mode 100644 index 0000000000..a6efe361c9 --- /dev/null +++ b/src/ckeditor/mail/MailPlugin.js @@ -0,0 +1,53 @@ +/** + * @author Daniel Kesselberg + * + * @license AGPL-3.0-or-later + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +import Plugin from '@ckeditor/ckeditor5-core/src/plugin' +import {Paragraph} from '@ckeditor/ckeditor5-paragraph' + +export default class Mail extends Plugin { + + static get requires() { + return [Paragraph] + } + + init() { + this._overwriteParagraphConversion() + } + + /** + * Overwrite the elementToElement conversion + * from the default paragraph plugin to add + * margin:0 to every

. + * + * @private + */ + _overwriteParagraphConversion() { + this.editor.conversion.elementToElement({ + model: 'paragraph', + view: { + name: 'p', + styles: { + 'margin': 0, + }, + }, + converterPriority: 'high', + }) + } + +} diff --git a/src/components/TextEditor.vue b/src/components/TextEditor.vue index 1c2270b9c3..402451b3eb 100644 --- a/src/components/TextEditor.vue +++ b/src/components/TextEditor.vue @@ -52,6 +52,7 @@ import Base64UploadAdapter from '@ckeditor/ckeditor5-upload/src/adapters/base64u import ImagePlugin from '@ckeditor/ckeditor5-image/src/image' import ImageResizePlugin from '@ckeditor/ckeditor5-image/src/imageresize' import ImageUploadPlugin from '@ckeditor/ckeditor5-image/src/imageupload' +import MailPlugin from '../ckeditor/mail/MailPlugin' import { getLanguage } from '@nextcloud/l10n' @@ -108,6 +109,7 @@ export default { ImageUploadPlugin, Base64UploadAdapter, ImageResizePlugin, + MailPlugin, ]) toolbar.unshift(...[ 'heading', @@ -181,20 +183,6 @@ export default { this.editorInstance = editor - // Set 0 pixel margin to all

elements - editor.conversion.for('downcast').add((dispatcher) => { - dispatcher.on( - 'insert:paragraph', - (evt, data, conversionApi) => { - const viewWriter = conversionApi.writer - viewWriter.setStyle('margin', '0', conversionApi.mapper.toViewElement(data.item)) - }, - { - priority: 'low', - } - ) - }) - schema.on( 'checkChild', (evt, args) => { diff --git a/src/tests/unit/components/MailPlugin.spec.js b/src/tests/unit/components/MailPlugin.spec.js new file mode 100644 index 0000000000..435f8056a7 --- /dev/null +++ b/src/tests/unit/components/MailPlugin.spec.js @@ -0,0 +1,40 @@ +/* + * @copyright 2022 Daniel Kesselberg + * + * @author 2022 Daniel Kesselberg + * + * @license AGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import VirtualTestEditor from '../../virtualtesteditor' +import ParagraphPlugin from '@ckeditor/ckeditor5-paragraph/src/paragraph' +import MailPlugin from '../../../ckeditor/mail/MailPlugin' + +describe('MailPlugin', () => { + + it('Add margin:0 to paragraph', async() => { + const text = '

bonjour bonjour

' + const expected = '

bonjour bonjour

' + + const editor = await VirtualTestEditor.create({ + initialData: text, + plugins: [ParagraphPlugin, MailPlugin], + }) + + expect(editor.getData()).toEqual(expected) + }) + +})