gfmdataprocessor.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  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 document */
  6. import Document from '@ckeditor/ckeditor5-engine/src/view/document';
  7. import { StylesProcessor } from '@ckeditor/ckeditor5-engine/src/view/stylesmap';
  8. import { stringify, parse } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  9. import MarkdownDataProcessor from '../../../src/gfmdataprocessor';
  10. const markdownTextArea = document.getElementById( 'markdown' );
  11. const viewTextArea = document.getElementById( 'view' );
  12. const dataProcessor = new MarkdownDataProcessor( new Document( new StylesProcessor() ) );
  13. document.getElementById( 'button_to_view' ).addEventListener( 'click', convertToView );
  14. document.getElementById( 'button_to_md' ).addEventListener( 'click', convertToMarkdown );
  15. markdownTextArea.value = '### Header 3\n\nTodo:\n\n* [ ] Test me';
  16. convertToView();
  17. function convertToView() {
  18. const markdown = markdownTextArea.value;
  19. viewTextArea.value = stringify( dataProcessor.toView( markdown ) );
  20. }
  21. function convertToMarkdown() {
  22. const viewText = viewTextArea.value;
  23. markdownTextArea.value = dataProcessor.toData( parse( viewText ) );
  24. }