|
@@ -8,8 +8,8 @@
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
|
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
|
|
-import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
|
|
|
|
|
-import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
|
|
|
|
|
|
|
+import { downcastAttributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
|
|
|
|
|
+import { upcastElementToAttribute, upcastAttributeToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
|
|
|
import AttributeCommand from './attributecommand';
|
|
import AttributeCommand from './attributecommand';
|
|
|
|
|
|
|
|
const STRIKETHROUGH = 'strikethrough';
|
|
const STRIKETHROUGH = 'strikethrough';
|
|
@@ -29,24 +29,20 @@ export default class StrikethroughEngine extends Plugin {
|
|
|
*/
|
|
*/
|
|
|
init() {
|
|
init() {
|
|
|
const editor = this.editor;
|
|
const editor = this.editor;
|
|
|
- const data = editor.data;
|
|
|
|
|
- const editing = editor.editing;
|
|
|
|
|
|
|
|
|
|
// Allow strikethrough attribute on text nodes.
|
|
// Allow strikethrough attribute on text nodes.
|
|
|
editor.model.schema.extend( '$text', { allowAttributes: STRIKETHROUGH } );
|
|
editor.model.schema.extend( '$text', { allowAttributes: STRIKETHROUGH } );
|
|
|
|
|
|
|
|
// Build converter from model to view for data and editing pipelines.
|
|
// Build converter from model to view for data and editing pipelines.
|
|
|
- buildModelConverter().for( data.modelToView, editing.modelToView )
|
|
|
|
|
- .fromAttribute( STRIKETHROUGH )
|
|
|
|
|
- .toElement( 's' );
|
|
|
|
|
|
|
+ editor.conversion.for( 'downcast' )
|
|
|
|
|
+ .add( downcastAttributeToElement( STRIKETHROUGH, { view: 's' } ) );
|
|
|
|
|
|
|
|
// Build converter from view to model for data pipeline.
|
|
// Build converter from view to model for data pipeline.
|
|
|
- buildViewConverter().for( data.viewToModel )
|
|
|
|
|
- .fromElement( 's' )
|
|
|
|
|
- .fromElement( 'del' )
|
|
|
|
|
- .fromElement( 'strike' )
|
|
|
|
|
- .fromAttribute( 'style', { 'text-decoration': 'line-through' } )
|
|
|
|
|
- .toAttribute( STRIKETHROUGH, true );
|
|
|
|
|
|
|
+ editor.conversion.for( 'upcast' )
|
|
|
|
|
+ .add( upcastElementToAttribute( { view: 's', model: STRIKETHROUGH } ) )
|
|
|
|
|
+ .add( upcastElementToAttribute( { view: 'del', model: STRIKETHROUGH } ) )
|
|
|
|
|
+ .add( upcastElementToAttribute( { view: 'strike', model: STRIKETHROUGH } ) )
|
|
|
|
|
+ .add( upcastAttributeToAttribute( { view: { style: { 'text-decoration': 'line-through' } }, model: STRIKETHROUGH } ) );
|
|
|
|
|
|
|
|
// Create strikethrough command.
|
|
// Create strikethrough command.
|
|
|
editor.commands.add( STRIKETHROUGH, new AttributeCommand( editor, STRIKETHROUGH ) );
|
|
editor.commands.add( STRIKETHROUGH, new AttributeCommand( editor, STRIKETHROUGH ) );
|