-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
heading.ts
74 lines (61 loc) · 1.73 KB
/
heading.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/**
* @module html-support/integrations/heading
*/
import { Plugin, type Editor } from 'ckeditor5/src/core.js';
import type { HeadingOption } from '@ckeditor/ckeditor5-heading';
import { Enter } from 'ckeditor5/src/enter.js';
import DataSchema from '../dataschema.js';
/**
* Provides the General HTML Support integration with {@link module:heading/heading~Heading Heading} feature.
*/
export default class HeadingElementSupport extends Plugin {
/**
* @inheritDoc
*/
public static get requires() {
return [ DataSchema, Enter ] as const;
}
/**
* @inheritDoc
*/
public static get pluginName() {
return 'HeadingElementSupport' as const;
}
/**
* @inheritDoc
*/
public init(): void {
const editor = this.editor;
if ( !editor.plugins.has( 'HeadingEditing' ) ) {
return;
}
const options: Array<HeadingOption> = editor.config.get( 'heading.options' )!;
this.registerHeadingElements( editor, options );
}
/**
* Registers all elements supported by HeadingEditing to enable custom attributes for those elements.
*/
private registerHeadingElements( editor: Editor, options: Array<HeadingOption> ) {
const dataSchema = editor.plugins.get( DataSchema );
const headerModels = [];
for ( const option of options ) {
if ( 'model' in option && 'view' in option ) {
dataSchema.registerBlockElement( {
view: option.view as string,
model: option.model
} );
headerModels.push( option.model );
}
}
dataSchema.extendBlockElement( {
model: 'htmlHgroup',
modelSchema: {
allowChildren: headerModels
}
} );
}
}