1 | /**
|
2 | * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
3 | * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4 | */
|
5 | /**
|
6 | * @module basic-styles/italic/italicediting
|
7 | */
|
8 | import { Plugin } from 'ckeditor5/src/core.js';
|
9 | import AttributeCommand from '../attributecommand.js';
|
10 | const ITALIC = 'italic';
|
11 | /**
|
12 | * The italic editing feature.
|
13 | *
|
14 | * It registers the `'italic'` command, the <kbd>Ctrl+I</kbd> keystroke and introduces the `italic` attribute in the model
|
15 | * which renders to the view as an `<i>` element.
|
16 | */
|
17 | export default class ItalicEditing extends Plugin {
|
18 | /**
|
19 | * @inheritDoc
|
20 | */
|
21 | static get pluginName() {
|
22 | return 'ItalicEditing';
|
23 | }
|
24 | /**
|
25 | * @inheritDoc
|
26 | */
|
27 | init() {
|
28 | const editor = this.editor;
|
29 | const t = this.editor.t;
|
30 | // Allow italic attribute on text nodes.
|
31 | editor.model.schema.extend('$text', { allowAttributes: ITALIC });
|
32 | editor.model.schema.setAttributeProperties(ITALIC, {
|
33 | isFormatting: true,
|
34 | copyOnEnter: true
|
35 | });
|
36 | editor.conversion.attributeToElement({
|
37 | model: ITALIC,
|
38 | view: 'i',
|
39 | upcastAlso: [
|
40 | 'em',
|
41 | {
|
42 | styles: {
|
43 | 'font-style': 'italic'
|
44 | }
|
45 | }
|
46 | ]
|
47 | });
|
48 | // Create italic command.
|
49 | editor.commands.add(ITALIC, new AttributeCommand(editor, ITALIC));
|
50 | // Set the Ctrl+I keystroke.
|
51 | editor.keystrokes.set('CTRL+I', ITALIC);
|
52 | // Add the information about the keystroke to the accessibility database.
|
53 | editor.accessibility.addKeystrokeInfos({
|
54 | keystrokes: [
|
55 | {
|
56 | label: t('Italic text'),
|
57 | keystroke: 'CTRL+I'
|
58 | }
|
59 | ]
|
60 | });
|
61 | }
|
62 | }
|