8
0
Просмотр исходного кода

Use explicit schema definition for codeBlock.

Maciej Gołaszewski 6 лет назад
Родитель
Сommit
3b5a109156
1 измененных файлов с 10 добавлено и 6 удалено
  1. 10 6
      packages/ckeditor5-code-block/src/codeblockediting.js

+ 10 - 6
packages/ckeditor5-code-block/src/codeblockediting.js

@@ -107,16 +107,20 @@ export default class CodeBlockEditing extends Plugin {
 		editor.keystrokes.set( 'Tab', getCommandExecuter( 'indentCodeBlock' ) );
 		editor.keystrokes.set( 'Shift+Tab', getCommandExecuter( 'outdentCodeBlock' ) );
 
-		// Schema.
 		schema.register( 'codeBlock', {
-			inheritAllFrom: '$block',
+			allowWhere: '$block',
+			isBlock: true,
 			allowAttributes: [ 'language' ]
 		} );
 
-		// Disallow all attributes in `codeBlock`.
-		schema.addAttributeCheck( ( context, attributeName ) => {
-			if ( context.endsWith( 'codeBlock' ) || context.endsWith( 'codeBlock $text' ) ) {
-				return attributeName === 'language';
+		schema.extend( '$text', {
+			allowIn: 'codeBlock'
+		} );
+
+		// Disallow all attributes on $text inside `codeBlock`.
+		schema.addAttributeCheck( context => {
+			if ( context.endsWith( 'codeBlock $text' ) ) {
+				return false;
 			}
 		} );