markdown.js 2.0 KB

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