-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-7141: Add ckeditor plugin for mail
**Add mail plugin** Move conversion for paragraph to `<p style="margin:0;"></p>` to plugin **Drop schema listener for `<blockQuote>`** Older versions of ckeditor did not support nested blockquotes[^1]. The schema listener is a workaround to keep nested blockquotes[^2]. CKEditor 28 added support for nested blockquotes back[^3][^4]. [^1]: ckeditor/ckeditor5#419 (comment) [^2]: ckeditor/ckeditor5#419 (comment) [^3]: ckeditor/ckeditor5#9382 [^4]: ckeditor/ckeditor5#9472 Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
- Loading branch information
Showing
4 changed files
with
98 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* @author Daniel Kesselberg <mail@danielkesselberg.de> | ||
* | ||
* @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 <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
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 <p>. | ||
* | ||
* @private | ||
*/ | ||
_overwriteParagraphConversion() { | ||
this.editor.conversion.elementToElement({ | ||
model: 'paragraph', | ||
view: { | ||
name: 'p', | ||
styles: { | ||
margin: 0, | ||
}, | ||
}, | ||
converterPriority: 'high', | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* @copyright 2022 Daniel Kesselberg <mail@danielkesselberg.de> | ||
* | ||
* @author 2022 Daniel Kesselberg <mail@danielkesselberg.de> | ||
* | ||
* @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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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 = '<p>bonjour bonjour</p>' | ||
const expected = '<p style="margin:0;">bonjour bonjour</p>' | ||
|
||
const editor = await VirtualTestEditor.create({ | ||
initialData: text, | ||
plugins: [ParagraphPlugin, MailPlugin], | ||
}) | ||
|
||
expect(editor.getData()).toEqual(expected) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters