Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge ee93cf6 into b2a8189
Browse files Browse the repository at this point in the history
  • Loading branch information
jodator committed Jan 21, 2020
2 parents b2a8189 + ee93cf6 commit 28976a6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,40 @@
* For licensing, see LICENSE.md.
*/

/* globals ClassicEditor, console, window, document */
/* globals ClassicEditor, console, window, document */

import { CS_CONFIG } from '@ckeditor/ckeditor5-cloud-services/tests/_utils/cloud-services-config';

/**
* Plugin that converts custom attributes for elements that are wrapped in <figure> in the view.
*/
function CustomFigureAttributes( editor ) {
// Define on which elements the CSS classes should be preserved:
setupCustomClassConversion( 'img', 'image', editor );
setupCustomClassConversion( 'table', 'table', editor );

editor.conversion.for( 'upcast' ).add( upcastCustomClasses( 'figure' ), { priority: 'low' } );

// Define custom attributes that should be preserved.
setupCustomAttributeConversion( 'img', 'image', 'id', editor );
setupCustomAttributeConversion( 'table', 'table', 'id', editor );
class CustomFigureAttributes {
/**
* Plugin's constructor - receives editor instance on creation.
*/
constructor( editor ) {
// Save reference to the editor.
this.editor = editor;
}

/**
* Setups conversion and extends table & image features schema.
*
* Schema extending must be done in the “afterInit()” call because plugins define their schema in “init()“.
*/
afterInit() {
const editor = this.editor;

// Define on which elements the CSS classes should be preserved:
setupCustomClassConversion( 'img', 'image', editor );
setupCustomClassConversion( 'table', 'table', editor );

editor.conversion.for( 'upcast' ).add( upcastCustomClasses( 'figure' ), { priority: 'low' } );

// Define custom attributes that should be preserved.
setupCustomAttributeConversion( 'img', 'image', 'id', editor );
setupCustomAttributeConversion( 'table', 'table', 'id', editor );
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,33 @@ The sample below is extensible. To add your own attributes to preserve, just add
/**
* Plugin that converts custom attributes for elements that are wrapped in <figure> in the view.
*/
function CustomFigureAttributes( editor ) {
// Define on which elements the CSS classes should be preserved:
setupCustomClassConversion( 'img', 'image', editor );
setupCustomClassConversion( 'table', 'table', editor );
class CustomFigureAttributes {
/**
* Plugin's constructor - receives editor instance on creation.
*/
constructor( editor ) {
// Save reference to the editor.
this.editor = editor;
}

/**
* Setups conversion and extends table & image features schema.
*
* Schema extending must be done in the “afterInit()” call because plugins define their schema in “init()“.
*/
afterInit() {
const editor = this.editor;

// Define on which elements the CSS classes should be preserved:
setupCustomClassConversion( 'img', 'image', editor );
setupCustomClassConversion( 'table', 'table', editor );

editor.conversion.for( 'upcast' ).add( upcastCustomClasses( 'figure' ), { priority: 'low' } );
editor.conversion.for( 'upcast' ).add( upcastCustomClasses( 'figure' ), { priority: 'low' } );

// Define custom attributes that should be preserved.
setupCustomAttributeConversion( 'img', 'image', 'id', editor );
setupCustomAttributeConversion( 'table', 'table', 'id', editor );
// Define custom attributes that should be preserved.
setupCustomAttributeConversion( 'img', 'image', 'id', editor );
setupCustomAttributeConversion( 'table', 'table', 'id', editor );
}
}

/**
Expand Down Expand Up @@ -451,4 +468,4 @@ ClassicEditor

## What's next?

If you would like to read more about how to extend the output of existing CKEditor 5 features, refer to the {@link framework/guides/deep-dive/conversion-extending-output Extending the editor output} guide.
If you would like to read more about how to extend the output of existing CKEditor 5 features, refer to the {@link framework/guides/deep-dive/conversion-extending-output Extending the editor output} guide.

0 comments on commit 28976a6

Please sign in to comment.