This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from ckeditor/t/76
Feature: Introduced the `Superscript` and the `Subscript` features. Closes #76. Closes #74. Thanks to @idleb!
- Loading branch information
Showing
25 changed files
with
646 additions
and
14 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
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
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
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
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,36 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/** | ||
* @module basic-styles/subscript | ||
*/ | ||
|
||
import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; | ||
import SubscriptEditing from './subscript/subscriptediting'; | ||
import SubscriptUI from './subscript/subscriptui'; | ||
|
||
/** | ||
* The subscript feature. | ||
* | ||
* It loads the {@link module:basic-styles/subscript/subscriptediting~SubscriptEditing} and | ||
* {@link module:basic-styles/subscript/subscriptui~SubscriptUI} plugins. | ||
* | ||
* @extends module:core/plugin~Plugin | ||
*/ | ||
export default class Subscript extends Plugin { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
static get requires() { | ||
return [ SubscriptEditing, SubscriptUI ]; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
static get pluginName() { | ||
return 'Subscript'; | ||
} | ||
} |
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,49 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/** | ||
* @module basic-styles/subscript/subscriptediting | ||
*/ | ||
|
||
import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; | ||
import AttributeCommand from '../attributecommand'; | ||
|
||
const SUBSCRIPT = 'subscript'; | ||
|
||
/** | ||
* The subscript editing feature. | ||
* | ||
* It registers the `sub` command and introduces the `sub` attribute in the model which renders to the view | ||
* as a `<sub>` element. | ||
* | ||
* @extends module:core/plugin~Plugin | ||
*/ | ||
export default class SubscriptEditing extends Plugin { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
init() { | ||
const editor = this.editor; | ||
// Allow sub attribute on text nodes. | ||
editor.model.schema.extend( '$text', { allowAttributes: SUBSCRIPT } ); | ||
|
||
// Build converter from model to view for data and editing pipelines. | ||
|
||
editor.conversion.attributeToElement( { | ||
model: SUBSCRIPT, | ||
view: 'sub', | ||
upcastAlso: [ | ||
{ | ||
styles: { | ||
'vertical-align': 'sub' | ||
} | ||
} | ||
] | ||
} ); | ||
|
||
// Create sub command. | ||
editor.commands.add( SUBSCRIPT, new AttributeCommand( editor, SUBSCRIPT ) ); | ||
} | ||
} |
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,49 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/** | ||
* @module basic-styles/subscript/subscriptui | ||
*/ | ||
|
||
import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; | ||
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; | ||
|
||
import subscriptIcon from '../../theme/icons/subscript.svg'; | ||
|
||
const SUBSCRIPT = 'subscript'; | ||
|
||
/** | ||
* The subscript UI feature. It introduces the Subscript button. | ||
* | ||
* @extends module:core/plugin~Plugin | ||
*/ | ||
export default class SubscriptUI extends Plugin { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
init() { | ||
const editor = this.editor; | ||
const t = editor.t; | ||
|
||
// Add subscript button to feature components. | ||
editor.ui.componentFactory.add( SUBSCRIPT, locale => { | ||
const command = editor.commands.get( SUBSCRIPT ); | ||
const view = new ButtonView( locale ); | ||
|
||
view.set( { | ||
label: t( 'Subscript' ), | ||
icon: subscriptIcon, | ||
tooltip: true | ||
} ); | ||
|
||
view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' ); | ||
|
||
// Execute command. | ||
this.listenTo( view, 'execute', () => editor.execute( SUBSCRIPT ) ); | ||
|
||
return view; | ||
} ); | ||
} | ||
} |
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,36 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/** | ||
* @module basic-styles/superscript | ||
*/ | ||
|
||
import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; | ||
import SuperscriptEditing from './superscript/superscriptediting'; | ||
import SuperscriptUI from './superscript/superscriptui'; | ||
|
||
/** | ||
* The superscript feature. | ||
* | ||
* It loads the {@link module:basic-styles/superscript/superscriptediting~SuperscriptEditing} and | ||
* {@link module:basic-styles/superscript/superscriptui~SuperscriptUI} plugins. | ||
* | ||
* @extends module:core/plugin~Plugin | ||
*/ | ||
export default class Superscript extends Plugin { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
static get requires() { | ||
return [ SuperscriptEditing, SuperscriptUI ]; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
static get pluginName() { | ||
return 'Superscript'; | ||
} | ||
} |
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,49 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/** | ||
* @module basic-styles/superscript/superscriptediting | ||
*/ | ||
|
||
import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; | ||
import AttributeCommand from '../attributecommand'; | ||
|
||
const SUPERSCRIPT = 'superscript'; | ||
|
||
/** | ||
* The superscript editing feature. | ||
* | ||
* It registers the `super` command and introduces the `super` attribute in the model which renders to the view | ||
* as a `<super>` element. | ||
* | ||
* @extends module:core/plugin~Plugin | ||
*/ | ||
export default class SuperscriptEditing extends Plugin { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
init() { | ||
const editor = this.editor; | ||
// Allow super attribute on text nodes. | ||
editor.model.schema.extend( '$text', { allowAttributes: SUPERSCRIPT } ); | ||
|
||
// Build converter from model to view for data and editing pipelines. | ||
|
||
editor.conversion.attributeToElement( { | ||
model: SUPERSCRIPT, | ||
view: 'sup', | ||
upcastAlso: [ | ||
{ | ||
styles: { | ||
'vertical-align': 'super' | ||
} | ||
} | ||
] | ||
} ); | ||
|
||
// Create super command. | ||
editor.commands.add( SUPERSCRIPT, new AttributeCommand( editor, SUPERSCRIPT ) ); | ||
} | ||
} |
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,49 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/** | ||
* @module basic-styles/superscript/superscriptui | ||
*/ | ||
|
||
import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; | ||
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; | ||
|
||
import superscriptIcon from '../../theme/icons/superscript.svg'; | ||
|
||
const SUPERSCRIPT = 'superscript'; | ||
|
||
/** | ||
* The superscript UI feature. It introduces the Superscript button. | ||
* | ||
* @extends module:core/plugin~Plugin | ||
*/ | ||
export default class SuperscriptUI extends Plugin { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
init() { | ||
const editor = this.editor; | ||
const t = editor.t; | ||
|
||
// Add superscript button to feature components. | ||
editor.ui.componentFactory.add( SUPERSCRIPT, locale => { | ||
const command = editor.commands.get( SUPERSCRIPT ); | ||
const view = new ButtonView( locale ); | ||
|
||
view.set( { | ||
label: t( 'Superscript' ), | ||
icon: superscriptIcon, | ||
tooltip: true | ||
} ); | ||
|
||
view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' ); | ||
|
||
// Execute command. | ||
this.listenTo( view, 'execute', () => editor.execute( SUPERSCRIPT ) ); | ||
|
||
return view; | ||
} ); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<div id="editor"> | ||
<p><i>This</i> <s>is</s> <code>an</code> <strong>editor</strong> <u>instance</u>.</p> | ||
<p><i>This</i> <s>is</s> <code>an</code> <strong>editor</strong> <u>instance</u>, X<sub>1</sub>, X<sup>2</sup>.</p> | ||
</div> |
Oops, something went wrong.