Skip to content

Commit

Permalink
!!!TASK: Simplify legacy autoparagraph: false mode
Browse files Browse the repository at this point in the history
The outer tag is not removed anymore - instead youll get a span. You should switch to the new isInline mode
  • Loading branch information
mhsdesign committed Jan 14, 2024
1 parent 2c72e4c commit 92e8e04
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 52 deletions.
Expand Up @@ -4,20 +4,5 @@ export const cleanupContentBeforeCommit = content => {
if (content.match(/^<([a-z][a-z0-9]*)\b[^>]*>&nbsp;<\/\1>$/)) {
return '';
}

// We remove opening and closing span tags that are produced by the `DisabledAutoparagraphMode` plugin
if (content.startsWith('<span>') && content.endsWith('</span>')) {
const contentWithoutOuterSpan = content
.replace(/^<span>/, '')
.replace(/<\/span>$/, '');

if (contentWithoutOuterSpan.includes('<span>')) {
// In case there is still a span tag, we can be sure that the previously trimmed ones were belonging together,
// as it could be the case that multiple root paragraph/span elements were inserted into the ckeditor
// (which is currently not prevented if the html is modified from outside), so we will preserve the output.
return content;
}
return contentWithoutOuterSpan;
}
return content;
};
Expand Up @@ -8,27 +8,3 @@ test('remove empty nbsp', () => {
assertCleanedUpContent('<p>&nbsp;</p>', '');
assertCleanedUpContent('<span>&nbsp;</span>', '');
})

describe('ckeditor DisabledAutoparagraphMode hack, cleanup outer spans', () => {
test('noop', () => {
assertCleanedUpContent('<p></p>', '<p></p>');

assertCleanedUpContent('', '');

assertCleanedUpContent('<span><span>foo</span></span>', '<span><span>foo</span></span>');
})

test('cleanup single root <span>', () => {
assertCleanedUpContent('<span></span>', '');
assertCleanedUpContent('<span>foo</span>', 'foo');
})

test('cleanup multiple root <span>', () => {
assertCleanedUpContent('<span>foo</span><span>bar</span>', '<span>foo</span><span>bar</span>');
})

test('cleanup <span> root after other root', () => {
// in the case you had multiple paragraphs and a headline and switched to autoparagraph: false
assertCleanedUpContent('<h1>foo</h1><span>bar</span>', '<h1>foo</h1><span>bar</span>');
})
})
14 changes: 1 addition & 13 deletions packages/neos-ui-ckeditor5-bindings/src/manifest.config.js
Expand Up @@ -33,18 +33,6 @@ const addPlugin = (Plugin, isEnabled) => (ckEditorConfiguration, options) => {
return ckEditorConfiguration;
};

// If the editable is a span or a heading, we automatically disable paragraphs and enable the soft break mode
// Also possible to force this behavior with `autoparagraph: false`
const disableAutoparagraph = (editorOptions, {propertyDomNode}) =>
editorOptions?.autoparagraph === false ||
propertyDomNode.tagName === 'SPAN' ||
propertyDomNode.tagName === 'H1' ||
propertyDomNode.tagName === 'H2' ||
propertyDomNode.tagName === 'H3' ||
propertyDomNode.tagName === 'H4' ||
propertyDomNode.tagName === 'H5' ||
propertyDomNode.tagName === 'H6';

//
// Create richtext editing toolbar registry
//
Expand Down Expand Up @@ -103,7 +91,7 @@ export default ckEditorRegistry => {
config.set('essentials', addPlugin(Essentials));
config.set('paragraph', addPlugin(Paragraph));
// @deprecated
config.set('disabledAutoparagraphMode', addPlugin(DisabledAutoparagraphMode, disableAutoparagraph));
config.set('disabledAutoparagraphMode', addPlugin(DisabledAutoparagraphMode, (editorOptions) => editorOptions?.autoparagraph === false));
config.set('sub', addPlugin(Sub, $get('formatting.sub')));
config.set('sup', addPlugin(Sup, $get('formatting.sup')));
config.set('bold', addPlugin(Bold, $get('formatting.strong')));
Expand Down

0 comments on commit 92e8e04

Please sign in to comment.