|
|
@@ -10,7 +10,6 @@
|
|
|
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
|
|
import PageBreakCommand from './pagebreakcommand';
|
|
|
import { toWidget } from '@ckeditor/ckeditor5-widget/src/utils';
|
|
|
-import first from '@ckeditor/ckeditor5-utils/src/first';
|
|
|
|
|
|
import '../theme/pagebreak.css';
|
|
|
|
|
|
@@ -85,27 +84,41 @@ export default class PageBreakEditing extends Plugin {
|
|
|
conversion.for( 'upcast' )
|
|
|
.elementToElement( {
|
|
|
view: element => {
|
|
|
- // The "page break" div must have specified value for the 'page-break-after' definition and single child only.
|
|
|
- if ( !element.is( 'div' ) || element.getStyle( 'page-break-after' ) != 'always' || element.childCount != 1 ) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ // For upcast conversion it's enough if we check for element style and verify if it's empty
|
|
|
+ // or contains only hidden span element.
|
|
|
|
|
|
- const viewSpan = first( element.getChildren() );
|
|
|
+ const hasPageBreakBefore = element.getStyle( 'page-break-before' ) == 'always';
|
|
|
+ const hasPageBreakAfter = element.getStyle( 'page-break-after' ) == 'always';
|
|
|
|
|
|
- // The child must be the "span" element that is not displayed and has a space inside.
|
|
|
- if ( !viewSpan.is( 'span' ) || viewSpan.getStyle( 'display' ) != 'none' || viewSpan.childCount != 1 ) {
|
|
|
+ if ( !hasPageBreakBefore && !hasPageBreakAfter ) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const text = first( viewSpan.getChildren() );
|
|
|
+ // The "page break" div accepts only single child.
|
|
|
+ if ( element.childCount == 1 ) {
|
|
|
+ const viewSpan = element.getChild( 0 );
|
|
|
+
|
|
|
+ // The child must be the "span" element that is not displayed and has a space inside.
|
|
|
+ if ( !viewSpan.is( 'span' ) || viewSpan.getStyle( 'display' ) != 'none' || viewSpan.childCount != 1 ) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if ( !text.is( 'text' ) || text.data !== ' ' ) {
|
|
|
+ const text = viewSpan.getChild( 0 );
|
|
|
+
|
|
|
+ if ( !text.is( 'text' ) || text.data !== ' ' ) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ } else if ( element.childCount > 1 ) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
return { name: true };
|
|
|
},
|
|
|
- model: 'pageBreak'
|
|
|
+ model: 'pageBreak',
|
|
|
+
|
|
|
+ // This conversion must be checked before <br> conversion because some editors use
|
|
|
+ // <br style="page-break-before:always"> as a page break marker.
|
|
|
+ converterPriority: 'high'
|
|
|
} );
|
|
|
|
|
|
editor.commands.add( 'pageBreak', new PageBreakCommand( editor ) );
|