|
|
@@ -40,7 +40,6 @@ export default class Paragraph extends Plugin {
|
|
|
init() {
|
|
|
const editor = this.editor;
|
|
|
const model = editor.model;
|
|
|
- const data = editor.data;
|
|
|
|
|
|
editor.commands.add( 'paragraph', new ParagraphCommand( editor ) );
|
|
|
editor.commands.add( 'insertParagraph', new InsertParagraphCommand( editor ) );
|
|
|
@@ -50,10 +49,7 @@ export default class Paragraph extends Plugin {
|
|
|
|
|
|
editor.conversion.elementToElement( { model: 'paragraph', view: 'p' } );
|
|
|
|
|
|
- // Content autoparagraphing. --------------------------------------------------
|
|
|
-
|
|
|
- // Handles element which has not been converted by any plugin and checks if it would be converted if
|
|
|
- // we wrap it in a paragraph or change it to a paragraph.
|
|
|
+ // Conversion for paragraph-like elements which has not been converted by any plugin.
|
|
|
editor.conversion.for( 'upcast' ).elementToElement( {
|
|
|
model: ( viewElement, modelWriter ) => {
|
|
|
if ( !Paragraph.paragraphLikeElements.has( viewElement.name ) ) {
|
|
|
@@ -71,53 +67,6 @@ export default class Paragraph extends Plugin {
|
|
|
converterPriority: 'low'
|
|
|
} );
|
|
|
|
|
|
- const conversionApi = data.upcastDispatcher.conversionApi;
|
|
|
- const originalSplitToAllowedParent = conversionApi.splitToAllowedParent;
|
|
|
-
|
|
|
- conversionApi.splitToAllowedParent = ( node, modelCursor ) => {
|
|
|
- const result = originalSplitToAllowedParent( node, modelCursor );
|
|
|
-
|
|
|
- if ( result ) {
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- if ( !isParagraphable( node, modelCursor, conversionApi.schema ) ) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- const paragraph = conversionApi.writer.createElement( 'paragraph' );
|
|
|
-
|
|
|
- conversionApi.writer.insert( paragraph, modelCursor );
|
|
|
-
|
|
|
- return {
|
|
|
- position: conversionApi.writer.createPositionAt( paragraph, 0 )
|
|
|
- };
|
|
|
- };
|
|
|
-
|
|
|
- data.upcastDispatcher.on( 'element', ( evt, data, conversionApi ) => {
|
|
|
- // Do not try auto-paragraphing if the element was already converted.
|
|
|
- if ( !conversionApi.consumable.test( data.viewItem, { name: data.viewItem.name } ) ) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // If the element is not paragraph-like try wrapping it in a paragraph.
|
|
|
- if ( isParagraphable( data.viewItem, data.modelCursor, conversionApi.schema ) ) {
|
|
|
- Object.assign( data, wrapInParagraph( data.viewItem, data.modelCursor, conversionApi ) );
|
|
|
- }
|
|
|
- }, { priority: 'low' } );
|
|
|
-
|
|
|
- // Handles not converted text nodes and checks if would be converted if we wraps then by a paragraph.
|
|
|
- data.upcastDispatcher.on( 'text', ( evt, data, conversionApi ) => {
|
|
|
- // When node is already converted then do nothing.
|
|
|
- if ( data.modelRange ) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if ( isParagraphable( data.viewItem, data.modelCursor, conversionApi.schema ) ) {
|
|
|
- Object.assign( data, wrapInParagraph( data.viewItem, data.modelCursor, conversionApi ) );
|
|
|
- }
|
|
|
- }, { priority: 'lowest' } );
|
|
|
-
|
|
|
// Empty roots autoparagraphing. -----------------------------------------------
|
|
|
|
|
|
// Post-fixer which takes care of adding empty paragraph elements to empty roots.
|
|
|
@@ -198,28 +147,6 @@ Paragraph.paragraphLikeElements = new Set( [
|
|
|
'h6',
|
|
|
'li',
|
|
|
'p',
|
|
|
- 'td'
|
|
|
+ 'td',
|
|
|
+ 'th'
|
|
|
] );
|
|
|
-
|
|
|
-function wrapInParagraph( input, position, conversionApi ) {
|
|
|
- const paragraph = conversionApi.writer.createElement( 'paragraph' );
|
|
|
-
|
|
|
- conversionApi.writer.insert( paragraph, position );
|
|
|
- return conversionApi.convertItem( input, conversionApi.writer.createPositionAt( paragraph, 0 ) );
|
|
|
-}
|
|
|
-
|
|
|
-function isParagraphable( node, position, schema ) {
|
|
|
- const context = schema.createContext( position );
|
|
|
-
|
|
|
- // When paragraph is allowed in this context...
|
|
|
- if ( !schema.checkChild( context, 'paragraph' ) ) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // And a node would be allowed in this paragraph...
|
|
|
- if ( !schema.checkChild( context.push( 'paragraph' ), node ) ) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
-}
|