markdown.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 Markdown from '@ckeditor/ckeditor5-markdown-gfm/src/markdown';
  9. import Strikethrough from '@ckeditor/ckeditor5-basic-styles/src/strikethrough';
  10. import TodoList from '@ckeditor/ckeditor5-list/src/todolist';
  11. import TableProperties from '@ckeditor/ckeditor5-table/src/tableproperties';
  12. import TableCellProperties from '@ckeditor/ckeditor5-table/src/tablecellproperties';
  13. import CodeBlock from '@ckeditor/ckeditor5-code-block/src/codeblock';
  14. import Code from '@ckeditor/ckeditor5-basic-styles/src/code';
  15. ClassicEditor
  16. .create( document.querySelector( '#editor' ), {
  17. plugins: [ Markdown, ArticlePluginSet, Code, CodeBlock, Strikethrough, TodoList, TableProperties, TableCellProperties ],
  18. toolbar: [
  19. 'heading',
  20. '|',
  21. 'bold',
  22. 'italic',
  23. 'strikethrough',
  24. 'underline',
  25. 'link',
  26. '|',
  27. 'code',
  28. 'codeBlock',
  29. '|',
  30. 'todoList',
  31. 'bulletedList',
  32. 'numberedList',
  33. '|',
  34. 'outdent',
  35. 'indent',
  36. '|',
  37. 'blockQuote',
  38. 'insertTable',
  39. '|',
  40. 'undo',
  41. 'redo'
  42. ],
  43. image: {
  44. toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageTextAlternative' ]
  45. },
  46. table: {
  47. contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells', 'tableProperties', 'tableCellProperties' ],
  48. tableToolbar: [ 'bold', 'italic' ]
  49. }
  50. } )
  51. .then( editor => {
  52. window.editor = editor;
  53. const outputElement = document.querySelector( '#markdown-output' );
  54. editor.model.document.on( 'change', () => {
  55. outputElement.innerText = editor.getData();
  56. } );
  57. // Set the initial data with delay so hightlight.js doesn't catch them.
  58. setTimeout( () => {
  59. outputElement.innerText = editor.getData();
  60. }, 500 );
  61. } )
  62. .catch( err => {
  63. console.error( err.stack );
  64. } );