markdown.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. 'blockQuote',
  32. 'undo',
  33. 'redo'
  34. ],
  35. image: {
  36. toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageTextAlternative' ]
  37. },
  38. codeBlock: {
  39. languages: [
  40. { language: 'css', label: 'CSS' },
  41. { language: 'html', label: 'HTML' }
  42. ]
  43. },
  44. cloudServices: CS_CONFIG
  45. } )
  46. .then( editor => {
  47. window.editor = editor;
  48. const outputElement = document.querySelector( '#snippet-markdown-output' );
  49. editor.model.document.on( 'change', () => {
  50. outputElement.innerText = editor.getData();
  51. } );
  52. // Set the initial data with delay so hightlight.js doesn't catch them.
  53. setTimeout( () => {
  54. outputElement.innerText = editor.getData();
  55. }, 500 );
  56. } )
  57. .catch( err => {
  58. console.error( err.stack );
  59. } );