paragraph.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Feature from '../core/feature.js';
  6. import buildModelConverter from '../engine/conversion/buildmodelconverter.js';
  7. import buildViewConverter from '../engine/conversion/buildviewconverter.js';
  8. /**
  9. * The paragraph feature for the editor.
  10. * Introduces the `<paragraph>` element in the model which renders as a `<p>` element in the DOM and data.
  11. *
  12. * @memberOf paragraph
  13. * @extends core.Feature
  14. */
  15. export default class Paragraph extends Feature {
  16. /**
  17. * @inheritDoc
  18. */
  19. init() {
  20. const editor = this.editor;
  21. const data = editor.data;
  22. const editing = editor.editing;
  23. // Schema.
  24. editor.document.schema.registerItem( 'paragraph', '$block' );
  25. // Build converter from model to view for data and editing pipelines.
  26. buildModelConverter().for( data.modelToView, editing.modelToView )
  27. .fromElement( 'paragraph' )
  28. .toElement( 'p' );
  29. // Build converter from view to model for data pipeline.
  30. buildViewConverter().for( data.viewToModel )
  31. .fromElement( 'p' )
  32. .toElement( 'paragraph' );
  33. }
  34. }