markdown.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 EasyImage from '@ckeditor/ckeditor5-easy-image/src/easyimage';
  9. import { TOKEN_URL } from '@ckeditor/ckeditor5-cloudservices/tests/_utils/cloudservices-config';
  10. import GFMDataProcessor from '@ckeditor/ckeditor5-markdown-gfm/src/gfmdataprocessor';
  11. function Markdown( editor ) {
  12. editor.data.processor = new GFMDataProcessor();
  13. }
  14. ClassicEditor
  15. .create( document.querySelector( '#snippet-markdown' ), {
  16. plugins: [ ArticlePluginSet, EasyImage, Markdown ],
  17. toolbar: [ 'headings', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ],
  18. image: {
  19. toolbar: [ 'imageStyleFull', 'imageStyleSide', '|', 'imageTextAlternative' ]
  20. },
  21. cloudServices: {
  22. tokenUrl: TOKEN_URL
  23. }
  24. } )
  25. .then( editor => {
  26. window.editor = editor;
  27. const outputElement = document.querySelector( '#snippet-markdown-output' );
  28. editor.model.document.on( 'changesDone', () => {
  29. outputElement.innerText = editor.getData();
  30. } );
  31. // Set the initial data with delay so hightlight.js doesn't catch them.
  32. setTimeout( () => {
  33. outputElement.innerText = editor.getData();
  34. }, 500 );
  35. } )
  36. .catch( err => {
  37. console.error( err.stack );
  38. } );