Sfoglia il codice sorgente

Use 'cssRules' instead of 'rules' when processing styles.

Krzysztof Krztoń 7 anni fa
parent
commit
05cbcab301

+ 1 - 1
packages/ckeditor5-paste-from-office/src/filters/utils.js

@@ -76,7 +76,7 @@ function extractStyles( htmlDocument ) {
 	const styleTags = htmlDocument.getElementsByTagName( 'style' );
 
 	for ( const style of styleTags ) {
-		if ( style.sheet && style.sheet.rules && style.sheet.rules.length ) {
+		if ( style.sheet && style.sheet.cssRules && style.sheet.cssRules.length ) {
 			styles.push( style.sheet );
 			stylesString.push( style.innerHTML );
 		}

+ 5 - 5
packages/ckeditor5-paste-from-office/tests/filters/utils.js

@@ -12,21 +12,21 @@ import { parseHtml } from '../../src/filters/utils';
 describe( 'Filters – utils', () => {
 	describe( 'parseHtml', () => {
 		it( 'correctly parses HTML with body and one style tag', () => {
-			const html = '<head><style>p { color: red; } a { border: none; }</style></head><body><p>Foo Bar</p></body>';
+			const html = '<head><style>p { color: red; } a { font-size: 12px; }</style></head><body><p>Foo Bar</p></body>';
 			const { body, bodyString, styles, stylesString } = parseHtml( html );
 
 			expect( body ).to.instanceof( DocumentFragment );
-			expect( body.childCount ).to.equal( 1 );
+			expect( body.childCount ).to.equal( 1, 'body.childCount' );
 
 			expect( bodyString ).to.equal( '<p>Foo Bar</p>' );
 
-			expect( styles.length ).to.equal( 1 );
+			expect( styles.length ).to.equal( 1, 'styles.length' );
 			expect( styles[ 0 ] ).to.instanceof( CSSStyleSheet );
 			expect( styles[ 0 ].cssRules.length ).to.equal( 2 );
 			expect( styles[ 0 ].cssRules[ 0 ].style.color ).to.equal( 'red' );
-			expect( styles[ 0 ].cssRules[ 1 ].style.border ).to.equal( 'none' );
+			expect( styles[ 0 ].cssRules[ 1 ].style[ 'font-size' ] ).to.equal( '12px' );
 
-			expect( stylesString ).to.equal( 'p { color: red; } a { border: none; }' );
+			expect( stylesString ).to.equal( 'p { color: red; } a { font-size: 12px; }' );
 		} );
 
 		it( 'correctly parses HTML with body contents only', () => {