@ckeditor/ckeditor5-link 36.0.1 → 37.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,695 +2,546 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module link/linkediting
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
9
  import { MouseObserver } from 'ckeditor5/src/engine';
12
10
  import { Input, TwoStepCaretMovement, inlineHighlight, findAttributeRange } from 'ckeditor5/src/typing';
13
11
  import { ClipboardPipeline } from 'ckeditor5/src/clipboard';
14
12
  import { keyCodes, env } from 'ckeditor5/src/utils';
15
-
16
13
  import LinkCommand from './linkcommand';
17
14
  import UnlinkCommand from './unlinkcommand';
18
15
  import ManualDecorator from './utils/manualdecorator';
19
- import {
20
- createLinkElement,
21
- ensureSafeUrl,
22
- getLocalizedDecorators,
23
- normalizeDecorators,
24
- openLink,
25
- addLinkProtocolIfApplicable
26
- } from './utils';
27
-
16
+ import { createLinkElement, ensureSafeUrl, getLocalizedDecorators, normalizeDecorators, openLink, addLinkProtocolIfApplicable } from './utils';
28
17
  import '../theme/link.css';
29
-
30
18
  const HIGHLIGHT_CLASS = 'ck-link_selected';
31
19
  const DECORATOR_AUTOMATIC = 'automatic';
32
20
  const DECORATOR_MANUAL = 'manual';
33
21
  const EXTERNAL_LINKS_REGEXP = /^(https?:)?\/\//;
34
-
35
22
  /**
36
23
  * The link engine feature.
37
24
  *
38
25
  * It introduces the `linkHref="url"` attribute in the model which renders to the view as a `<a href="url">` element
39
26
  * as well as `'link'` and `'unlink'` commands.
40
- *
41
- * @extends module:core/plugin~Plugin
42
27
  */
