@ckeditor/ckeditor5-code-block 0.0.0-nightly-20240604.1 → 0.0.0-nightly-20240605.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-code-block",
3
- "version": "0.0.0-nightly-20240604.1",
3
+ "version": "0.0.0-nightly-20240605.0",
4
4
  "description": "Code block feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -13,7 +13,7 @@
13
13
  "type": "module",
14
14
  "main": "src/index.js",
15
15
  "dependencies": {
16
- "ckeditor5": "0.0.0-nightly-20240604.1",
16
+ "ckeditor5": "0.0.0-nightly-20240605.0",
17
17
  "lodash-es": "4.17.21"
18
18
  },
19
19
  "author": "CKSource (http://cksource.com/)",
@@ -63,6 +63,8 @@ export default class CodeBlockEditing extends Plugin {
63
63
  const schema = editor.model.schema;
64
64
  const model = editor.model;
65
65
  const view = editor.editing.view;
66
+ const listEditing = editor.plugins.has('ListEditing') ?
67
+ editor.plugins.get('ListEditing') : null;
66
68
  const normalizedLanguagesDefs = getNormalizedAndLocalizedLanguageDefinitions(editor);
67
69
  // The main command.
68
70
  editor.commands.add('codeBlock', new CodeBlockCommand(editor));
@@ -83,19 +85,26 @@ export default class CodeBlockEditing extends Plugin {
83
85
  schema.register('codeBlock', {
84
86
  allowWhere: '$block',
85
87
  allowChildren: '$text',
86
- // Disallow `$inlineObject` and its derivatives like `inlineWidget` inside `codeBlock` to ensure that only text,
87
- // not other inline elements like inline images, are allowed. This maintains the semantic integrity of code blocks.
88
- disallowChildren: '$inlineObject',
89
- allowAttributes: ['language'],
90
- allowAttributesOf: '$listItem',
91
- isBlock: true
88
+ isBlock: true,
89
+ allowAttributes: ['language']
92
90
  });
93
- // Disallow all attributes on `$text` inside `codeBlock`.
94
- schema.addAttributeCheck(context => {
91
+ // Allow all list* attributes on `codeBlock` (integration with DocumentList).
92
+ // Disallow all attributes on $text inside `codeBlock`.
93
+ schema.addAttributeCheck((context, attributeName) => {
94
+ if (context.endsWith('codeBlock') &&
95
+ listEditing && listEditing.getListAttributeNames().includes(attributeName)) {
96
+ return true;
97
+ }
95
98
  if (context.endsWith('codeBlock $text')) {
96
99
  return false;
97
100
  }
98
101
  });
102
+ // Disallow object elements inside `codeBlock`. See #9567.
103
+ editor.model.schema.addChildCheck((context, childDefinition) => {
104
+ if (context.endsWith('codeBlock') && childDefinition.isObject) {
105
+ return false;
106
+ }
107
+ });
99
108
  // Conversion.
100
109
  editor.editing.downcastDispatcher.on('insert:codeBlock', modelToViewCodeBlockInsertion(model, normalizedLanguagesDefs, true));
101
110
  editor.data.downcastDispatcher.on('insert:codeBlock', modelToViewCodeBlockInsertion(model, normalizedLanguagesDefs));