UNPKG

1.41 kBJavaScriptView Raw
1/**
2 * @license Copyright (c) 2003-2022, 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/**
7 * @module basic-styles/superscript/superscriptediting
8 */
9
10import { Plugin } from 'ckeditor5/src/core';
11import AttributeCommand from '../attributecommand';
12
13const SUPERSCRIPT = 'superscript';
14
15/**
16 * The superscript editing feature.
17 *
18 * It registers the `super` command and introduces the `super` attribute in the model which renders to the view
19 * as a `<super>` element.
20 *
21 * @extends module:core/plugin~Plugin
22 */
23export default class SuperscriptEditing extends Plugin {
24 /**
25 * @inheritDoc
26 */
27 static get pluginName() {
28 return 'SuperscriptEditing';
29 }
30
31 /**
32 * @inheritDoc
33 */
34 init() {
35 const editor = this.editor;
36 // Allow super attribute on text nodes.
37 editor.model.schema.extend( '$text', { allowAttributes: SUPERSCRIPT } );
38 editor.model.schema.setAttributeProperties( SUPERSCRIPT, {
39 isFormatting: true,
40 copyOnEnter: true
41 } );
42
43 // Build converter from model to view for data and editing pipelines.
44
45 editor.conversion.attributeToElement( {
46 model: SUPERSCRIPT,
47 view: 'sup',
48 upcastAlso: [
49 {
50 styles: {
51 'vertical-align': 'super'
52 }
53 }
54 ]
55 } );
56
57 // Create super command.
58 editor.commands.add( SUPERSCRIPT, new AttributeCommand( editor, SUPERSCRIPT ) );
59 }
60}