43
28
  export default class LinkEditing extends Plugin {
44
- /**
45
- * @inheritDoc
46
- */
47
- static get pluginName() {
48
- return 'LinkEditing';
49
- }
50
-
51
- /**
52
- * @inheritDoc
53
- */
54
- static get requires() {
55
- // Clipboard is required for handling cut and paste events while typing over the link.
56
- return [ TwoStepCaretMovement, Input, ClipboardPipeline ];
57
- }
58
-
59
- /**
60
- * @inheritDoc
61
- */
62
- constructor( editor ) {
63
- super( editor );
64
-
65
- editor.config.define( 'link', {
66
- addTargetToExternalLinks: false
67
- } );
68
- }
69
-
70
- /**
71
- * @inheritDoc
72
- */
73
- init() {
74
- const editor = this.editor;
75
-
76
- // Allow link attribute on all inline nodes.
77
- editor.model.schema.extend( '$text', { allowAttributes: 'linkHref' } );
78
-
79
- editor.conversion.for( 'dataDowncast' )
80
- .attributeToElement( { model: 'linkHref', view: createLinkElement } );
81
-
82
- editor.conversion.for( 'editingDowncast' )
83
- .attributeToElement( { model: 'linkHref', view: ( href, conversionApi ) => {
84
- return createLinkElement( ensureSafeUrl( href ), conversionApi );
85
- } } );
86
-
87
- editor.conversion.for( 'upcast' )
88
- .elementToAttribute( {
89
- view: {
90
- name: 'a',
91
- attributes: {
92
- href: true
93
- }
94
- },
95
- model: {
96
- key: 'linkHref',
97
- value: viewElement => viewElement.getAttribute( 'href' )
98
- }
99
- } );
100
-
101
- // Create linking commands.
102
- editor.commands.add( 'link', new LinkCommand( editor ) );
103
- editor.commands.add( 'unlink', new UnlinkCommand( editor ) );
104
-
105
- const linkDecorators = getLocalizedDecorators( editor.t, normalizeDecorators( editor.config.get( 'link.decorators' ) ) );
106
-
107
- this._enableAutomaticDecorators( linkDecorators.filter( item => item.mode === DECORATOR_AUTOMATIC ) );
108
- this._enableManualDecorators( linkDecorators.filter( item => item.mode === DECORATOR_MANUAL ) );
109
-
110
- // Enable two-step caret movement for `linkHref` attribute.
111
- const twoStepCaretMovementPlugin = editor.plugins.get( TwoStepCaretMovement );
112
- twoStepCaretMovementPlugin.registerAttribute( 'linkHref' );
113
-
114
- // Setup highlight over selected link.
115
- inlineHighlight( editor, 'linkHref', 'a', HIGHLIGHT_CLASS );
116
-
117
- // Handle link following by CTRL+click or ALT+ENTER
118
- this._enableLinkOpen();
119
-
120
- // Change the attributes of the selection in certain situations after the link was inserted into the document.
121
- this._enableInsertContentSelectionAttributesFixer();
122
-
123
- // Handle a click at the beginning/end of a link element.
124
- this._enableClickingAfterLink();
125
-
126
- // Handle typing over the link.
127
- this._enableTypingOverLink();
128
-
129
- // Handle removing the content after the link element.
130
- this._handleDeleteContentAfterLink();
131
-
132
- // Handle adding default protocol to pasted links.
133
- this._enableClipboardIntegration();
134
- }
135
-
136
- /**
137
- * Processes an array of configured {@link module:link/link~LinkDecoratorAutomaticDefinition automatic decorators}
138
- * and registers a {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher downcast dispatcher}
139
- * for each one of them. Downcast dispatchers are obtained using the
140
- * {@link module:link/utils~AutomaticDecorators#getDispatcher} method.
141
- *
142
- * **Note**: This method also activates the automatic external link decorator if enabled with
143
- * {@link module:link/link~LinkConfig#addTargetToExternalLinks `config.link.addTargetToExternalLinks`}.
144
- *
145
- * @private
146
- * @param {Array.<module:link/link~LinkDecoratorAutomaticDefinition>} automaticDecoratorDefinitions
147
- */
148
- _enableAutomaticDecorators( automaticDecoratorDefinitions ) {
149
- const editor = this.editor;
150
- // Store automatic decorators in the command instance as we do the same with manual decorators.
151
- // Thanks to that, `LinkImageEditing` plugin can re-use the same definitions.
152
- const command = editor.commands.get( 'link' );
153
- const automaticDecorators = command.automaticDecorators;
154
-
155
- // Adds a default decorator for external links.
156
- if ( editor.config.get( 'link.addTargetToExternalLinks' ) ) {
157
- automaticDecorators.add( {
158
- id: 'linkIsExternal',
159
- mode: DECORATOR_AUTOMATIC,
160
- callback: url => EXTERNAL_LINKS_REGEXP.test( url ),
161
- attributes: {
162
- target: '_blank',
163
- rel: 'noopener noreferrer'
164
- }
165
- } );
166
- }
167
-
168
- automaticDecorators.add( automaticDecoratorDefinitions );
169
-
170
- if ( automaticDecorators.length ) {
171
- editor.conversion.for( 'downcast' ).add( automaticDecorators.getDispatcher() );
172
- }
173
- }
174
-
175
- /**
176
- * Processes an array of configured {@link module:link/link~LinkDecoratorManualDefinition manual decorators},
177
- * transforms them into {@link module:link/utils~ManualDecorator} instances and stores them in the
178
- * {@link module:link/linkcommand~LinkCommand#manualDecorators} collection (a model for manual decorators state).
179
- *
180
- * Also registers an {@link module:engine/conversion/downcasthelpers~DowncastHelpers#attributeToElement attribute-to-element}
181
- * converter for each manual decorator and extends the {@link module:engine/model/schema~Schema model's schema}
182
- * with adequate model attributes.
183
- *
184
- * @private
185
- * @param {Array.<module:link/link~LinkDecoratorManualDefinition>} manualDecoratorDefinitions
186
- */
187
- _enableManualDecorators( manualDecoratorDefinitions ) {
188
- if ( !manualDecoratorDefinitions.length ) {
189
- return;
190
- }
191
-
192
- const editor = this.editor;
193
- const command = editor.commands.get( 'link' );
194
- const manualDecorators = command.manualDecorators;
195
-
196
- manualDecoratorDefinitions.forEach( decorator => {
197
- editor.model.schema.extend( '$text', { allowAttributes: decorator.id } );
198
-
199
- // Keeps reference to manual decorator to decode its name to attributes during downcast.
200
- decorator = new ManualDecorator( decorator );
201
-
202
- manualDecorators.add( decorator );
203
-
204
- editor.conversion.for( 'downcast' ).attributeToElement( {
205
- model: decorator.id,
206
- view: ( manualDecoratorValue, { writer, schema }, { item } ) => {
207
- // Manual decorators for block links are handled e.g. in LinkImageEditing.
208
- if ( !( item.is( 'selection' ) || schema.isInline( item ) ) ) {
209
- return;
210
- }
211
-
212
- if ( manualDecoratorValue ) {
213
- const element = writer.createAttributeElement( 'a', decorator.attributes, { priority: 5 } );
214
-
215
- if ( decorator.classes ) {
216
- writer.addClass( decorator.classes, element );
217
- }
218
-
219
- for ( const key in decorator.styles ) {
220
- writer.setStyle( key, decorator.styles[ key ], element );
221
- }
222
-
223
- writer.setCustomProperty( 'link', true, element );
224
-
225
- return element;
226
- }
227
- }
228
- } );
229
-
230
- editor.conversion.for( 'upcast' ).elementToAttribute( {
231
- view: {
232
- name: 'a',
233
- ...decorator._createPattern()
234
- },
235
- model: {
236
- key: decorator.id
237
- }
238
- } );
239
- } );
240
- }
241
-
242
- /**
243
- * Attaches handlers for {@link module:engine/view/document~Document#event:enter} and
244
- * {@link module:engine/view/document~Document#event:click} to enable link following.
245
- *
246
- * @private
247
- */
248
- _enableLinkOpen() {
249
- const editor = this.editor;
250
- const view = editor.editing.view;
251
- const viewDocument = view.document;
252
-
253
- this.listenTo( viewDocument, 'click', ( evt, data ) => {
254
- const shouldOpen = env.isMac ? data.domEvent.metaKey : data.domEvent.ctrlKey;
255
-
256
- if ( !shouldOpen ) {
257
- return;
258
- }
259
-
260
- let clickedElement = data.domTarget;
261
-
262
- if ( clickedElement.tagName.toLowerCase() != 'a' ) {
263
- clickedElement = clickedElement.closest( 'a' );
264
- }
265
-
266
- if ( !clickedElement ) {
267
- return;
268
- }
269
-
270
- const url = clickedElement.getAttribute( 'href' );
271
-
272
- if ( !url ) {
273
- return;
274
- }
275
-
276
- evt.stop();
277
- data.preventDefault();
278
-
279
- openLink( url );
280
- }, { context: '$capture' } );
281
-
282
- // Open link on Alt+Enter.
283
- this.listenTo( viewDocument, 'keydown', ( evt, data ) => {
284
- const url = editor.commands.get( 'link' ).value;
285
- const shouldOpen = url && data.keyCode === keyCodes.enter && data.altKey;
286
-
287
- if ( !shouldOpen ) {
288
- return;
289
- }
290
-
291
- evt.stop();
292
-
293
- openLink( url );
294
- } );
295
- }
296
-
297
- /**
298
- * Starts listening to {@link module:engine/model/model~Model#event:insertContent} and corrects the model
299
- * selection attributes if the selection is at the end of a link after inserting the content.
300
- *
301
- * The purpose of this action is to improve the overall UX because the user is no longer "trapped" by the
302
- * `linkHref` attribute of the selection and they can type a "clean" (`linkHref`–less) text right away.
303
- *
304
- * See https://github.com/ckeditor/ckeditor5/issues/6053.
305
- *
306
- * @private
307
- */
308
- _enableInsertContentSelectionAttributesFixer() {
309
- const editor = this.editor;
310
- const model = editor.model;
311
- const selection = model.document.selection;
312
-
313
- this.listenTo( model, 'insertContent', () => {
314
- const nodeBefore = selection.anchor.nodeBefore;
315
- const nodeAfter = selection.anchor.nodeAfter;
316
-
317
- // NOTE: ↰ and ↱ represent the gravity of the selection.
318
-
319
- // The only truly valid case is:
320
- //
321
- // ↰
322
- // ...<$text linkHref="foo">INSERTED[]</$text>
323
- //
324
- // If the selection is not "trapped" by the `linkHref` attribute after inserting, there's nothing
325
- // to fix there.
326
- if ( !selection.hasAttribute( 'linkHref' ) ) {
327
- return;
328
- }
329
-
330
- // Filter out the following case where a link with the same href (e.g. <a href="foo">INSERTED</a>) is inserted
331
- // in the middle of an existing link:
332
- //
333
- // Before insertion:
334
- // ↰
335
- // <$text linkHref="foo">l[]ink</$text>
336
- //
337
- // Expected after insertion:
338
- // ↰
339
- // <$text linkHref="foo">lINSERTED[]ink</$text>
340
- //
341
- if ( !nodeBefore ) {
342
- return;
343
- }
344
-
345
- // Filter out the following case where the selection has the "linkHref" attribute because the
346
- // gravity is overridden and some text with another attribute (e.g. <b>INSERTED</b>) is inserted:
347
- //
348
- // Before insertion:
349
- //
350
- // ↱
351
- // <$text linkHref="foo">[]link</$text>
352
- //
353
- // Expected after insertion:
354
- //
355
- // ↱
356
- // <$text bold="true">INSERTED</$text><$text linkHref="foo">[]link</$text>
357
- //
358
- if ( !nodeBefore.hasAttribute( 'linkHref' ) ) {
359
- return;
360
- }
361
-
362
- // Filter out the following case where a link is a inserted in the middle (or before) another link
363
- // (different URLs, so they will not merge). In this (let's say weird) case, we can leave the selection
364
- // attributes as they are because the user will end up writing in one link or another anyway.
365
- //
366
- // Before insertion:
367
- //
368
- // ↰
369
- // <$text linkHref="foo">l[]ink</$text>
370
- //
371
- // Expected after insertion:
372
- //
373
- // ↰
374
- // <$text linkHref="foo">l</$text><$text linkHref="bar">INSERTED[]</$text><$text linkHref="foo">ink</$text>
375
- //
376
- if ( nodeAfter && nodeAfter.hasAttribute( 'linkHref' ) ) {
377
- return;
378
- }
379
-
380
- model.change( writer => {
381
- removeLinkAttributesFromSelection( writer, getLinkAttributesAllowedOnText( model.schema ) );
382
- } );
383
- }, { priority: 'low' } );
384
- }
385
-
386
- /**
387
- * Starts listening to {@link module:engine/view/document~Document#event:mousedown} and
388
- * {@link module:engine/view/document~Document#event:selectionChange} and puts the selection before/after a link node
389
- * if clicked at the beginning/ending of the link.
390
- *
391
- * The purpose of this action is to allow typing around the link node directly after a click.
392
- *
393
- * See https://github.com/ckeditor/ckeditor5/issues/1016.
394
- *
395
- * @private
396
- */
397
- _enableClickingAfterLink() {
398
- const editor = this.editor;
399
- const model = editor.model;
400
-
401
- editor.editing.view.addObserver( MouseObserver );
402
-
403
- let clicked = false;
404
-
405
- // Detect the click.
406
- this.listenTo( editor.editing.view.document, 'mousedown', () => {
407
- clicked = true;
408
- } );
409
-
410
- // When the selection has changed...
411
- this.listenTo( editor.editing.view.document, 'selectionChange', () => {
412
- if ( !clicked ) {
413
- return;
414
- }
415
-
416
- // ...and it was caused by the click...
417
- clicked = false;
418
-
419
- const selection = model.document.selection;
420
-
421
- // ...and no text is selected...
422
- if ( !selection.isCollapsed ) {
423
- return;
424
- }
425
-
426
- // ...and clicked text is the link...
427
- if ( !selection.hasAttribute( 'linkHref' ) ) {
428
- return;
429
- }
430
-
431
- const position = selection.getFirstPosition();
432
- const linkRange = findAttributeRange( position, 'linkHref', selection.getAttribute( 'linkHref' ), model );
433
-
434
- // ...check whether clicked start/end boundary of the link.
435
- // If so, remove the `linkHref` attribute.
436
- if ( position.isTouching( linkRange.start ) || position.isTouching( linkRange.end ) ) {
437
- model.change( writer => {
438
- removeLinkAttributesFromSelection( writer, getLinkAttributesAllowedOnText( model.schema ) );
439
- } );
440
- }
441
- } );
442
- }
443
-
444
- /**
445
- * Starts listening to {@link module:engine/model/model~Model#deleteContent} and {@link module:engine/model/model~Model#insertContent}
446
- * and checks whether typing over the link. If so, attributes of removed text are preserved and applied to the inserted text.
447
- *
448
- * The purpose of this action is to allow modifying a text without loosing the `linkHref` attribute (and other).
449
- *
450
- * See https://github.com/ckeditor/ckeditor5/issues/4762.
451
- *
452
- * @private
453
- */
454
- _enableTypingOverLink() {
455
- const editor = this.editor;
456
- const view = editor.editing.view;
457
-
458
- // Selection attributes when started typing over the link.
459
- let selectionAttributes;
460
-
461
- // Whether pressed `Backspace` or `Delete`. If so, attributes should not be preserved.
462
- let deletedContent;
463
-
464
- // Detect pressing `Backspace` / `Delete`.
465
- this.listenTo( view.document, 'delete', () => {
466
- deletedContent = true;
467
- }, { priority: 'high' } );
468
-
469
- // Listening to `model#deleteContent` allows detecting whether selected content was a link.
470
- // If so, before removing the element, we will copy its attributes.
471
- this.listenTo( editor.model, 'deleteContent', () => {
472
- const selection = editor.model.document.selection;
473
-
474
- // Copy attributes only if anything is selected.
475
- if ( selection.isCollapsed ) {
476
- return;
477
- }
478
-
479
- // When the content was deleted, do not preserve attributes.
480
- if ( deletedContent ) {
481
- deletedContent = false;
482
-
483
- return;
484
- }
485
-
486
- // Enabled only when typing.
487
- if ( !isTyping( editor ) ) {
488
- return;
489
- }
490
-
491
- if ( shouldCopyAttributes( editor.model ) ) {
492
- selectionAttributes = selection.getAttributes();
493
- }
494
- }, { priority: 'high' } );
495
-
496
- // Listening to `model#insertContent` allows detecting the content insertion.
497
- // We want to apply attributes that were removed while typing over the link.
498
- this.listenTo( editor.model, 'insertContent', ( evt, [ element ] ) => {
499
- deletedContent = false;
500
-
501
- // Enabled only when typing.
502
- if ( !isTyping( editor ) ) {
503
- return;
504
- }
505
-
506
- if ( !selectionAttributes ) {
507
- return;
508
- }
509
-
510
- editor.model.change( writer => {
511
- for ( const [ attribute, value ] of selectionAttributes ) {
512
- writer.setAttribute( attribute, value, element );
513
- }
514
- } );
515
-
516
- selectionAttributes = null;
517
- }, { priority: 'high' } );
518
- }
519
-
520
- /**
521
- * Starts listening to {@link module:engine/model/model~Model#deleteContent} and checks whether
522
- * removing a content right after the "linkHref" attribute.
523
- *
524
- * If so, the selection should not preserve the `linkHref` attribute. However, if
525
- * the {@link module:typing/twostepcaretmovement~TwoStepCaretMovement} plugin is active and
526
- * the selection has the "linkHref" attribute due to overriden gravity (at the end), the `linkHref` attribute should stay untouched.
527
- *
528
- * The purpose of this action is to allow removing the link text and keep the selection outside the link.
529
- *
530
- * See https://github.com/ckeditor/ckeditor5/issues/7521.
531
- *
532
- * @private
533
- */
534
- _handleDeleteContentAfterLink() {
535
- const editor = this.editor;
536
- const model = editor.model;
537
- const selection = model.document.selection;
538
- const view = editor.editing.view;
539
-
540
- // A flag whether attributes `linkHref` attribute should be preserved.
541
- let shouldPreserveAttributes = false;
542
-
543
- // A flag whether the `Backspace` key was pressed.
544
- let hasBackspacePressed = false;
545
-
546
- // Detect pressing `Backspace`.
547
- this.listenTo( view.document, 'delete', ( evt, data ) => {
548
- hasBackspacePressed = data.direction === 'backward';
549
- }, { priority: 'high' } );
550
-
551
- // Before removing the content, check whether the selection is inside a link or at the end of link but with 2-SCM enabled.
552
- // If so, we want to preserve link attributes.
553
- this.listenTo( model, 'deleteContent', () => {
554
- // Reset the state.
555
- shouldPreserveAttributes = false;
556
-
557
- const position = selection.getFirstPosition();
558
- const linkHref = selection.getAttribute( 'linkHref' );
559
-
560
- if ( !linkHref ) {
561
- return;
562
- }
563
-
564
- const linkRange = findAttributeRange( position, 'linkHref', linkHref, model );
565
-
566
- // Preserve `linkHref` attribute if the selection is in the middle of the link or
567
- // the selection is at the end of the link and 2-SCM is activated.
568
- shouldPreserveAttributes = linkRange.containsPosition( position ) || linkRange.end.isEqual( position );
569
- }, { priority: 'high' } );
570
-
571
- // After removing the content, check whether the current selection should preserve the `linkHref` attribute.
572
- this.listenTo( model, 'deleteContent', () => {
573
- // If didn't press `Backspace`.
574
- if ( !hasBackspacePressed ) {
575
- return;
576
- }
577
-
578
- hasBackspacePressed = false;
579
-
580
- // Disable the mechanism if inside a link (`<$text url="foo">F[]oo</$text>` or <$text url="foo">Foo[]</$text>`).
581
- if ( shouldPreserveAttributes ) {
582
- return;
583
- }
584
-
585
- // Use `model.enqueueChange()` in order to execute the callback at the end of the changes process.
586
- editor.model.enqueueChange( writer => {
587
- removeLinkAttributesFromSelection( writer, getLinkAttributesAllowedOnText( model.schema ) );
588
- } );
589
- }, { priority: 'low' } );
590
- }
591
-
592
- /**
593
- * Enables URL fixing on pasting.
594
- *
595
- * @private
596
- */
597
- _enableClipboardIntegration() {
598
- const editor = this.editor;
599
- const model = editor.model;
600
- const defaultProtocol = this.editor.config.get( 'link.defaultProtocol' );
601
-
602
- if ( !defaultProtocol ) {
603
- return;
604
- }
605
-
606
- this.listenTo( editor.plugins.get( 'ClipboardPipeline' ), 'contentInsertion', ( evt, data ) => {
607
- model.change( writer => {
608
- const range = writer.createRangeIn( data.content );
609
-
610
- for ( const item of range.getItems() ) {
611
- if ( item.hasAttribute( 'linkHref' ) ) {
612
- const newLink = addLinkProtocolIfApplicable( item.getAttribute( 'linkHref' ), defaultProtocol );
613
-
614
- writer.setAttribute( 'linkHref', newLink, item );
615
- }
616
- }
617
- } );
618
- } );
619
- }
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ static get pluginName() {
33
+ return 'LinkEditing';
34
+ }
35
+ /**
36
+ * @inheritDoc
37
+ */
38
+ static get requires() {
39
+ // Clipboard is required for handling cut and paste events while typing over the link.
40
+ return [TwoStepCaretMovement, Input, ClipboardPipeline];
41
+ }
42
+ /**
43
+ * @inheritDoc
44
+ */
45
+ constructor(editor) {
46
+ super(editor);
47
+ editor.config.define('link', {
48
+ addTargetToExternalLinks: false
49
+ });
50
+ }
51
+ /**
52
+ * @inheritDoc
53
+ */
54
+ init() {
55
+ const editor = this.editor;
56
+ // Allow link attribute on all inline nodes.
57
+ editor.model.schema.extend('$text', { allowAttributes: 'linkHref' });
58
+ editor.conversion.for('dataDowncast')
59
+ .attributeToElement({ model: 'linkHref', view: createLinkElement });
60
+ editor.conversion.for('editingDowncast')
61
+ .attributeToElement({ model: 'linkHref', view: (href, conversionApi) => {
62
+ return createLinkElement(ensureSafeUrl(href), conversionApi);
63
+ } });
64
+ editor.conversion.for('upcast')
65
+ .elementToAttribute({
66
+ view: {
67
+ name: 'a',
68
+ attributes: {
69
+ href: true
70
+ }
71
+ },
72
+ model: {
73
+ key: 'linkHref',
74
+ value: (viewElement) => viewElement.getAttribute('href')
75
+ }
76
+ });
77
+ // Create linking commands.
78
+ editor.commands.add('link', new LinkCommand(editor));
79
+ editor.commands.add('unlink', new UnlinkCommand(editor));
80
+ const linkDecorators = getLocalizedDecorators(editor.t, normalizeDecorators(editor.config.get('link.decorators')));
81
+ this._enableAutomaticDecorators(linkDecorators
82
+ .filter((item) => item.mode === DECORATOR_AUTOMATIC));
83
+ this._enableManualDecorators(linkDecorators
84
+ .filter((item) => item.mode === DECORATOR_MANUAL));
85
+ // Enable two-step caret movement for `linkHref` attribute.
86
+ const twoStepCaretMovementPlugin = editor.plugins.get(TwoStepCaretMovement);
87
+ twoStepCaretMovementPlugin.registerAttribute('linkHref');
88
+ // Setup highlight over selected link.
89
+ inlineHighlight(editor, 'linkHref', 'a', HIGHLIGHT_CLASS);
90
+ // Handle link following by CTRL+click or ALT+ENTER
91
+ this._enableLinkOpen();
92
+ // Change the attributes of the selection in certain situations after the link was inserted into the document.
93
+ this._enableInsertContentSelectionAttributesFixer();
94
+ // Handle a click at the beginning/end of a link element.
95
+ this._enableClickingAfterLink();
96
+ // Handle typing over the link.
97
+ this._enableTypingOverLink();
98
+ // Handle removing the content after the link element.
99
+ this._handleDeleteContentAfterLink();
100
+ // Handle adding default protocol to pasted links.
101
+ this._enableClipboardIntegration();
102
+ }
103
+ /**
104
+ * Processes an array of configured {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition automatic decorators}
105
+ * and registers a {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher downcast dispatcher}
106
+ * for each one of them. Downcast dispatchers are obtained using the
107
+ * {@link module:link/utils/automaticdecorators~AutomaticDecorators#getDispatcher} method.
108
+ *
109
+ * **Note**: This method also activates the automatic external link decorator if enabled with
110
+ * {@link module:link/linkconfig~LinkConfig#addTargetToExternalLinks `config.link.addTargetToExternalLinks`}.
111
+ */
112
+ _enableAutomaticDecorators(automaticDecoratorDefinitions) {
113
+ const editor = this.editor;
114
+ // Store automatic decorators in the command instance as we do the same with manual decorators.
115
+ // Thanks to that, `LinkImageEditing` plugin can re-use the same definitions.
116
+ const command = editor.commands.get('link');
117
+ const automaticDecorators = command.automaticDecorators;
118
+ // Adds a default decorator for external links.
119
+ if (editor.config.get('link.addTargetToExternalLinks')) {
120
+ automaticDecorators.add({
121
+ id: 'linkIsExternal',
122
+ mode: DECORATOR_AUTOMATIC,
123
+ callback: url => !!url && EXTERNAL_LINKS_REGEXP.test(url),
124
+ attributes: {
125
+ target: '_blank',
126
+ rel: 'noopener noreferrer'
127
+ }
128
+ });
129
+ }
130
+ automaticDecorators.add(automaticDecoratorDefinitions);
131
+ if (automaticDecorators.length) {
132
+ editor.conversion.for('downcast').add(automaticDecorators.getDispatcher());
133
+ }
134
+ }
135
+ /**
136
+ * Processes an array of configured {@link module:link/linkconfig~LinkDecoratorManualDefinition manual decorators},
137
+ * transforms them into {@link module:link/utils/manualdecorator~ManualDecorator} instances and stores them in the
138
+ * {@link module:link/linkcommand~LinkCommand#manualDecorators} collection (a model for manual decorators state).
139
+ *
140
+ * Also registers an {@link module:engine/conversion/downcasthelpers~DowncastHelpers#attributeToElement attribute-to-element}
141
+ * converter for each manual decorator and extends the {@link module:engine/model/schema~Schema model's schema}
142
+ * with adequate model attributes.
143
+ */
144
+ _enableManualDecorators(manualDecoratorDefinitions) {
145
+ if (!manualDecoratorDefinitions.length) {
146
+ return;
147
+ }
148
+ const editor = this.editor;
149
+ const command = editor.commands.get('link');
150
+ const manualDecorators = command.manualDecorators;
151
+ manualDecoratorDefinitions.forEach(decoratorDefinition => {
152
+ editor.model.schema.extend('$text', { allowAttributes: decoratorDefinition.id });
153
+ // Keeps reference to manual decorator to decode its name to attributes during downcast.
154
+ const decorator = new ManualDecorator(decoratorDefinition);
155
+ manualDecorators.add(decorator);
156
+ editor.conversion.for('downcast').attributeToElement({
157
+ model: decorator.id,
158
+ view: (manualDecoratorValue, { writer, schema }, { item }) => {
159
+ // Manual decorators for block links are handled e.g. in LinkImageEditing.
160
+ if (!(item.is('selection') || schema.isInline(item))) {
161
+ return;
162
+ }
163
+ if (manualDecoratorValue) {
164
+ const element = writer.createAttributeElement('a', decorator.attributes, { priority: 5 });
165
+ if (decorator.classes) {
166
+ writer.addClass(decorator.classes, element);
167
+ }
168
+ for (const key in decorator.styles) {
169
+ writer.setStyle(key, decorator.styles[key], element);
170
+ }
171
+ writer.setCustomProperty('link', true, element);
172
+ return element;
173
+ }
174
+ }
175
+ });
176
+ editor.conversion.for('upcast').elementToAttribute({
177
+ view: {
178
+ name: 'a',
179
+ ...decorator._createPattern()
180
+ },
181
+ model: {
182
+ key: decorator.id
183
+ }
184
+ });
185
+ });
186
+ }
187
+ /**
188
+ * Attaches handlers for {@link module:engine/view/document~Document#event:enter} and
189
+ * {@link module:engine/view/document~Document#event:click} to enable link following.
190
+ */
191
+ _enableLinkOpen() {
192
+ const editor = this.editor;
193
+ const view = editor.editing.view;
194
+ const viewDocument = view.document;
195
+ this.listenTo(viewDocument, 'click', (evt, data) => {
196
+ const shouldOpen = env.isMac ? data.domEvent.metaKey : data.domEvent.ctrlKey;
197
+ if (!shouldOpen) {
198
+ return;
199
+ }
200
+ let clickedElement = data.domTarget;
201
+ if (clickedElement.tagName.toLowerCase() != 'a') {
202
+ clickedElement = clickedElement.closest('a');
203
+ }
204
+ if (!clickedElement) {
205
+ return;
206
+ }
207
+ const url = clickedElement.getAttribute('href');
208
+ if (!url) {
209
+ return;
210
+ }
211
+ evt.stop();
212
+ data.preventDefault();
213
+ openLink(url);
214
+ }, { context: '$capture' });
215
+ // Open link on Alt+Enter.
216
+ this.listenTo(viewDocument, 'keydown', (evt, data) => {
217
+ const linkCommand = editor.commands.get('link');
218
+ const url = linkCommand.value;
219
+ const shouldOpen = !!url && data.keyCode === keyCodes.enter && data.altKey;
220
+ if (!shouldOpen) {
221
+ return;
222
+ }
223
+ evt.stop();
224
+ openLink(url);
225
+ });
226
+ }
227
+ /**
228
+ * Starts listening to {@link module:engine/model/model~Model#event:insertContent} and corrects the model
229
+ * selection attributes if the selection is at the end of a link after inserting the content.
230
+ *
231
+ * The purpose of this action is to improve the overall UX because the user is no longer "trapped" by the
232
+ * `linkHref` attribute of the selection and they can type a "clean" (`linkHref`–less) text right away.
233
+ *
234
+ * See https://github.com/ckeditor/ckeditor5/issues/6053.
235
+ */
236
+ _enableInsertContentSelectionAttributesFixer() {
237
+ const editor = this.editor;
238
+ const model = editor.model;
239
+ const selection = model.document.selection;
240
+ this.listenTo(model, 'insertContent', () => {
241
+ const nodeBefore = selection.anchor.nodeBefore;
242
+ const nodeAfter = selection.anchor.nodeAfter;
243
+ // NOTE: ↰ and ↱ represent the gravity of the selection.
244
+ // The only truly valid case is:
245
+ //
246
+ // ↰
247
+ // ...<$text linkHref="foo">INSERTED[]</$text>
248
+ //
249
+ // If the selection is not "trapped" by the `linkHref` attribute after inserting, there's nothing
250
+ // to fix there.
251
+ if (!selection.hasAttribute('linkHref')) {
252
+ return;
253
+ }
254
+ // Filter out the following case where a link with the same href (e.g. <a href="foo">INSERTED</a>) is inserted
255
+ // in the middle of an existing link:
256
+ //
257
+ // Before insertion:
258
+ // ↰
259
+ // <$text linkHref="foo">l[]ink</$text>
260
+ //
261
+ // Expected after insertion:
262
+ // ↰
263
+ // <$text linkHref="foo">lINSERTED[]ink</$text>
264
+ //
265
+ if (!nodeBefore) {
266
+ return;
267
+ }
268
+ // Filter out the following case where the selection has the "linkHref" attribute because the
269
+ // gravity is overridden and some text with another attribute (e.g. <b>INSERTED</b>) is inserted:
270
+ //
271
+ // Before insertion:
272
+ //
273
+ // ↱
274
+ // <$text linkHref="foo">[]link</$text>
275
+ //
276
+ // Expected after insertion:
277
+ //
278
+ // ↱
279
+ // <$text bold="true">INSERTED</$text><$text linkHref="foo">[]link</$text>
280
+ //
281
+ if (!nodeBefore.hasAttribute('linkHref')) {
282
+ return;
283
+ }
284
+ // Filter out the following case where a link is a inserted in the middle (or before) another link
285
+ // (different URLs, so they will not merge). In this (let's say weird) case, we can leave the selection
286
+ // attributes as they are because the user will end up writing in one link or another anyway.
287
+ //
288
+ // Before insertion:
289
+ //
290
+ // ↰
291
+ // <$text linkHref="foo">l[]ink</$text>
292
+ //
293
+ // Expected after insertion:
294
+ //
295
+ // ↰
296
+ // <$text linkHref="foo">l</$text><$text linkHref="bar">INSERTED[]</$text><$text linkHref="foo">ink</$text>
297
+ //
298
+ if (nodeAfter && nodeAfter.hasAttribute('linkHref')) {
299
+ return;
300
+ }
301
+ model.change(writer => {
302
+ removeLinkAttributesFromSelection(writer, getLinkAttributesAllowedOnText(model.schema));
303
+ });
304
+ }, { priority: 'low' });
305
+ }
306
+ /**
307
+ * Starts listening to {@link module:engine/view/document~Document#event:mousedown} and
308
+ * {@link module:engine/view/document~Document#event:selectionChange} and puts the selection before/after a link node
309
+ * if clicked at the beginning/ending of the link.
310
+ *
311
+ * The purpose of this action is to allow typing around the link node directly after a click.
312
+ *
313
+ * See https://github.com/ckeditor/ckeditor5/issues/1016.
314
+ */
315
+ _enableClickingAfterLink() {
316
+ const editor = this.editor;
317
+ const model = editor.model;
318
+ editor.editing.view.addObserver(MouseObserver);
319
+ let clicked = false;
320
+ // Detect the click.
321
+ this.listenTo(editor.editing.view.document, 'mousedown', () => {
322
+ clicked = true;
323
+ });
324
+ // When the selection has changed...
325
+ this.listenTo(editor.editing.view.document, 'selectionChange', () => {
326
+ if (!clicked) {
327
+ return;
328
+ }
329
+ // ...and it was caused by the click...
330
+ clicked = false;
331
+ const selection = model.document.selection;
332
+ // ...and no text is selected...
333
+ if (!selection.isCollapsed) {
334
+ return;
335
+ }
336
+ // ...and clicked text is the link...
337
+ if (!selection.hasAttribute('linkHref')) {
338
+ return;
339
+ }
340
+ const position = selection.getFirstPosition();
341
+ const linkRange = findAttributeRange(position, 'linkHref', selection.getAttribute('linkHref'), model);
342
+ // ...check whether clicked start/end boundary of the link.
343
+ // If so, remove the `linkHref` attribute.
344
+ if (position.isTouching(linkRange.start) || position.isTouching(linkRange.end)) {
345
+ model.change(writer => {
346
+ removeLinkAttributesFromSelection(writer, getLinkAttributesAllowedOnText(model.schema));
347
+ });
348
+ }
349
+ });
350
+ }
351
+ /**
352
+ * Starts listening to {@link module:engine/model/model~Model#deleteContent} and {@link module:engine/model/model~Model#insertContent}
353
+ * and checks whether typing over the link. If so, attributes of removed text are preserved and applied to the inserted text.
354
+ *
355
+ * The purpose of this action is to allow modifying a text without loosing the `linkHref` attribute (and other).
356
+ *
357
+ * See https://github.com/ckeditor/ckeditor5/issues/4762.
358
+ */
359
+ _enableTypingOverLink() {
360
+ const editor = this.editor;
361
+ const view = editor.editing.view;
362
+ // Selection attributes when started typing over the link.
363
+ let selectionAttributes = null;
364
+ // Whether pressed `Backspace` or `Delete`. If so, attributes should not be preserved.
365
+ let deletedContent = false;
366
+ // Detect pressing `Backspace` / `Delete`.
367
+ this.listenTo(view.document, 'delete', () => {
368
+ deletedContent = true;
369
+ }, { priority: 'high' });
370
+ // Listening to `model#deleteContent` allows detecting whether selected content was a link.
371
+ // If so, before removing the element, we will copy its attributes.
372
+ this.listenTo(editor.model, 'deleteContent', () => {
373
+ const selection = editor.model.document.selection;
374
+ // Copy attributes only if anything is selected.
375
+ if (selection.isCollapsed) {
376
+ return;
377
+ }
378
+ // When the content was deleted, do not preserve attributes.
379
+ if (deletedContent) {
380
+ deletedContent = false;
381
+ return;
382
+ }
383
+ // Enabled only when typing.
384
+ if (!isTyping(editor)) {
385
+ return;
386
+ }
387
+ if (shouldCopyAttributes(editor.model)) {
388
+ selectionAttributes = selection.getAttributes();
389
+ }
390
+ }, { priority: 'high' });
391
+ // Listening to `model#insertContent` allows detecting the content insertion.
392
+ // We want to apply attributes that were removed while typing over the link.
393
+ this.listenTo(editor.model, 'insertContent', (evt, [element]) => {
394
+ deletedContent = false;
395
+ // Enabled only when typing.
396
+ if (!isTyping(editor)) {
397
+ return;
398
+ }
399
+ if (!selectionAttributes) {
400
+ return;
401
+ }
402
+ editor.model.change(writer => {
403
+ for (const [attribute, value] of selectionAttributes) {
404
+ writer.setAttribute(attribute, value, element);
405
+ }
406
+ });
407
+ selectionAttributes = null;
408
+ }, { priority: 'high' });
409
+ }
410
+ /**
411
+ * Starts listening to {@link module:engine/model/model~Model#deleteContent} and checks whether
412
+ * removing a content right after the "linkHref" attribute.
413
+ *
414
+ * If so, the selection should not preserve the `linkHref` attribute. However, if
415
+ * the {@link module:typing/twostepcaretmovement~TwoStepCaretMovement} plugin is active and
416
+ * the selection has the "linkHref" attribute due to overriden gravity (at the end), the `linkHref` attribute should stay untouched.
417
+ *
418
+ * The purpose of this action is to allow removing the link text and keep the selection outside the link.
419
+ *
420
+ * See https://github.com/ckeditor/ckeditor5/issues/7521.
421
+ */
422
+ _handleDeleteContentAfterLink() {
423
+ const editor = this.editor;
424
+ const model = editor.model;
425
+ const selection = model.document.selection;
426
+ const view = editor.editing.view;
427
+ // A flag whether attributes `linkHref` attribute should be preserved.
428
+ let shouldPreserveAttributes = false;
429
+ // A flag whether the `Backspace` key was pressed.
430
+ let hasBackspacePressed = false;
431
+ // Detect pressing `Backspace`.
432
+ this.listenTo(view.document, 'delete', (evt, data) => {
433
+ hasBackspacePressed = data.direction === 'backward';
434
+ }, { priority: 'high' });
435
+ // Before removing the content, check whether the selection is inside a link or at the end of link but with 2-SCM enabled.
436
+ // If so, we want to preserve link attributes.
437
+ this.listenTo(model, 'deleteContent', () => {
438
+ // Reset the state.
439
+ shouldPreserveAttributes = false;
440
+ const position = selection.getFirstPosition();
441
+ const linkHref = selection.getAttribute('linkHref');
442
+ if (!linkHref) {
443
+ return;
444
+ }
445
+ const linkRange = findAttributeRange(position, 'linkHref', linkHref, model);
446
+ // Preserve `linkHref` attribute if the selection is in the middle of the link or
447
+ // the selection is at the end of the link and 2-SCM is activated.
448
+ shouldPreserveAttributes = linkRange.containsPosition(position) || linkRange.end.isEqual(position);
449
+ }, { priority: 'high' });
450
+ // After removing the content, check whether the current selection should preserve the `linkHref` attribute.
451
+ this.listenTo(model, 'deleteContent', () => {
452
+ // If didn't press `Backspace`.
453
+ if (!hasBackspacePressed) {
454
+ return;
455
+ }
456
+ hasBackspacePressed = false;
457
+ // Disable the mechanism if inside a link (`<$text url="foo">F[]oo</$text>` or <$text url="foo">Foo[]</$text>`).
458
+ if (shouldPreserveAttributes) {
459
+ return;
460
+ }
461
+ // Use `model.enqueueChange()` in order to execute the callback at the end of the changes process.
462
+ editor.model.enqueueChange(writer => {
463
+ removeLinkAttributesFromSelection(writer, getLinkAttributesAllowedOnText(model.schema));
464
+ });
465
+ }, { priority: 'low' });
466
+ }
467
+ /**
468
+ * Enables URL fixing on pasting.
469
+ */
470
+ _enableClipboardIntegration() {
471
+ const editor = this.editor;
472
+ const model = editor.model;
473
+ const defaultProtocol = this.editor.config.get('link.defaultProtocol');
474
+ if (!defaultProtocol) {
475
+ return;
476
+ }
477
+ this.listenTo(editor.plugins.get('ClipboardPipeline'), 'contentInsertion', (evt, data) => {
478
+ model.change(writer => {
479
+ const range = writer.createRangeIn(data.content);
480
+ for (const item of range.getItems()) {
481
+ if (item.hasAttribute('linkHref')) {
482
+ const newLink = addLinkProtocolIfApplicable(item.getAttribute('linkHref'), defaultProtocol);
483
+ writer.setAttribute('linkHref', newLink, item);
484
+ }
485
+ }
486
+ });
487
+ });
488
+ }
620
489
  }
