Преглед изворни кода

Paragraph feature initial implementation.

Szymon Kupś пре 9 година
родитељ
комит
2df294069c

+ 33 - 0
packages/ckeditor5-paragraph/src/paragraph.js

@@ -0,0 +1,33 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+import Feature from '../feature.js';
+import BuildModelConverterFor from '../engine/treecontroller/model-converter-builder.js';
+import BuildViewConverterFor from '../engine/treecontroller/view-converter-builder.js';
+
+export default class Paragraph extends Feature {
+	init() {
+		const editor = this.editor;
+		const document = editor.document;
+		const schema = document.schema;
+		const data = editor.data;
+		const editing = editor.editing;
+
+		// Schema.
+		schema.registerItem( 'paragraph', '$block' );
+
+		// Build converter from model to view for data and editing pipelines.
+		BuildModelConverterFor( data.toView, editing.toView )
+			.fromElement( 'paragraph' )
+			.toElement( 'p' );
+
+		// Build converter from view to model for data and editing pipelines.
+		BuildViewConverterFor( data.toModel, editing.toModel )
+			.fromElement( 'p' )
+			.toElement( 'paragraph' );
+	}
+}

+ 27 - 0
packages/ckeditor5-paragraph/tests/paragraph.js

@@ -0,0 +1,27 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+import Paragraph from '/ckeditor5/paragraph/paragraph.js';
+import Editor from '/ckeditor5/editor.js';
+import StandardCreator from '/ckeditor5/creator/standardcreator.js';
+
+describe( 'Paragraph feature', () => {
+	let editor;
+
+	beforeEach( () => {
+		editor = new Editor( null, {
+			creator: StandardCreator,
+			features: [ Paragraph ]
+		} );
+
+		return editor.init();
+	} );
+
+	it( 'should be loaded', () => {
+		expect( editor.plugins.get( Paragraph ) ).to.be.instanceOf( Paragraph );
+	} );
+} );