浏览代码

Style improvements.

Oskar Wróbel 6 年之前
父节点
当前提交
c44b3895aa
共有 1 个文件被更改,包括 12 次插入1 次删除
  1. 12 1
      packages/ckeditor5-code-block/src/codeblockediting.js

+ 12 - 1
packages/ckeditor5-code-block/src/codeblockediting.js

@@ -125,7 +125,7 @@ function dataViewModelPreInsertion( dataController ) {
 		const modelItem = writer.createElement( 'codeBlock' );
 
 		const stringifiedElement = dataController.processor.toData( data.viewItem );
-		const textData = new RegExp( /^<pre>(.*)<\/pre>$/, 's' ).exec( stringifiedElement )[ 1 ];
+		const textData = extractDataFromPreElement( stringifiedElement );
 		const textLines = textData.split( '\n' ).map( data => writer.createText( data ) );
 		const lastLine = textLines[ textLines.length - 1 ];
 
@@ -143,3 +143,14 @@ function dataViewModelPreInsertion( dataController ) {
 		data.modelRange = writer.createRange( data.modelCursor );
 	};
 }
+
+// Returns content of `<pre></pre>` with unescaped html inside.
+//
+// @param {String} stringifiedElement
+function extractDataFromPreElement( stringifiedElement ) {
+	const data = new RegExp( /^<pre>(.*)<\/pre>$/, 's' ).exec( stringifiedElement )[ 1 ];
+
+	return data
+		.replace( /&lt;/g, '<' )
+		.replace( /&gt;/g, '>' );
+}