621
-
622
- // Make the selection free of link-related model attributes.
623
- // All link-related model attributes start with "link". That includes not only "linkHref"
624
- // but also all decorator attributes (they have dynamic names), or even custom plugins.
625
- //
626
- // @param {module:engine/model/writer~Writer} writer
627
- // @param {Array.<String>} linkAttributes
628
- function removeLinkAttributesFromSelection( writer, linkAttributes ) {
629
- writer.removeSelectionAttribute( 'linkHref' );
630
-
631
- for ( const attribute of linkAttributes ) {
632
- writer.removeSelectionAttribute( attribute );
633
- }
490
+ /**
491
+ * Make the selection free of link-related model attributes.
492
+ * All link-related model attributes start with "link". That includes not only "linkHref"
493
+ * but also all decorator attributes (they have dynamic names), or even custom plugins.
494
+ */
495
+ function removeLinkAttributesFromSelection(writer, linkAttributes) {
496
+ writer.removeSelectionAttribute('linkHref');
497
+ for (const attribute of linkAttributes) {
498
+ writer.removeSelectionAttribute(attribute);
499
+ }
634
500
  }
635
-
636
- // Checks whether selection's attributes should be copied to the new inserted text.
637
- //
638
- // @param {module:engine/model/model~Model} model
639
- // @returns {Boolean}
640
- function shouldCopyAttributes( model ) {
641
- const selection = model.document.selection;
642
- const firstPosition = selection.getFirstPosition();
643
- const lastPosition = selection.getLastPosition();
644
- const nodeAtFirstPosition = firstPosition.nodeAfter;
645
-
646
- // The text link node does not exist...
647
- if ( !nodeAtFirstPosition ) {
648
- return false;
649
- }
650
-
651
- // ...or it isn't the text node...
652
- if ( !nodeAtFirstPosition.is( '$text' ) ) {
653
- return false;
654
- }
655
-
656
- // ...or isn't the link.
657
- if ( !nodeAtFirstPosition.hasAttribute( 'linkHref' ) ) {
658
- return false;
659
- }
660
-
661
- // `textNode` = the position is inside the link element.
662
- // `nodeBefore` = the position is at the end of the link element.
663
- const nodeAtLastPosition = lastPosition.textNode || lastPosition.nodeBefore;
664
-
665
- // If both references the same node selection contains a single text node.
666
- if ( nodeAtFirstPosition === nodeAtLastPosition ) {
667
- return true;
668
- }
669
-
670
- // If nodes are not equal, maybe the link nodes has defined additional attributes inside.
671
- // First, we need to find the entire link range.
672
- const linkRange = findAttributeRange( firstPosition, 'linkHref', nodeAtFirstPosition.getAttribute( 'linkHref' ), model );
673
-
674
- // Then we can check whether selected range is inside the found link range. If so, attributes should be preserved.
675
- return linkRange.containsRange( model.createRange( firstPosition, lastPosition ), true );
501
+ /**
502
+ * Checks whether selection's attributes should be copied to the new inserted text.
503
+ */
504
+ function shouldCopyAttributes(model) {
505
+ const selection = model.document.selection;
506
+ const firstPosition = selection.getFirstPosition();
507
+ const lastPosition = selection.getLastPosition();
508
+ const nodeAtFirstPosition = firstPosition.nodeAfter;
509
+ // The text link node does not exist...
510
+ if (!nodeAtFirstPosition) {
511
+ return false;
512
+ }
513
+ // ...or it isn't the text node...
514
+ if (!nodeAtFirstPosition.is('$text')) {
515
+ return false;
516
+ }
517
+ // ...or isn't the link.
518
+ if (!nodeAtFirstPosition.hasAttribute('linkHref')) {
519
+ return false;
520
+ }
521
+ // `textNode` = the position is inside the link element.
522
+ // `nodeBefore` = the position is at the end of the link element.
523
+ const nodeAtLastPosition = lastPosition.textNode || lastPosition.nodeBefore;
524
+ // If both references the same node selection contains a single text node.
525
+ if (nodeAtFirstPosition === nodeAtLastPosition) {
526
+ return true;
527
+ }
528
+ // If nodes are not equal, maybe the link nodes has defined additional attributes inside.
529
+ // First, we need to find the entire link range.
530
+ const linkRange = findAttributeRange(firstPosition, 'linkHref', nodeAtFirstPosition.getAttribute('linkHref'), model);
531
+ // Then we can check whether selected range is inside the found link range. If so, attributes should be preserved.
532
+ return linkRange.containsRange(model.createRange(firstPosition, lastPosition), true);
676
533
  }
677
-
678
- // Checks whether provided changes were caused by typing.
679
- //
680
- // @params {module:core/editor/editor~Editor} editor
681
- // @returns {Boolean}
682
- function isTyping( editor ) {
683
- const currentBatch = editor.model.change( writer => writer.batch );
684
-
685
- return currentBatch.isTyping;
534
+ /**
535
+ * Checks whether provided changes were caused by typing.
536
+ */
537
+ function isTyping(editor) {
538
+ const currentBatch = editor.model.change(writer => writer.batch);
539
+ return currentBatch.isTyping;
686
540
  }
687
-
688
- // Returns an array containing names of the attributes allowed on `$text` that describes the link item.
689
- //
690
- // @param {module:engine/model/schema~Schema} schema
691
- // @returns {Array.<String>}
692
- function getLinkAttributesAllowedOnText( schema ) {
693
- const textAttributes = schema.getDefinition( '$text' ).allowAttributes;
694
-
695
- return textAttributes.filter( attribute => attribute.startsWith( 'link' ) );
541
+ /**
542
+ * Returns an array containing names of the attributes allowed on `$text` that describes the link item.
543
+ */
544
+ function getLinkAttributesAllowedOnText(schema) {
545
+ const textAttributes = schema.getDefinition('$text').allowAttributes;
546
+ return textAttributes.filter(attribute => attribute.startsWith('link'));
696
547
  }