Sfoglia il codice sorgente

Use plugin import for custom figure attributes sample.

Maciej Gołaszewski 6 anni fa
parent
commit
ebb6dbc401

+ 11 - 5
packages/ckeditor5-engine/docs/_snippets/framework/extending-content-custom-figure-attributes.js

@@ -3,16 +3,22 @@
  * 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 ) {
-	// Schema extending must be done in the “afterInit()” call because plugins define their schema in “init()“.
-	this.afterInit = () => {
+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 );
@@ -22,7 +28,7 @@ function CustomFigureAttributes( editor ) {
 		// Define custom attributes that should be preserved.
 		setupCustomAttributeConversion( 'img', 'image', 'id', editor );
 		setupCustomAttributeConversion( 'table', 'table', 'id', editor );
-	};
+	}
 }
 
 /**

+ 13 - 4
packages/ckeditor5-engine/docs/framework/guides/deep-dive/conversion-preserving-custom-content.md

@@ -287,12 +287,21 @@ 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 ) {
-	// Schema extending must be done in the “afterInit()” call because plugins define their schema in “init()“.
-	this.afterInit = () => {
+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 );
@@ -302,7 +311,7 @@ function CustomFigureAttributes( editor ) {
 		// Define custom attributes that should be preserved.
 		setupCustomAttributeConversion( 'img', 'image', 'id', editor );
 		setupCustomAttributeConversion( 'table', 'table', 'id', editor );
-	};
+	}
 }
 
 /**