markdown.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 console, window, document, setTimeout */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  8. import EasyImage from '@ckeditor/ckeditor5-easy-image/src/easyimage';
  9. import { CS_CONFIG } from '@ckeditor/ckeditor5-cloud-services/tests/_utils/cloud-services-config';
  10. import Markdown from '@ckeditor/ckeditor5-markdown-gfm/src/markdown';
  11. ClassicEditor
  12. .create( document.querySelector( '#snippet-markdown' ), {
  13. plugins: [ ArticlePluginSet, EasyImage, Markdown ],
  14. toolbar: [
  15. 'heading',
  16. '|',
  17. 'bold',
  18. 'italic',
  19. 'link',
  20. 'bulletedList',
  21. 'numberedList',
  22. '|',
  23. 'outdent',
  24. 'indent',
  25. '|',
  26. 'blockQuote',
  27. 'undo',
  28. 'redo'
  29. ],
  30. image: {
  31. toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageTextAlternative' ]
  32. },
  33. cloudServices: CS_CONFIG
  34. } )
  35. .then( editor => {
  36. window.editor = editor;
  37. const outputElement = document.querySelector( '#snippet-markdown-output' );
  38. editor.model.document.on( 'change', () => {
  39. outputElement.innerText = editor.getData();
  40. } );
  41. // Set the initial data with delay so hightlight.js doesn't catch them.
  42. setTimeout( () => {
  43. outputElement.innerText = editor.getData();
  44. }, 500 );
  45. } )
  46. .catch( err => {
  47. console.error( err.stack );
  48. } );