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

Commit

Permalink
Merge 403cdcf into 613bf3c
Browse files Browse the repository at this point in the history
  • Loading branch information
jodator committed Oct 11, 2019
2 parents 613bf3c + 403cdcf commit cdb994f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 22 deletions.
2 changes: 2 additions & 0 deletions docs/_snippets/framework/build-extending-content-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import ClassicEditor from '@ckeditor/ckeditor5-build-classic/src/ckeditor';
import Code from '@ckeditor/ckeditor5-basic-styles/src/code';
import Font from '@ckeditor/ckeditor5-font/src/font';
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';

ClassicEditor.builtinPlugins.push( Code );
ClassicEditor.builtinPlugins.push( Font );

window.ClassicEditor = ClassicEditor;
window.Plugin = Plugin;
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,32 @@
* For licensing, see LICENSE.md.
*/

/* globals ClassicEditor, console, window, document */
/* globals ClassicEditor, Plugin, 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 extends Plugin {
/**
* 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 @@ -287,19 +287,31 @@ To overcome this limitation it is sufficient to write a custom converter that ad
The sample below is extensible. To add your own attributes to preserve, just add another `setupCustomAttributeConversion()` call with desired names.

```js
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';

/**
* 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 extends Plugin {

/**
* 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 Expand Up @@ -451,4 +463,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 cdb994f

Please sign in to comment.