markdown.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 CodeBlock from '@ckeditor/ckeditor5-code-block/src/codeblock';
  10. import Code from '@ckeditor/ckeditor5-basic-styles/src/code';
  11. import { CS_CONFIG } from '@ckeditor/ckeditor5-cloud-services/tests/_utils/cloud-services-config';
  12. import Markdown from '@ckeditor/ckeditor5-markdown-gfm/src/markdown';
  13. ClassicEditor
  14. .create( document.querySelector( '#snippet-markdown' ), {
  15. plugins: [ ArticlePluginSet, EasyImage, Markdown, Code, CodeBlock ],
  16. toolbar: [
  17. 'heading',
  18. '|',
  19. 'bold',
  20. 'italic',
  21. 'link',
  22. 'bulletedList',
  23. 'numberedList',
  24. '|',
  25. 'code',
  26. 'codeBlock',
  27. '|',
  28. 'outdent',
  29. 'indent',
  30. '|',
  31. 'imageUpload',
  32. 'blockQuote',
  33. '|',
  34. 'undo',
  35. 'redo'
  36. ],
  37. image: {
  38. toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageTextAlternative' ]
  39. },
  40. codeBlock: {
  41. languages: [
  42. { language: 'css', label: 'CSS' },
  43. { language: 'html', label: 'HTML' }
  44. ]
  45. },
  46. cloudServices: CS_CONFIG
  47. } )
  48. .then( editor => {
  49. window.editor = editor;
  50. const outputElement = document.querySelector( '#snippet-markdown-output' );
  51. editor.model.document.on( 'change', () => {
  52. outputElement.innerText = editor.getData();
  53. } );
  54. // Set the initial data with delay so hightlight.js doesn't catch them.
  55. setTimeout( () => {
  56. outputElement.innerText = editor.getData();
  57. }, 500 );
  58. } )
  59. .catch( err => {
  60. console.error( err.stack );
  61. } );