-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 #7787 from ckeditor/i/6698
Fix (engine): Upcast conversion will now try to wrap text and inline elements in paragraph if such content is converted in a place where is not allowed but a paragraph is allowed. Closes #7753. Closes #6698. Internal (paragraph): Auto-paragraphing content conversion moved to the engine package. Tests (table): Added tests for upcasting inline elements inside a table cell.
- Loading branch information
Showing
13 changed files
with
272 additions
and
120 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
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
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
77 changes: 77 additions & 0 deletions
77
packages/ckeditor5-engine/src/model/utils/autoparagraphing.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,77 @@ | ||
/** | ||
* @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
/** | ||
* @module engine/model/utils/autoparagraphing | ||
*/ | ||
|
||
/** | ||
* Fixes all empty roots. | ||
* | ||
* @protected | ||
* @param {module:engine/model/writer~Writer} writer The model writer. | ||
* @returns {Boolean} `true` if any change has been applied, `false` otherwise. | ||
*/ | ||
export function autoParagraphEmptyRoots( writer ) { | ||
const { schema, document } = writer.model; | ||
|
||
for ( const rootName of document.getRootNames() ) { | ||
const root = document.getRoot( rootName ); | ||
|
||
if ( root.isEmpty && !schema.checkChild( root, '$text' ) ) { | ||
// If paragraph element is allowed in the root, create paragraph element. | ||
if ( schema.checkChild( root, 'paragraph' ) ) { | ||
writer.insertElement( 'paragraph', root ); | ||
|
||
// Other roots will get fixed in the next post-fixer round. Those will be triggered | ||
// in the same batch no matter if this method was triggered by the post-fixing or not | ||
// (the above insertElement call will trigger the post-fixers). | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Checks if the given node wrapped with a paragraph would be accepted by the schema in the given position. | ||
* | ||
* @protected | ||
* @param {module:engine/model/position~Position} position The position at which to check. | ||
* @param {module:engine/model/node~Node|String} nodeOrType The child node or child type to check. | ||
* @param {module:engine/model/schema~Schema} schema A schema instance used for element validation. | ||
*/ | ||
export function isParagraphable( position, nodeOrType, 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' ), nodeOrType ) ) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Inserts a new paragraph at the given position and returns a position inside that paragraph. | ||
* | ||
* @protected | ||
* @param {module:engine/model/position~Position} position The position where a paragraph should be inserted. | ||
* @param {module:engine/model/writer~Writer} writer The model writer. | ||
* @returns {module:engine/model/position~Position} Position inside the created paragraph. | ||
*/ | ||
export function wrapInParagraph( position, writer ) { | ||
const paragraph = writer.createElement( 'paragraph' ); | ||
|
||
writer.insert( paragraph, position ); | ||
|
||
return writer.createPositionAt( paragraph, 0 ); | ||
} |
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
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
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
Oops, something went wrong.