markdown.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  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 GFMDataProcessor from '@ckeditor/ckeditor5-markdown-gfm/src/gfmdataprocessor';
  9. function Markdown( editor ) {
  10. editor.data.processor = new GFMDataProcessor();
  11. }
  12. ClassicEditor
  13. .create( document.querySelector( '#snippet-markdown' ), {
  14. plugins: [ ArticlePluginSet, Markdown ],
  15. toolbar: [ 'headings', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ],
  16. image: {
  17. toolbar: [ 'imageStyleFull', 'imageStyleSide', '|', 'imageTextAlternative' ]
  18. }
  19. } )
  20. .then( editor => {
  21. window.editor = editor;
  22. const outputElement = document.querySelector( '#snippet-markdown-output' );
  23. editor.model.document.on( 'changesDone', () => {
  24. outputElement.innerText = editor.getData();
  25. } );
  26. // Set the initial data with delay so hightlight.js doesn't catch them.
  27. setTimeout( () => {
  28. outputElement.innerText = editor.getData();
  29. }, 500 );
  30. } )
  31. .catch( err => {
  32. console.error( err.stack );
  33. } );