Explorar el Código

Use explicit schema definition for codeBlock.

Maciej Gołaszewski hace 6 años
padre
commit
3b5a109156
Se han modificado 1 ficheros con 10 adiciones y 6 borrados
  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( 'Tab', getCommandExecuter( 'indentCodeBlock' ) );
 		editor.keystrokes.set( 'Shift+Tab', getCommandExecuter( 'outdentCodeBlock' ) );
 		editor.keystrokes.set( 'Shift+Tab', getCommandExecuter( 'outdentCodeBlock' ) );
 
 
-		// Schema.
 		schema.register( 'codeBlock', {
 		schema.register( 'codeBlock', {
-			inheritAllFrom: '$block',
+			allowWhere: '$block',
+			isBlock: true,
 			allowAttributes: [ 'language' ]
 			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;
 			}
 			}
 		} );
 		} );