8
0

codeblock-integration.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* globals document */
  6. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  7. import Enter from '@ckeditor/ckeditor5-enter/src/enter';
  8. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  9. import GFMDataProcessor from '@ckeditor/ckeditor5-markdown-gfm/src/gfmdataprocessor';
  10. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  11. import CodeBlockEditing from '../src/codeblockediting';
  12. // A simple plugin that enables the GFM data processor.
  13. class CodeBlockIntegration extends Plugin {
  14. constructor( editor ) {
  15. super( editor );
  16. editor.data.processor = new GFMDataProcessor( editor.data.viewDocument );
  17. }
  18. }
  19. function getEditor( initialData = '' ) {
  20. return ClassicTestEditor
  21. .create( initialData, {
  22. plugins: [ CodeBlockIntegration, CodeBlockEditing, Enter, Paragraph ]
  23. } );
  24. }
  25. describe( 'CodeBlock - integration', () => {
  26. let element;
  27. beforeEach( () => {
  28. element = document.createElement( 'div' );
  29. document.body.appendChild( element );
  30. } );
  31. afterEach( () => {
  32. element.remove();
  33. } );
  34. describe( 'with Markdown GFM', () => {
  35. it( 'should be loaded and returned from the editor', async () => {
  36. const markdown =
  37. '```\n' +
  38. 'test()\n' +
  39. '```';
  40. const editor = await getEditor( markdown );
  41. expect( editor.getData() ).to.equal( markdown );
  42. await editor.destroy();
  43. } );
  44. } );
  45. } );