From 5ae67fda7ff1463c5f23374df5e2a40b652c4f03 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 2 Dec 2025 12:13:40 +0200 Subject: [PATCH] fix(ckeditor/math): math can be inserted in code blocks (closes #7913) --- packages/ckeditor5-math/src/mathediting.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/ckeditor5-math/src/mathediting.ts b/packages/ckeditor5-math/src/mathediting.ts index a5f1a11db..53b50614b 100644 --- a/packages/ckeditor5-math/src/mathediting.ts +++ b/packages/ckeditor5-math/src/mathediting.ts @@ -62,6 +62,16 @@ export default class MathEditing extends Plugin { allowAttributes: [ 'equation', 'type', 'display', 'fontSize', 'fontColor', 'fontBackgroundColor' ] } ); + // Prevent from being inserted inside + schema.addChildCheck( ( context, childDefinition ) => { + if ( childDefinition && childDefinition.name === 'mathtex-inline' ) { + // If the context is inside a codeBlock, disallow it + if ( context.endsWith( 'codeBlock' ) ) { + return false; + } + } + }); + schema.register( 'mathtex-display', { inheritAllFrom: '$blockObject', allowAttributes: [ 'equation', 'type', 'display', 'fontSize', 'fontColor' ]