-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3558 from neos/bugfix/3557-placeholder-plugin-aut…
…oparagraph-false BUGFIX: 3557 placeholder plugin with autoparagraph false
- Loading branch information
Showing
11 changed files
with
89 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 2 additions & 21 deletions
23
packages/neos-ui-ckeditor5-bindings/src/cleanupContentBeforeCommit.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,9 @@ | ||
// We remove opening and closing span tags that are produced by the inlineMode plugin | ||
|
||
// TODO: remove when this is fixed: https://github.com/ckeditor/ckeditor5/issues/401 | ||
/** @param {String} content */ | ||
export const cleanupContentBeforeCommit = content => { | ||
// TODO: remove when this is fixed: https://github.com/ckeditor/ckeditor5/issues/401 | ||
if (content.match(/^<([a-z][a-z0-9]*)\b[^>]*> <\/\1>$/)) { | ||
return ''; | ||
} | ||
|
||
if (content.includes('<neos-inline-wrapper>')) { | ||
let contentWithoutOuterInlineWrapper = content; | ||
|
||
if (content.startsWith('<neos-inline-wrapper>') && content.endsWith('</neos-inline-wrapper>')) { | ||
contentWithoutOuterInlineWrapper = content | ||
.replace(/^<neos-inline-wrapper>/, '') | ||
.replace(/<\/neos-inline-wrapper>$/, ''); | ||
} | ||
|
||
if (contentWithoutOuterInlineWrapper.includes('<neos-inline-wrapper>')) { | ||
// in the case, multiple root paragraph elements were inserted into the ckeditor (wich is currently not prevented if the html is modified from outside) | ||
// we have multiple root elements of type <neos-inline-wrapper>. We will convert all of them into spans. | ||
return content | ||
.replace(/<neos-inline-wrapper>/g, '<span>') | ||
.replace(/<\/neos-inline-wrapper>/g, '</span>'); | ||
} | ||
return contentWithoutOuterInlineWrapper; | ||
} | ||
return content; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/neos-ui-ckeditor5-bindings/src/placeholder.vanilla-css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.ck.ck-placeholder:before, .ck .ck-placeholder:before { | ||
content: attr(data-placeholder); | ||
|
||
/* See ckeditor/ckeditor5#469. */ | ||
pointer-events: none; | ||
|
||
color: #999; | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/neos-ui-ckeditor5-bindings/src/plugins/cleanupNeosInlineWrapper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* We remove opening and closing span tags that are produced by the inlineMode plugin | ||
* | ||
* @private only exported for testing | ||
* @param {String} content | ||
*/ | ||
export const cleanupNeosInlineWrapper = content => { | ||
if (content.includes('<neos-inline-wrapper>')) { | ||
let contentWithoutOuterInlineWrapper = content; | ||
|
||
if (content.startsWith('<neos-inline-wrapper>') && content.endsWith('</neos-inline-wrapper>')) { | ||
contentWithoutOuterInlineWrapper = content | ||
.replace(/^<neos-inline-wrapper>/, '') | ||
.replace(/<\/neos-inline-wrapper>$/, ''); | ||
} | ||
|
||
if (contentWithoutOuterInlineWrapper.includes('<neos-inline-wrapper>')) { | ||
// in the case, multiple root paragraph elements were inserted into the ckeditor (wich is currently not prevented if the html is modified from outside) | ||
// we have multiple root elements of type <neos-inline-wrapper>. We will convert all of them into spans. | ||
return content | ||
.replace(/<neos-inline-wrapper>/g, '<span>') | ||
.replace(/<\/neos-inline-wrapper>/g, '</span>'); | ||
} | ||
return contentWithoutOuterInlineWrapper; | ||
} | ||
return content; | ||
}; |
31 changes: 31 additions & 0 deletions
31
packages/neos-ui-ckeditor5-bindings/src/plugins/cleanupNeosInlineWrapper.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {cleanupNeosInlineWrapper} from './cleanupNeosInlineWrapper'; | ||
|
||
const assertCleanedUpContent = (input, expected) => { | ||
expect(cleanupNeosInlineWrapper(input)).toBe(expected); | ||
} | ||
|
||
describe('ckeditor inline mode hack, cleanup <neos-inline-wrapper>', () => { | ||
test('noop', () => { | ||
assertCleanedUpContent('<p></p>', '<p></p>'); | ||
|
||
assertCleanedUpContent('', ''); | ||
}) | ||
|
||
test('cleanup single <neos-inline-wrapper>', () => { | ||
assertCleanedUpContent('<neos-inline-wrapper></neos-inline-wrapper>', ''); | ||
assertCleanedUpContent('<neos-inline-wrapper>foo</neos-inline-wrapper>', 'foo'); | ||
|
||
assertCleanedUpContent('<neos-inline-wrapper><span>foo</span></neos-inline-wrapper>', '<span>foo</span>'); | ||
}) | ||
|
||
test('cleanup multiple <neos-inline-wrapper>', () => { | ||
assertCleanedUpContent('<neos-inline-wrapper>foo</neos-inline-wrapper><neos-inline-wrapper>bar</neos-inline-wrapper>', '<span>foo</span><span>bar</span>'); | ||
|
||
assertCleanedUpContent('<neos-inline-wrapper>foo</neos-inline-wrapper><neos-inline-wrapper>bar</neos-inline-wrapper>', '<span>foo</span><span>bar</span>'); | ||
}) | ||
|
||
test('cleanup <neos-inline-wrapper> after other root', () => { | ||
// in the case you had multiple paragraphs and a headline and switched to autoparagrahp: false | ||
assertCleanedUpContent('<h1>foo</h1><neos-inline-wrapper>bar</neos-inline-wrapper>', '<h1>foo</h1><span>bar</span>'); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 0 additions & 75 deletions
75
packages/neos-ui-ckeditor5-bindings/src/plugins/neosPlaceholder.js
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
packages/neos-ui-ckeditor5-bindings/src/plugins/neosPlaceholder.vanilla-css
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters