markdown.js 1.6 KB

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