`.
+ // Read only text nodes.
+ const textData = [ ...editingView.createRangeIn( viewChild ) ]
+ .filter( current => current.type === 'text' )
+ .map( ( { item } ) => item.data )
+ .join( '' );
const fragment = rawSnippetTextToModelDocumentFragment( writer, textData );
writer.append( fragment, codeBlock );
@@ -234,14 +238,3 @@ export function dataViewToModelCodeBlockInsertion( dataController, languageDefs
}
};
}
-
-// Returns content of `` with unescaped html inside.
-//
-// @param {String} stringifiedElement
-function extractDataFromCodeElement( stringifiedElement ) {
- const data = new RegExp( /^]*>([\S\s]*)<\/code>$/ ).exec( stringifiedElement )[ 1 ];
-
- return data
- .replace( /</g, '<' )
- .replace( />/g, '>' );
-}
diff --git a/packages/ckeditor5-code-block/tests/codeblockediting.js b/packages/ckeditor5-code-block/tests/codeblockediting.js
index 8cd86abd9eb..738f7d93898 100644
--- a/packages/ckeditor5-code-block/tests/codeblockediting.js
+++ b/packages/ckeditor5-code-block/tests/codeblockediting.js
@@ -889,29 +889,39 @@ describe( 'CodeBlockEditing', () => {
);
} );
+ // Undesired by expected. There is an issue with identifying the correct filler type.
+ // is inline, so dom-to-view converter expects an inline filler.
+ it( 'should convert pre > code with only inside to a codeBlock with ', () => {
+ editor.setData( '
' );
+
+ expect( getModelData( model ) ).to.equal(
+ '[]\u00a0 '
+ );
+ } );
+
it( 'should convert pre > code with HTML inside', () => {
editor.setData( 'Foo
\nBar
' );
expect( getModelData( model ) ).to.equal(
'[]' +
- 'Foo
' +
+ 'Foo' +
' ' +
- 'Bar
' +
+ 'Bar' +
' '
);
} );
- it( 'should convert pre > code tag with HTML and nested pre > code tag', () => {
- editor.setData( 'Foo
Bar
Biz
' );
+ it( 'should convert pre > code tag with HTML and nested pre > code tag and use only the text content of invalid HTML tags', () => {
+ editor.setData( 'Foo
Bar
Biz
' );
expect( getModelData( model ) ).to.equal(
- '[]Foo
Bar
Biz
' );
+ '[]FooBarBiz ' );
} );
it( 'should convert pre > code tag with escaped html content', () => {
- editor.setData( '<div><p>Foo</p></div>
' );
+ editor.setData( '<div><p>Foo's&"bar"</p></div>
' );
- expect( getModelData( model ) ).to.equal( '[]Foo
' );
+ expect( getModelData( model ) ).to.equal( '[]Foo\'s&"bar"
' );
} );
it( 'should be overridable', () => {